diff --git a/README.md b/README.md index bc4401f..5fec6e7 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,29 @@ -BehatSandbox -======================== +# Behat Skeleton -Basic implementations with Majora Skeleton +Ceci est un example pour l'implémentation d'un skeleton Majora avec un bootstrap pour les tests Behat. -3 suites for the post entity: - - post_dal_domain (to test internal domain) - - post_api_controller (to test api) - - post_api_domain (to test sdk) +Pour faire fonctionner les tests behat, il vous faudra configurer le fichier behat.yml à la racine de votre projet de la manière suivante : -1 feature in Lv\Acme\Bundle\ApiBundle\Features +```yml +imports: + - app/config/parameters.yml -4 contexts: - - PostContext : basic actions for every suite - - PostApiContext : context to test the api - - PostDomainContext : context to test the dal and api domains - - PostRouterContext : just to configure majora router, perhaps not needed, obviously must be refacto as an extension if needed. +default: + autoload: + '': %paths.base%/src + extensions: + Behat\Symfony2Extension: ~ # Using the Symfony Extension + suites: + dal_domain: # Name your suite as you wish. + type: symfony_bundle + bundle: LvExampleDalBundle # Your generated bundle + paths: + - %paths.base%/src/Lv/Example/Bundle/ApiBundle/Features # Path to your generated features + contexts: + - Lv\Example\Bundle\ApiBundle\Features\Context\EntityContext: # Class of your generated entity context + domain: '@lv.entity.domain' # Domain service of your generated entity (majora_vendor.majora_entity.domain) + loader: '@Lv.entity.loader' # Loader service of your generated entity (majora_vendor.majora_entity.domain) + em: '@doctrine.orm.entity_manager' # Doctrine entity manager +``` +Libre à vous ensuite de compléter ces tests avec vos règles métiers. diff --git a/app/AppKernel.php b/app/AppKernel.php index 0ebe1c6..f8eee24 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -17,9 +17,9 @@ public function registerBundles() new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new Majora\Bundle\FrameworkExtraBundle\MajoraFrameworkExtraBundle($this), - new Acme\Lv\Bundle\ApiBundle\AcmeLvApiBundle(), - new Acme\Lv\Bundle\DalBundle\AcmeLvDalBundle(), - new Acme\Lv\Bundle\SdkBundle\AcmeLvSdkBundle(), + new Lv\Example\Bundle\ApiBundle\LvExampleApiBundle(), + new Lv\Example\Bundle\SdkBundle\LvExampleSdkBundle(), + new Lv\Example\Bundle\DalBundle\LvExampleDalBundle(), ]; if (in_array($this->getEnvironment(), ['dev', 'test'], true)) { diff --git a/app/config/behat.yml b/app/config/behat.yml new file mode 100644 index 0000000..2779ed3 --- /dev/null +++ b/app/config/behat.yml @@ -0,0 +1,19 @@ +imports: + - app/config/parameters.yml + +default: + autoload: + '': %paths.base%/src + extensions: + Behat\Symfony2Extension: ~ + suites: + dal_domain: + type: symfony_bundle + bundle: Sir1Partner3DalBundle + paths: + - %paths.base%/src/Sir1/Partner3/Bundle/ApiBundle/Features + contexts: + - Sir1\Partner3\Bundle\ApiBundle\Features\Context\Person2Context: + domain: '@sir1.person2.domain' + loader: '@sir1.person2.loader' + em: '@doctrine.orm.entity_manager' diff --git a/app/config/config.yml b/app/config/config.yml index c5bf7e1..df55751 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -60,11 +60,11 @@ doctrine: entity_managers: default: mappings: - AcmeLvDalBundle: + LvExampleDalBundle: type: yml dir: Resources/config/doctrine - prefix: Acme\Lv\Component\Entity - alias: AcmeLv + prefix: Lv\Example\Component\Entity + alias: LvExample # Swiftmailer Configuration swiftmailer: diff --git a/app/config/routing.yml b/app/config/routing.yml index fd22036..e69de29 100644 --- a/app/config/routing.yml +++ b/app/config/routing.yml @@ -1,2 +0,0 @@ -app: - resource: "@AcmeLvSdkBundle/Resources/config/routing/auto/auto_post.yml" \ No newline at end of file diff --git a/behat.yml b/behat.yml index c74727f..d18676f 100644 --- a/behat.yml +++ b/behat.yml @@ -1,44 +1,2 @@ -default: - autoload: - '': %paths.base%/src - extensions: - Behat\Symfony2Extension: ~ - suites: - api_controller: - type: symfony_bundle - bundle: AcmeLvApiBundle - paths: [ %paths.base%/src/Acme/Lv/Bundle/ApiBundle/Features ] - contexts: - - Acme\Lv\Bundle\ApiBundle\Features\Context\PostApiControllerContext: - em: '@doctrine.orm.entity_manager' - router: '@router' - - Acme\Lv\Bundle\ApiBundle\Features\Context\PostRouterContext: - router: '@router' - host: 'localhost' - scheme: 'http' - baseUrl: '/web/app.php' - port: '9001' - dal_domain: - type: symfony_bundle - bundle: AcmeLvDalBundle - paths: [ %paths.base%/src/Acme/Lv/Bundle/ApiBundle/Features ] - contexts: - - Acme\Lv\Bundle\ApiBundle\Features\Context\PostDalDomainContext: - domain: '@acme.post.domain' - loader: '@acme.post.loader' - em: '@doctrine.orm.entity_manager' - api_domain: - type: symfony_bundle - bundle: AcmeLvDalBundle - paths: [ %paths.base%/src/Acme/Lv/Bundle/ApiBundle/Features ] - contexts: - - Acme\Lv\Bundle\ApiBundle\Features\Context\PostApiDomainContext: - em: '@doctrine.orm.entity_manager' - domain: '@acme.post.api_domain' - loader: '@acme.post.api_loader' - - Acme\Lv\Bundle\ApiBundle\Features\Context\PostRouterContext: - router: '@router' - host: 'localhost' - scheme: 'http' - baseUrl: '/web/app.php' - port: '9001' +imports: + - app/config/behat.yml diff --git a/composer.json b/composer.json index a8cfb20..3ea6dd0 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "require-dev": { "sensio/generator-bundle": "^3.0", "symfony/phpunit-bridge": "^3.0", - "majora/generator-bundle": "dev-master", + "majora/generator-bundle": "dev-feature/add-behat-generator", "behat/behat": "dev-master", "behat/symfony2-extension": "dev-master", "behat/mink-extension": "^2.1", diff --git a/composer.lock b/composer.lock index d6b9ef4..2c728ce 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "5cdf383ad2b9247c93eba68c440cd164", - "content-hash": "4107798a24c21254032eef520c2ef0f7", + "hash": "c3972cbf42f891378c9d935c8a97384f", + "content-hash": "4fbd5a18f391b40a50b4fd1294193e7a", "packages": [ { "name": "behat/transliterator", @@ -2676,20 +2676,20 @@ }, { "name": "majora/generator-bundle", - "version": "dev-master", + "version": "dev-feature/add-behat-generator", "source": { "type": "git", "url": "https://github.com/LinkValue/MajoraGeneratorBundle.git", - "reference": "73b1563455aaf76acfd77bd789479bacef53ec47" + "reference": "0ff9561e9bf07426213fd28eae5ef83937456ef9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/LinkValue/MajoraGeneratorBundle/zipball/73b1563455aaf76acfd77bd789479bacef53ec47", - "reference": "73b1563455aaf76acfd77bd789479bacef53ec47", + "url": "https://api.github.com/repos/LinkValue/MajoraGeneratorBundle/zipball/0ff9561e9bf07426213fd28eae5ef83937456ef9", + "reference": "0ff9561e9bf07426213fd28eae5ef83937456ef9", "shasum": "" }, "require": { - "majora/framework-extra-bundle": ">=1.0", + "majora/framework-extra-bundle": "*", "php": ">=5.6", "sensio/generator-bundle": ">=2.7" }, @@ -2724,7 +2724,7 @@ "generator", "symfony" ], - "time": "2016-03-11 08:35:35" + "time": "2016-07-29 16:00:48" }, { "name": "sensio/generator-bundle", diff --git a/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Features/Context/MajoraEntityContext.php b/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Features/Context/MajoraEntityContext.php index b70f512..a6802a9 100644 --- a/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Features/Context/MajoraEntityContext.php +++ b/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Features/Context/MajoraEntityContext.php @@ -3,10 +3,211 @@ namespace MajoraVendor\MajoraNamespace\Bundle\ApiBundle\Features\Context; use Behat\Behat\Context\Context; +use MajoraVendor\MajoraNamespace\Component\Entity\MajoraEntity; +use MajoraVendor\MajoraNamespace\Component\Entity\MajoraEntityCollection; +use MajoraVendor\MajoraNamespace\Component\Domain\MajoraEntityDomainInterface; +use MajoraVendor\MajoraNamespace\Component\Loader\MajoraEntityLoaderInterface; +use MajoraVendor\MajoraNamespace\Bundle\ApiBundle\Features\Context\MajoraEntityApiContext; +use Doctrine\ORM\EntityManagerInterface; /** * Defines application features from the specific context. + * @MajoraGenerator({"register_behat": {"target": "/config/behat.yml", "context": "MajoraVendor\\MajoraNamespace\\Bundle\\ApiBundle\\Features\\Context\\MajoraEntityContext", "path": "%paths.base%/src/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Features", "domain": "MajoraVendor.MajoraEntity.domain", "loader": "MajoraVendor.MajoraEntity.loader"}}) */ class MajoraEntityContext implements Context { + + private static $totalToInsert = 3; + + /** + * @var ClientInterface + */ + private $client; + + /** + * @var MajoraEntityCollection + */ + private $majora_entitys; + + /** + * @var MajoraEntity + */ + private $currentMajoraEntity; + + /** + * @var MajoraEntity + */ + private $loadedMajoraEntity; + + /** + * @var MajoraEntityCollection + */ + private $currentMajoraEntitys; + + /** + * @var int + */ + private $memoryId; + + /** + * @var EntityManagerInterface + */ + protected $em; + + /** + * @var MajoraEntityDomainInterface + */ + protected $domain; + + /** + * @var MajoraEntityLoaderInterface + */ + protected $loader; + + public function __construct( + MajoraEntityDomainInterface $domain, + MajoraEntityLoaderInterface $loader, + EntityManagerInterface $em + ) { + $this->em = $em; + $this->domain = $domain; + $this->loader = $loader; + } + + /** + * @BeforeScenario + */ + public function initMajoraEntitys() + { + $this->truncateMajoraEntitys(); + for($i=0; $i<= self::$totalToInsert; $i++){ + $this->em->persist(new MajoraEntity()); + } + $this->em->flush(); + } + + /** + * @Given I have some majora_entitys + * + */ + public function retrieveSomeMajoraEntitys() + { + $this->majora_entitys = $this->em->getRepository(MajoraEntity::class)->findAll(); + } + + /** + * @Given I have created a new majora_entity + */ + public function insertMajoraEntity() + { + $this->currentMajoraEntity = new MajoraEntity(); + $this->em->getRepository(MajoraEntity::class)->persist($this->currentMajoraEntity); + $this->em->flush(); + $this->em->refresh($this->currentMajoraEntity); + + $this->memoryId = $this->currentMajoraEntity->getId(); + } + + /** + * @When I create a new majora_entity + */ + public function createMajoraEntity() + { + $this->currentMajoraEntity = $this->domain->create(new MajoraEntity()); + } + + /** + * @When I get the majora_entitys list + */ + public function getMajoraEntityList() + { + $this->currentMajoraEntitys = $this->loader->retrieveAll(); + } + + /** + * @When I get this majora_entity by id + */ + public function getMajoraEntity() + { + $this->loadedMajoraEntity = $this->em->getRepository(MajoraEntity::class)->find($this->memoryId); + } + + /** + * @When I delete this majora_entity + */ + public function deleteMajoraEntity() + { + $this->domain->delete($this->currentMajoraEntity); + } + + /** + * @When I update this majora_entity with a new id + */ + public function updateMajoraEntity() + { + $this->memoryId = $this->currentMajoraEntity->getId(); + $this->domain->update($this->currentMajoraEntity, array("id" => ($this->currentMajoraEntity->getId() + 1))); + } + + /** + * @Then I retrieve new majora_entity id + */ + public function testMajoraEntityId() + { + return $this->currentMajoraEntity->getId() != null; + } + + /** + * @Then I should see a list of majora_entitys + */ + public function compareListMajoraEntitys() + { + return $this->currentMajoraEntitys === $this->majora_entitys; + } + + /** + * @Then I should see this majora_entity + */ + public function compareMajoraEntity() + { + return $this->loadedMajoraEntity === $this->currentMajoraEntity; + } + + /** + * @Then I should not see this majora_entity + */ + public function checkMajoraEntityDeleted() + { + return is_null($this->em->getRepository(MajoraEntity::class)->find($this->memoryId)); + } + + /** + * @Then I should see the same majora_entity with this new id value + */ + public function checkMajoraEntityAsUpdated() + { + return $this->memoryId === $this->currentMajoraEntity->getId() + 1; + } + + /** + * @AfterScenario + */ + public function terminateMajoraEntitys() + { + $this->truncateMajoraEntitys(); + } + + /** + * Trucate all table data + * @throws \Doctrine\DBAL\DBALException + */ + private function truncateMajoraEntitys() + { + $connection = $this->em->getConnection(); + $connection->query('SET FOREIGN_KEY_CHECKS=0'); + $this->em->createQuery('DELETE FROM MajoraVendor\MajoraNamespace\Component\Entity\MajoraEntity')->execute(); + $connection->query('SET FOREIGN_KEY_CHECKS=1'); + $this->em->flush(); + } + } diff --git a/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Features/MajoraEntity.feature b/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Features/MajoraEntity.feature index 39d6465..fe8106f 100644 --- a/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Features/MajoraEntity.feature +++ b/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Features/MajoraEntity.feature @@ -1,4 +1,31 @@ +# @MajoraGenerator({"force_generation": true}) @MajoraEntity Feature: MajoraEntity Crud. - In order to manage MajoraEntity + In order to manage majora_entity As a user + I need to be able to create, update, delete and retrieve majora_entity. + + Scenario: Create + Given I have some majora_entitys + When I create a new majora_entity + Then I retrieve new majora_entity id + + Scenario: ReadAll + Given I have some majora_entitys + When I get the majora_entitys list + Then I should see a list of majora_entitys + + Scenario: Read + Given I have created a new majora_entity + When I get this majora_entity by id + Then I should see this majora_entity + + Scenario: delete + Given I have created a new majora_entity + When I delete this majora_entity + Then I should not see this majora_entity + + Scenario: Update + Given I have created a new majora_entity + When I update this majora_entity with a new id + Then I should see the same majora_entity with this new id value diff --git a/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/MajoraVendorMajoraNamespaceApiBundle.php b/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/MajoraVendorMajoraNamespaceApiBundle.php index 08eeb5a..758b83a 100644 --- a/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/MajoraVendorMajoraNamespaceApiBundle.php +++ b/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/MajoraVendorMajoraNamespaceApiBundle.php @@ -5,7 +5,7 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; /** - * @MajoraGenerator({"register_bundle": {"target": "\\ApiAppKernel"}}) + * @MajoraGenerator({"register_bundle": {"target": "\\AppKernel"}}) */ class MajoraVendorMajoraNamespaceApiBundle extends Bundle { diff --git a/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Resources/config/routing.yml b/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Resources/config/routing.yml index cfab09a..f319881 100644 --- a/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Resources/config/routing.yml +++ b/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Resources/config/routing.yml @@ -1,6 +1,2 @@ -# @MajoraGenerator({"include_routing": {"target": "@ApplicationApiAppBundle/Resources/config/routing.yml"}}) -# @MajoraGenerator({"include_routing": {"route": "majora_vendor_majora_namespace_api"}}) -# @MajoraGenerator({"include_routing": {"resource": "@MajoraVendorMajoraNamespaceApiBundle/Resources/config/routing.yml"}}) - majora_vendor_majora_namespace_sdk: resource: "@MajoraVendorMajoraNamespaceSdkBundle/Resources/config/routing.yml" diff --git a/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Resources/config/services.xml b/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Resources/config/services.xml index eaceadc..92bff1d 100644 --- a/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Resources/config/services.xml +++ b/skeletons/MajoraVendor/MajoraNamespace/Bundle/ApiBundle/Resources/config/services.xml @@ -3,11 +3,11 @@ - + + + diff --git a/src/Acme/Lv/Bundle/ApiBundle/AcmeLvApiBundle.php b/src/Acme/Lv/Bundle/ApiBundle/AcmeLvApiBundle.php deleted file mode 100644 index d51b5d0..0000000 --- a/src/Acme/Lv/Bundle/ApiBundle/AcmeLvApiBundle.php +++ /dev/null @@ -1,12 +0,0 @@ -router = $router; - $this->em = $em; - - $this->client = new Client(); - $this->posts = new PostCollection(); - } - - /** - * @AfterScenario - */ - public function removePosts() - { - foreach ($this->posts as $post) { - $this->em->remove($post); - } - $this->em->flush(); - } - - /** - * @Given I have theses posts: - */ - public function iHaveThesesPosts(PostCollection $posts) - { - // Fill posts table. - foreach ($posts as $post) { - $this->em->persist($post); - } - $this->em->flush(); - $this->posts = $posts; - } - - /** - * @Transform table:key,name - * @Transform table:name - */ - public function castPostsTable(TableNode $postsTable) - { - $posts = new PostCollection(); - foreach ($postsTable->getHash() as $postHash) { - $post = new Post(); - $post->setName($postHash['name']); - if (isset($postHash['key'])) { - $posts->set($postHash['key'], $post); - continue; - } - $posts->add($post); - } - - return $posts; - } - - /** - * @Given I get the post list - */ - public function iGetThePostList() - { - $response = $this->client->request( - 'GET', - $this->router->generate( - 'acme_api_post_collection', - [], - UrlGeneratorInterface::ABSOLUTE_URL - ), - [] - ); - - if ($response->getStatusCode() != Response::HTTP_OK) { - throw new \Exception( - sprintf( - 'Wrong status code : %s given, %s expected', - $response->getStatusCode(), - Response::HTTP_OK - ) - ); - } - - $data = json_decode($response->getBody()->getContents()); - $this->postList = new PostCollection(); - $this->postList->denormalize($data); - } - - /** - * @Then I should see theses posts: - * @Then I should see this post: - */ - public function iShouldSeeThesesPosts(PostCollection $posts) - { - foreach ($posts as $post) { - if (!$this->postList->search(['name' => $post->getName()])->count()) { - $postName = $post->getName(); - throw new \Exception("The post $postName was not found."); - } - } - } - - /** - * @Then I should not see theses posts: - * @Then I should not see this post: - */ - public function iShouldNotSeeThesesPosts(PostCollection $posts) - { - foreach ($posts as $post) { - if ($this->postList->search(['name' => $post->getName()])->count()) { - $postName = $post->getName(); - throw new \Exception("The post $postName was found."); - } - } - } - - /** - * @Given I create this post: - * @Given I create theses posts: - */ - public function iCreateThisPost(PostCollection $posts) - { - foreach ($posts as $post) { - $response = $this->client->request( - 'POST', - $this->router->generate( - 'acme_api_post_create', - [], - UrlGeneratorInterface::ABSOLUTE_URL - ), - ['form_params' => $post->serialize()] - ); - - if ($response->getStatusCode() != Response::HTTP_CREATED) { - throw new \Exception( - sprintf( - 'Wrong status code : %s given, %s expected', - $response->getStatusCode(), - Response::HTTP_CREATED - ) - ); - } - - // Parse the answer and add the created post to the postlist so we can delete it after the scenario. - $data = (array) json_decode($response->getBody()->getContents()); - $post->denormalize($data); - $post = $this->em->getReference('Acme\Lv\Component\Entity\Post', $post->getId()); - $this->posts->add($post); - } - } - - /** - * @Given I update the :key post with theses values: - */ - public function iUpdateTheKeyPost($key, PostCollection $posts) - { - $oldPost = $this->posts->get($key); - - if (!$oldPost) { - throw new \Exception("The post \"$key\" was not found."); - } - - foreach ($posts as $post) { - $response = $this->client->request( - 'PUT', - $this->router->generate( - 'acme_api_post_update', - ['id' => $oldPost->getId()], - UrlGeneratorInterface::ABSOLUTE_URL - ), - ['form_params' => $post->serialize()] - ); - - if ($response->getStatusCode() != Response::HTTP_NO_CONTENT) { - throw new \Exception( - sprintf( - 'Wrong status code : %s given, %s expected', - $response->getStatusCode(), - Response::HTTP_NO_CONTENT - ) - ); - } - } - } - - /** - * @Given I delete the :key post - */ - public function iDeleteTheKeyPost($key) - { - $oldPost = $this->posts->get($key); - - if (!$oldPost) { - throw new \Exception("The post \"$key\" was not found."); - } - - $response = $this->client->request( - 'DELETE', - $this->router->generate( - 'acme_api_post_delete', - ['id' => $oldPost->getId()], - UrlGeneratorInterface::ABSOLUTE_URL - ), - [] - ); - - if ($response->getStatusCode() != Response::HTTP_NO_CONTENT) { - throw new \Exception( - sprintf( - 'Wrong status code : %s given, %s expected', - $response->getStatusCode(), - Response::HTTP_NO_CONTENT - ) - ); - } - } -} diff --git a/src/Acme/Lv/Bundle/ApiBundle/Features/Context/PostApiDomainContext.php b/src/Acme/Lv/Bundle/ApiBundle/Features/Context/PostApiDomainContext.php deleted file mode 100644 index 06b7ad0..0000000 --- a/src/Acme/Lv/Bundle/ApiBundle/Features/Context/PostApiDomainContext.php +++ /dev/null @@ -1,172 +0,0 @@ -domain = $domain; - $this->loader = $loader; - $this->em = $em; - - $this->posts = new PostCollection(); - } - - /** - * @AfterScenario - */ - public function removePosts() - { - foreach ($this->posts as $post) { - $this->em->remove($post); - } - $this->em->flush(); - } - - /** - * @Given I have theses posts: - */ - public function iHaveThesesPosts(PostCollection $posts) - { - // Fill posts table. - foreach ($posts as $post) { - $this->em->persist($post); - } - $this->em->flush(); - $this->posts = $posts; - } - - /** - * @Transform table:key,name - * @Transform table:name - */ - public function castPostsTable(TableNode $postsTable) - { - $posts = new PostCollection(); - foreach ($postsTable->getHash() as $postHash) { - $post = new Post(); - $post->setName($postHash['name']); - if (isset($postHash['key'])) { - $posts->set($postHash['key'], $post); - continue; - } - $posts->add($post); - } - - return $posts; - } - - /** - * @Given I get the post list - */ - public function iGetThePostList() - { - $this->postList = $this->loader->retrieveAll(); - } - - /** - * @Then I should see theses posts: - * @Then I should see this post: - */ - public function iShouldSeeThesesPosts(PostCollection $posts) - { - foreach ($posts as $post) { - if (!$this->postList->search(['name' => $post->getName()])->count()) { - $postName = $post->getName(); - throw new \Exception(sprintf('The post %s was not found.', $postName)); - } - } - } - - /** - * @Then I should not see theses posts: - * @Then I should not see this post: - */ - public function iShouldNotSeeThesesPosts(PostCollection $posts) - { - foreach ($posts as $post) { - if ($this->postList->search(['name' => $post->getName()])->count()) { - $postName = $post->getName(); - throw new \Exception(sprintf('The post %s was found.', $postName)); - } - } - } - - /** - * @Given I create this post: - * @Given I create theses posts: - */ - public function iCreateThisPost(PostCollection $posts) - { - foreach ($posts as $post) { - $post = $this->domain->create($post->serialize()); - $post = $this->em->getReference('Acme\Lv\Component\Entity\Post', $post->getId()); - $this->posts->add($post); - } - } - - /** - * @Given I update the :key post with theses values: - */ - public function iUpdateTheKeyPost($key, PostCollection $posts) - { - $oldPost = $this->posts->get($key); - - if (!$oldPost) { - throw new \Exception(sprintf('The post %s was not found.', $key)); - } - - foreach ($posts as $post) { - $this->domain->update($oldPost, $post->serialize()); - } - } - - /** - * @Given I delete the :key post - */ - public function iDeleteTheKeyPost($key) - { - $oldPost = $this->posts->get($key); - - if (!$oldPost) { - throw new \Exception(sprintf('The post %s was not found.', $key)); - } - - $this->domain->delete($oldPost); - } -} diff --git a/src/Acme/Lv/Bundle/ApiBundle/Features/Context/PostDalDomainContext.php b/src/Acme/Lv/Bundle/ApiBundle/Features/Context/PostDalDomainContext.php deleted file mode 100644 index 374dba2..0000000 --- a/src/Acme/Lv/Bundle/ApiBundle/Features/Context/PostDalDomainContext.php +++ /dev/null @@ -1,177 +0,0 @@ -domain = $domain; - $this->loader = $loader; - $this->em = $em; - - $this->posts = new PostCollection(); - } - - /** - * @BeforeScenario - */ - public function BeforeScenario() - { - $this->em->getConnection(); - $this->em->beginTransaction(); - } - - /** - * @AfterScenario - */ - public function AfterScenario() - { - $this->em->rollback(); - $this->em->close(); - } - - /** - * @Given I have theses posts: - */ - public function iHaveThesesPosts(PostCollection $posts) - { - // Fill posts table. - foreach ($posts as $post) { - $this->em->persist($post); - } - $this->em->flush(); - $this->posts = $posts; - } - - /** - * @Transform table:key,name - * @Transform table:name - */ - public function castPostsTable(TableNode $postsTable) - { - $posts = new PostCollection(); - foreach ($postsTable->getHash() as $postHash) { - $post = new Post(); - $post->setName($postHash['name']); - if (isset($postHash['key'])) { - $posts->set($postHash['key'], $post); - continue; - } - $posts->add($post); - } - - return $posts; - } - - /** - * @Given I get the post list - */ - public function iGetThePostList() - { - $this->postList = $this->loader->retrieveAll(); - } - - /** - * @Then I should see theses posts: - * @Then I should see this post: - */ - public function iShouldSeeThesesPosts(PostCollection $posts) - { - foreach ($posts as $post) { - if (!$this->postList->search(['name' => $post->getName()])->count()) { - $postName = $post->getName(); - throw new \Exception(sprintf('The post %s was not found.', $postName)); - } - } - } - - /** - * @Then I should not see theses posts: - * @Then I should not see this post: - */ - public function iShouldNotSeeThesesPosts(PostCollection $posts) - { - foreach ($posts as $post) { - if ($this->postList->search(['name' => $post->getName()])->count()) { - $postName = $post->getName(); - throw new \Exception(sprintf('The post %s was found.', $postName)); - } - } - } - - /** - * @Given I create this post: - * @Given I create theses posts: - */ - public function iCreateThisPost(PostCollection $posts) - { - foreach ($posts as $post) { - $this->domain->create($post->serialize()); - } - } - - /** - * @Given I update the :key post with theses values: - */ - public function iUpdateTheKeyPost($key, PostCollection $posts) - { - $oldPost = $this->posts->get($key); - - if (!$oldPost) { - throw new \Exception(sprintf('The post %s was not found.', $key)); - } - - foreach ($posts as $post) { - $this->domain->update($oldPost, $post->serialize()); - } - } - - /** - * @Given I delete the :key post - */ - public function iDeleteTheKeyPost($key) - { - $oldPost = $this->posts->get($key); - - if (!$oldPost) { - throw new \Exception(sprintf('The post %s was not found.', $key)); - } - - $this->domain->delete($oldPost); - } -} diff --git a/src/Acme/Lv/Bundle/ApiBundle/Features/Context/PostRouterContext.php b/src/Acme/Lv/Bundle/ApiBundle/Features/Context/PostRouterContext.php deleted file mode 100644 index c900582..0000000 --- a/src/Acme/Lv/Bundle/ApiBundle/Features/Context/PostRouterContext.php +++ /dev/null @@ -1,24 +0,0 @@ -getContext(); - $context->setHost($host); - $context->setScheme($scheme); - $context->setBaseUrl($baseUrl); - $setPortMethodName = 'set'.ucfirst($scheme).'Port'; - $context->$setPortMethodName($port); - } -} diff --git a/src/Acme/Lv/Bundle/ApiBundle/Features/Post.feature b/src/Acme/Lv/Bundle/ApiBundle/Features/Post.feature deleted file mode 100644 index 31f600a..0000000 --- a/src/Acme/Lv/Bundle/ApiBundle/Features/Post.feature +++ /dev/null @@ -1,57 +0,0 @@ -@Post -Feature: Post Crud. - In order to manage Post - As an admin user - I need to be able to create, update, delete and retrieve posts. - - Background: Fixtures - Given I have theses posts: - | key | name | - | post_1 | Gérard | - | post_2 | Michel | - | post_3 | André | - - Scenario: Read - Given I get the post list - Then I should see theses posts: - | name | - | Gérard | - | Michel | - | André | - - Scenario: Create - Given I create theses posts: - | name | - | Clark | - And I get the post list - Then I should see theses posts: - | name | - | Gérard | - | Michel | - | André | - | Clark | - - Scenario: Update - Given I update the "post_2" post with theses values: - | name | - | Bruce | - And I get the post list - Then I should see theses posts: - | name | - | Gérard | - | Bruce | - | André | - And I should not see theses posts: - | name | - | Michel | - - Scenario: Delete - Given I delete the "post_2" post - And I get the post list - Then I should see theses posts: - | name | - | Gérard | - | André | - And I should not see theses posts: - | name | - | Michel | diff --git a/src/Acme/Lv/Bundle/ApiBundle/Resources/config/routing.yml b/src/Acme/Lv/Bundle/ApiBundle/Resources/config/routing.yml deleted file mode 100644 index 4d40a9c..0000000 --- a/src/Acme/Lv/Bundle/ApiBundle/Resources/config/routing.yml +++ /dev/null @@ -1,6 +0,0 @@ -# @MajoraGenerator({"include_routing": {"target": "@ApplicationApiAppBundle/Resources/config/routing.yml"}}) -# @MajoraGenerator({"include_routing": {"route": "acme_lv_api"}}) -# @MajoraGenerator({"include_routing": {"resource": "@AcmeLvApiBundle/Resources/config/routing.yml"}}) - -acme_lv_sdk: - resource: "@AcmeLvSdkBundle/Resources/config/routing.yml" diff --git a/src/Acme/Lv/Bundle/ApiBundle/Resources/config/services/auto/auto_post.xml b/src/Acme/Lv/Bundle/ApiBundle/Resources/config/services/auto/auto_post.xml deleted file mode 100644 index 1b2ac8c..0000000 --- a/src/Acme/Lv/Bundle/ApiBundle/Resources/config/services/auto/auto_post.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Acme/Lv/Bundle/DalBundle/AcmeLvDalBundle.php b/src/Acme/Lv/Bundle/DalBundle/AcmeLvDalBundle.php deleted file mode 100644 index c587383..0000000 --- a/src/Acme/Lv/Bundle/DalBundle/AcmeLvDalBundle.php +++ /dev/null @@ -1,12 +0,0 @@ -postRepository = $postRepository; - } - - /** - * @see EventSubscriberInterface::getSubscribedEvents() - * - * @codeCoverageIgnore - */ - public static function getSubscribedEvents() - { - return array( - PostEvents::ACME_POST_CREATED => array('onWritePost', -100), - PostEvents::ACME_POST_EDITED => array('onWritePost', -100), - PostEvents::ACME_POST_DELETED => array('onDeletePost', -100), - ); - } - - /** - * Post writting event handler. - * - * @param PostEvent $event - */ - public function onWritePost(PostEvent $event) - { - $this->postRepository->persist( - $event->getPost() - ); - } - - /** - * Post deletion event handler. - * - * @param PostEvent $event - */ - public function onDeletePost(PostEvent $event) - { - $this->postRepository->remove( - $event->getPost() - ); - } -} diff --git a/src/Acme/Lv/Bundle/DalBundle/Resources/config/services/auto/auto_post.xml b/src/Acme/Lv/Bundle/DalBundle/Resources/config/services/auto/auto_post.xml deleted file mode 100644 index 8b3cfe2..0000000 --- a/src/Acme/Lv/Bundle/DalBundle/Resources/config/services/auto/auto_post.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - AcmeLv:Post - default - - - - - - - - - - - - - - - - - - - - diff --git a/src/Acme/Lv/Bundle/SdkBundle/AcmeLvSdkBundle.php b/src/Acme/Lv/Bundle/SdkBundle/AcmeLvSdkBundle.php deleted file mode 100644 index 3e2fca2..0000000 --- a/src/Acme/Lv/Bundle/SdkBundle/AcmeLvSdkBundle.php +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - - - - - acme_api_post_collection - acme_api_post_create - acme_api_post_read - acme_api_post_update - acme_api_post_delete - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Acme/Lv/Component/Action/AbstractPostAction.php b/src/Acme/Lv/Component/Action/AbstractPostAction.php deleted file mode 100644 index 8546ac0..0000000 --- a/src/Acme/Lv/Component/Action/AbstractPostAction.php +++ /dev/null @@ -1,41 +0,0 @@ -post = $post; - - return $this; - } - - /** - * Return related Post if defined. - * - * @return Post|null $post - */ - public function getPost() - { - return $this->post; - } -} diff --git a/src/Acme/Lv/Component/Action/Api/Post/AbstractApiAction.php b/src/Acme/Lv/Component/Action/Api/Post/AbstractApiAction.php deleted file mode 100644 index 4c6d66a..0000000 --- a/src/Acme/Lv/Component/Action/Api/Post/AbstractApiAction.php +++ /dev/null @@ -1,14 +0,0 @@ -post = new Post(); - $this->post->deserialize($this->serialize()); - - $this->assertEntityIsValid($this->post, array('Post', 'creation')); - - $this->fireEvent( - PostEvents::ACME_POST_CREATED, - new PostEvent($this->post, $this) - ); - - return $this->post; - } -} diff --git a/src/Acme/Lv/Component/Action/Dal/Post/UpdateAction.php b/src/Acme/Lv/Component/Action/Dal/Post/UpdateAction.php deleted file mode 100644 index db30be7..0000000 --- a/src/Acme/Lv/Component/Action/Dal/Post/UpdateAction.php +++ /dev/null @@ -1,30 +0,0 @@ -post->deserialize($this->serialize()); - - $this->assertEntityIsValid($this->post, array('Post', 'edition')); - - $this->fireEvent( - PostEvents::ACME_POST_EDITED, - new PostEvent($this->post, $this) - ); - } -} diff --git a/src/Acme/Lv/Component/Domain/Action/Auto/PostActionDispatcherDomainTrait.php b/src/Acme/Lv/Component/Domain/Action/Auto/PostActionDispatcherDomainTrait.php deleted file mode 100644 index b189159..0000000 --- a/src/Acme/Lv/Component/Domain/Action/Auto/PostActionDispatcherDomainTrait.php +++ /dev/null @@ -1,47 +0,0 @@ -getAction('create', null, ...$arguments) - ->resolve() - ; - } - - /** - * @see PostDomainInterface::update() - */ - public function update(Post $post, ...$arguments) - { - return $this->getAction('update', $post, ...$arguments) - ->resolve() - ; - } - - /** - * @see PostDomainInterface::delete() - */ - public function delete(Post $post, ...$arguments) - { - return $this->getAction('delete', $post, ...$arguments) - ->resolve() - ; - } -} diff --git a/src/Acme/Lv/Component/Domain/Action/PostActionDispatcherDomain.php b/src/Acme/Lv/Component/Domain/Action/PostActionDispatcherDomain.php deleted file mode 100644 index 2efcb97..0000000 --- a/src/Acme/Lv/Component/Domain/Action/PostActionDispatcherDomain.php +++ /dev/null @@ -1,21 +0,0 @@ -post = $post; - $this->action = $action; - } - - /** - * return related. - * - * @return Post - */ - public function getPost() - { - return $this->post; - } - - /** - * @see BroadcastableEventInterface::getSubject() - */ - public function getSubject() - { - return $this->getPost(); - } - - /** - * @see BroadcastableEventInterface::getAction() - */ - public function getAction() - { - return $this->action; - } -} diff --git a/src/Acme/Lv/Component/Event/PostEvents.php b/src/Acme/Lv/Component/Event/PostEvents.php deleted file mode 100644 index 4870926..0000000 --- a/src/Acme/Lv/Component/Event/PostEvents.php +++ /dev/null @@ -1,24 +0,0 @@ -deserialize(array( - 'post_1' => array('id' => 42), - 'post_2' => array('id' => 66), - )); - - $this->assertInstanceOf( - Post::class, - $postCollection->get('post_1'), - 'Deserialization process hydrate a related entity class object and index it under given key.' - ); - $this->assertInstanceOf( - Post::class, - $postCollection->get('post_2'), - 'Deserialization process hydrate a related entity class object and index it under given key.' - ); - $this->assertEquals( - array( - 'post_1' => 42, - 'post_2' => 66, - ), - $postCollection->serialize('id'), - 'Serialization scopes are transmitted to related entity serialization process.' - ); - } -} diff --git a/src/Acme/Lv/Component/Tests/Event/PostEventTest.php b/src/Acme/Lv/Component/Tests/Event/PostEventTest.php deleted file mode 100644 index d9ab04d..0000000 --- a/src/Acme/Lv/Component/Tests/Event/PostEventTest.php +++ /dev/null @@ -1,34 +0,0 @@ -prophesize(AbstractPostAction::class)->reveal(); - - // Event - $event = new PostEvent( - $post = new Post(), - $action - ); - - // Assertions - $this->assertSame($post, $event->getPost()); - $this->assertSame($post, $event->getSubject()); - $this->assertSame($action, $event->getAction()); - } -} diff --git a/src/Acme/Lv/Component/Tests/Loader/Doctrine/PostDoctrineLoader.php b/src/Acme/Lv/Component/Tests/Loader/Doctrine/PostDoctrineLoader.php deleted file mode 100644 index 0ec259f..0000000 --- a/src/Acme/Lv/Component/Tests/Loader/Doctrine/PostDoctrineLoader.php +++ /dev/null @@ -1,31 +0,0 @@ -prophesize(PostRepositoryInterface::class); - $repository->save()->shouldNotBeCalled(); - - $loader = new PostDoctrineLoader(); - $loader->setUp( - Post::class, - array('majora' => 'entity'), - PostCollection::class, - $repository->reveal() - ); - } -} diff --git a/src/Acme/Lv/Bundle/ApiBundle/Controller/Auto/PostApiControllerTrait.php b/src/Lv/Example/Bundle/ApiBundle/Controller/Auto/EntityApiControllerTrait.php similarity index 71% rename from src/Acme/Lv/Bundle/ApiBundle/Controller/Auto/PostApiControllerTrait.php rename to src/Lv/Example/Bundle/ApiBundle/Controller/Auto/EntityApiControllerTrait.php index 7471255..71f9721 100644 --- a/src/Acme/Lv/Bundle/ApiBundle/Controller/Auto/PostApiControllerTrait.php +++ b/src/Lv/Example/Bundle/ApiBundle/Controller/Auto/EntityApiControllerTrait.php @@ -1,27 +1,27 @@ createJsonResponse( - $this->container->get('acme.post.loader')->retrieveAll( + $this->container->get('lv.entity.loader')->retrieveAll( $this->container->get('majora.inflector')->normalize($queryFilters, 'camelize'), $request->query->get('limit'), $request->query->get('offset') @@ -45,25 +45,25 @@ public function cgetAction(Request $request) } /** - * Returns a single Post by id. + * Returns a single Entity by id. * - * @param int $id requested Post id + * @param int $id requested Entity id * @param Request $request * * @return JsonResponse */ public function getAction($id, Request $request) { - $post = $this->retrieveOr404($id, 'acme.post.loader'); + $entity = $this->retrieveOr404($id, 'lv.entity.loader'); return $this->createJsonResponse( - $post, + $entity, $request->query->get('scope') ); } /** - * Creates a new Post. + * Creates a new Entity. * * @param Request $request * @@ -82,19 +82,19 @@ public function postAction(Request $request) ); // resolve use case - $post = $form->getData()->resolve(); + $entity = $form->getData()->resolve(); return $this->createJsonResponse( - $post, + $entity, $request->query->get('scope'), 201 ); } /** - * Updates a single Post by id. + * Updates a single Entity by id. * - * @param int $id requested Post id + * @param int $id requested Entity id * @param Request $request * * @return JsonResponse @@ -109,7 +109,7 @@ public function putAction($id, Request $request) null, array( 'method' => 'PUT', - 'entity' => $this->retrieveOr404($id, 'acme.post.loader'), + 'entity' => $this->retrieveOr404($id, 'lv.entity.loader'), ) ) ); @@ -121,16 +121,16 @@ public function putAction($id, Request $request) } /** - * Delete a single Post by id. + * Delete a single Entity by id. * - * @param int $id requested Post id + * @param int $id requested Entity id * * @return JsonResponse */ public function deleteAction($id) { - $this->container->get('acme.post.domain')->delete( - $this->retrieveOr404($id, 'acme.post.loader') + $this->container->get('lv.entity.domain')->delete( + $this->retrieveOr404($id, 'lv.entity.loader') ); return $this->createJsonNoContentResponse(); diff --git a/src/Acme/Lv/Bundle/ApiBundle/Controller/PostApiController.php b/src/Lv/Example/Bundle/ApiBundle/Controller/EntityApiController.php similarity index 58% rename from src/Acme/Lv/Bundle/ApiBundle/Controller/PostApiController.php rename to src/Lv/Example/Bundle/ApiBundle/Controller/EntityApiController.php index a48576d..38975cc 100644 --- a/src/Acme/Lv/Bundle/ApiBundle/Controller/PostApiController.php +++ b/src/Lv/Example/Bundle/ApiBundle/Controller/EntityApiController.php @@ -1,12 +1,12 @@ root('acme_lv_api') + * $treeBuilder->root('lv_example_api') * ->children() * ->scalarNode('...') * ->isRequired() @@ -34,7 +34,7 @@ class Configuration implements ConfigurationInterface public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); - $treeBuilder->root('acme_lv_api'); + $treeBuilder->root('lv_example_api'); return $treeBuilder; } diff --git a/src/Acme/Lv/Bundle/ApiBundle/DependencyInjection/AcmeLvApiExtension.php b/src/Lv/Example/Bundle/ApiBundle/DependencyInjection/LvExampleApiExtension.php similarity index 88% rename from src/Acme/Lv/Bundle/ApiBundle/DependencyInjection/AcmeLvApiExtension.php rename to src/Lv/Example/Bundle/ApiBundle/DependencyInjection/LvExampleApiExtension.php index 6e49676..0b26511 100644 --- a/src/Acme/Lv/Bundle/ApiBundle/DependencyInjection/AcmeLvApiExtension.php +++ b/src/Lv/Example/Bundle/ApiBundle/DependencyInjection/LvExampleApiExtension.php @@ -1,6 +1,6 @@ em = $em; + $this->domain = $domain; + $this->loader = $loader; + } + + /** + * @BeforeScenario + */ + public function initEntitys() + { + $this->truncateEntitys(); + for($i=0; $i<= self::$totalToInsert; $i++){ + $this->em->persist(new Entity()); + } + $this->em->flush(); + } + + /** + * @Given I have some entitys + * + */ + public function retrieveSomeEntitys() + { + $this->entitys = $this->em->getRepository(Entity::class)->findAll(); + } + + /** + * @Given I have created a new entity + */ + public function insertEntity() + { + $this->currentEntity = new Entity(); + $this->em->getRepository(Entity::class)->persist($this->currentEntity); + $this->em->flush(); + $this->em->refresh($this->currentEntity); + + $this->memoryId = $this->currentEntity->getId(); + } + + /** + * @When I create a new entity + */ + public function createEntity() + { + $this->currentEntity = $this->domain->create(new Entity()); + } + + /** + * @When I get the entitys list + */ + public function getEntityList() + { + $this->currentEntitys = $this->loader->retrieveAll(); + } + + /** + * @When I get this entity by id + */ + public function getEntity() + { + $this->loadedEntity = $this->em->getRepository(Entity::class)->find($this->memoryId); + } + + /** + * @When I delete this entity + */ + public function deleteEntity() + { + $this->domain->delete($this->currentEntity); + } + + /** + * @When I update this entity with a new id + */ + public function updateEntity() + { + $this->memoryId = $this->currentEntity->getId(); + $this->domain->update($this->currentEntity, array("id" => ($this->currentEntity->getId() + 1))); + } + + /** + * @Then I retrieve new entity id + */ + public function testEntityId() + { + return $this->currentEntity->getId() != null; + } + + /** + * @Then I should see a list of entitys + */ + public function compareListEntitys() + { + return $this->currentEntitys === $this->entitys; + } + + /** + * @Then I should see this entity + */ + public function compareEntity() + { + return $this->loadedEntity === $this->currentEntity; + } + + /** + * @Then I should not see this entity + */ + public function checkEntityDeleted() + { + return is_null($this->em->getRepository(Entity::class)->find($this->memoryId)); + } + + /** + * @Then I should see the same entity with this new id value + */ + public function checkEntityAsUpdated() + { + return $this->memoryId === $this->currentEntity->getId() + 1; + } + + /** + * @AfterScenario + */ + public function terminateEntitys() + { + $this->truncateEntitys(); + } + + /** + * Trucate all table data + * @throws \Doctrine\DBAL\DBALException + */ + private function truncateEntitys() + { + $connection = $this->em->getConnection(); + $connection->query('SET FOREIGN_KEY_CHECKS=0'); + $this->em->createQuery('DELETE FROM Lv\Example\Component\Entity\Entity')->execute(); + $connection->query('SET FOREIGN_KEY_CHECKS=1'); + $this->em->flush(); + } + +} diff --git a/src/Lv/Example/Bundle/ApiBundle/Features/Entity.feature b/src/Lv/Example/Bundle/ApiBundle/Features/Entity.feature new file mode 100644 index 0000000..f2aa744 --- /dev/null +++ b/src/Lv/Example/Bundle/ApiBundle/Features/Entity.feature @@ -0,0 +1,30 @@ +@Entity +Feature: Entity Crud. + In order to manage entity + As a user + I need to be able to create, update, delete and retrieve entity. + + Scenario: Create + Given I have some entitys + When I create a new entity + Then I retrieve new entity id + + Scenario: ReadAll + Given I have some entitys + When I get the entitys list + Then I should see a list of entitys + + Scenario: Read + Given I have created a new entity + When I get this entity by id + Then I should see this entity + + Scenario: delete + Given I have created a new entity + When I delete this entity + Then I should not see this entity + + Scenario: Update + Given I have created a new entity + When I update this entity with a new id + Then I should see the same entity with this new id value diff --git a/src/Acme/Lv/Bundle/ApiBundle/Form/Post/AbstractType.php b/src/Lv/Example/Bundle/ApiBundle/Form/Entity/AbstractType.php similarity index 65% rename from src/Acme/Lv/Bundle/ApiBundle/Form/Post/AbstractType.php rename to src/Lv/Example/Bundle/ApiBundle/Form/Entity/AbstractType.php index 5fd2ead..d00fec4 100644 --- a/src/Acme/Lv/Bundle/ApiBundle/Form/Post/AbstractType.php +++ b/src/Lv/Example/Bundle/ApiBundle/Form/Entity/AbstractType.php @@ -1,30 +1,30 @@ postDomain = $postDomain; + $this->entityDomain = $entityDomain; } /** @@ -40,7 +40,7 @@ public function configureOptions(OptionsResolver $resolver) } /** - * Post form prototype definition. + * Entity form prototype definition. * * @warning : function auto generated by MajoraGeneratorBundle, implement your own logic here ! * @@ -48,6 +48,5 @@ public function configureOptions(OptionsResolver $resolver) */ public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->add('name'); } } diff --git a/src/Acme/Lv/Bundle/ApiBundle/Form/Post/CreationType.php b/src/Lv/Example/Bundle/ApiBundle/Form/Entity/CreationType.php similarity index 69% rename from src/Acme/Lv/Bundle/ApiBundle/Form/Post/CreationType.php rename to src/Lv/Example/Bundle/ApiBundle/Form/Entity/CreationType.php index 1b01d6a..e0bab99 100644 --- a/src/Acme/Lv/Bundle/ApiBundle/Form/Post/CreationType.php +++ b/src/Lv/Example/Bundle/ApiBundle/Form/Entity/CreationType.php @@ -1,13 +1,13 @@ setDefaults(array( 'data_class' => CreateAction::class, 'empty_data' => function (FormInterface $form) { - return $this->postDomain->getAction('create'); + return $this->entityDomain->getAction('create'); }, )); } diff --git a/src/Acme/Lv/Bundle/ApiBundle/Form/Post/EditionType.php b/src/Lv/Example/Bundle/ApiBundle/Form/Entity/EditionType.php similarity index 67% rename from src/Acme/Lv/Bundle/ApiBundle/Form/Post/EditionType.php rename to src/Lv/Example/Bundle/ApiBundle/Form/Entity/EditionType.php index 096713f..6978bc1 100644 --- a/src/Acme/Lv/Bundle/ApiBundle/Form/Post/EditionType.php +++ b/src/Lv/Example/Bundle/ApiBundle/Form/Entity/EditionType.php @@ -1,14 +1,14 @@ setDefaults(array( 'data_class' => UpdateAction::class, 'empty_data' => function (FormInterface $form) { - return $this->postDomain->getAction( + return $this->entityDomain->getAction( 'update', $form->getConfig()->getOption('entity') ); }, )); $resolver->setRequired('entity'); - $resolver->setAllowedTypes('entity', Post::class); + $resolver->setAllowedTypes('entity', Entity::class); } } diff --git a/src/Lv/Example/Bundle/ApiBundle/LvExampleApiBundle.php b/src/Lv/Example/Bundle/ApiBundle/LvExampleApiBundle.php new file mode 100644 index 0000000..20adbce --- /dev/null +++ b/src/Lv/Example/Bundle/ApiBundle/LvExampleApiBundle.php @@ -0,0 +1,12 @@ + - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Acme/Lv/Bundle/ApiBundle/Resources/config/services/post.xml b/src/Lv/Example/Bundle/ApiBundle/Resources/config/services/entity.xml similarity index 84% rename from src/Acme/Lv/Bundle/ApiBundle/Resources/config/services/post.xml rename to src/Lv/Example/Bundle/ApiBundle/Resources/config/services/entity.xml index 66a033f..cedde9c 100644 --- a/src/Acme/Lv/Bundle/ApiBundle/Resources/config/services/post.xml +++ b/src/Lv/Example/Bundle/ApiBundle/Resources/config/services/entity.xml @@ -1,13 +1,13 @@ - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + LvExample:Entity + default + + + + + + + + + + + + + + + + + + + + diff --git a/src/Acme/Lv/Bundle/DalBundle/Resources/config/services/post.xml b/src/Lv/Example/Bundle/DalBundle/Resources/config/services/entity.xml similarity index 84% rename from src/Acme/Lv/Bundle/DalBundle/Resources/config/services/post.xml rename to src/Lv/Example/Bundle/DalBundle/Resources/config/services/entity.xml index 66a033f..cedde9c 100644 --- a/src/Acme/Lv/Bundle/DalBundle/Resources/config/services/post.xml +++ b/src/Lv/Example/Bundle/DalBundle/Resources/config/services/entity.xml @@ -1,13 +1,13 @@ - + - + - + + + + + + + + + + + + + + + + lv_api_entity_collection + lv_api_entity_create + lv_api_entity_read + lv_api_entity_update + lv_api_entity_delete + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Acme/Lv/Bundle/SdkBundle/Resources/config/services/post.xml b/src/Lv/Example/Bundle/SdkBundle/Resources/config/services/entity.xml similarity index 84% rename from src/Acme/Lv/Bundle/SdkBundle/Resources/config/services/post.xml rename to src/Lv/Example/Bundle/SdkBundle/Resources/config/services/entity.xml index 66a033f..cedde9c 100644 --- a/src/Acme/Lv/Bundle/SdkBundle/Resources/config/services/post.xml +++ b/src/Lv/Example/Bundle/SdkBundle/Resources/config/services/entity.xml @@ -1,13 +1,13 @@ - + - +