From ae20d4bd1d5dede0e19b52f3e095bb828c27ca8a Mon Sep 17 00:00:00 2001 From: Teoh Han Hui Date: Thu, 20 Aug 2015 19:35:16 +0800 Subject: [PATCH] Bump nelmio/alice to ~2.0 --- composer.json | 2 +- doc/context-alice.md | 2 + .../Context/AliceContextSpec.php | 4 +- .../Alice/Fixtures/Loader.php | 42 +++++++++++++++++++ .../FriendlyContexts/Alice/Loader/Yaml.php | 34 --------------- src/Knp/FriendlyContexts/Context/Context.php | 2 +- src/Knp/FriendlyContexts/services/core.yml | 4 +- 7 files changed, 50 insertions(+), 40 deletions(-) create mode 100644 src/Knp/FriendlyContexts/Alice/Fixtures/Loader.php delete mode 100644 src/Knp/FriendlyContexts/Alice/Loader/Yaml.php diff --git a/composer.json b/composer.json index 3dc6b25b..a950673e 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "doctrine/data-fixtures": "~1.0", "behat/mink-extension": "~2.0", "fzaninotto/faker": "~1.0", - "nelmio/alice": "~1.7", + "nelmio/alice": "~2.0", "guzzle/guzzle": "~3.7" }, "require-dev": { diff --git a/doc/context-alice.md b/doc/context-alice.md index 35dfacb1..dbc4d1b8 100644 --- a/doc/context-alice.md +++ b/doc/context-alice.md @@ -2,6 +2,8 @@ Alice Context ============= This context use the [nelmio/alice](https://github.com/nelmio/alice) fixture loading system. +>**Warning** : Alice context is compatible with nelmio/alice ~2.0. + Configuration ------------- diff --git a/spec/Knp/FriendlyContexts/Context/AliceContextSpec.php b/spec/Knp/FriendlyContexts/Context/AliceContextSpec.php index 548ae902..5bda3fe3 100644 --- a/spec/Knp/FriendlyContexts/Context/AliceContextSpec.php +++ b/spec/Knp/FriendlyContexts/Context/AliceContextSpec.php @@ -12,9 +12,9 @@ class AliceContextSpec extends ObjectBehavior * @param \Doctrine\Common\Persistence\ManagerRegistry $doctrine * @param \Doctrine\Common\Persistence\ObjectManager $manager * @param \Behat\Behat\Hook\Scope\ScenarioScope $event + * @param Knp\FriendlyContexts\Alice\Fixtures\Loader $loader * @param \Behat\Gherkin\Node\FeatureNode $feature * @param \Behat\Gherkin\Node\ScenarioNode $scenario - * @param \Knp\FriendlyContexts\Alice\Loader\Yaml $loader * @param \Doctrine\Common\Persistence\Mapping\ClassMetadataFactory $metadataFactory * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $userMetadata * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $placeMetadata @@ -36,7 +36,7 @@ function let($container, $doctrine, $manager, $event, $loader, $feature, $scenar $config = [ 'alice' => [ 'fixtures' => $fixtures, 'dependencies' => [] ]]; $container->has(Argument::any())->willReturn(true); $container->hasParameter(Argument::any())->willReturn(true); - $container->get('friendly.alice.loader.yaml')->willReturn($loader); + $container->get('friendly.alice.fixtures.loader')->willReturn($loader); $container->get('doctrine')->willReturn($doctrine); $container->getParameter('friendly.alice.fixtures')->willReturn($fixtures); $container->getParameter('friendly.alice.dependencies')->willReturn([]); diff --git a/src/Knp/FriendlyContexts/Alice/Fixtures/Loader.php b/src/Knp/FriendlyContexts/Alice/Fixtures/Loader.php new file mode 100644 index 00000000..74e8beb3 --- /dev/null +++ b/src/Knp/FriendlyContexts/Alice/Fixtures/Loader.php @@ -0,0 +1,42 @@ +all()); + } + + public function getCache() + { + return $this->cache; + } + + public function clearCache() + { + $this->cache = []; + } + + /** + * {@inheritdoc} + */ + protected function instantiateFixtures(array $fixtures) + { + parent::instantiateFixtures($fixtures); + + foreach ($fixtures as $fixture) { + $spec = array_map(function ($property) { + return $property->getValue(); + }, $fixture->getProperties()); + + $this->cache[] = [ $spec, $this->objects->get($fixture->getName()) ]; + } + } +} diff --git a/src/Knp/FriendlyContexts/Alice/Loader/Yaml.php b/src/Knp/FriendlyContexts/Alice/Loader/Yaml.php deleted file mode 100644 index 83548a34..00000000 --- a/src/Knp/FriendlyContexts/Alice/Loader/Yaml.php +++ /dev/null @@ -1,34 +0,0 @@ -all()); - } - - public function getCache() - { - return $this->cache; - } - - public function clearCache() - { - $this->cache = []; - } - - protected function createInstance($class, $name, array &$data) - { - $instance = parent::createInstance($class, $name, $data); - $this->cache[] = [ $data, $instance ]; - - return $instance; - } -} diff --git a/src/Knp/FriendlyContexts/Context/Context.php b/src/Knp/FriendlyContexts/Context/Context.php index e11d06bd..b5eeb732 100644 --- a/src/Knp/FriendlyContexts/Context/Context.php +++ b/src/Knp/FriendlyContexts/Context/Context.php @@ -65,7 +65,7 @@ protected function getFeatureWalker() protected function getAliceLoader() { - return $this->get('friendly.alice.loader.yaml'); + return $this->get('friendly.alice.fixtures.loader'); } protected function getEntityManager() diff --git a/src/Knp/FriendlyContexts/services/core.yml b/src/Knp/FriendlyContexts/services/core.yml index 4d3ee671..a18934a7 100644 --- a/src/Knp/FriendlyContexts/services/core.yml +++ b/src/Knp/FriendlyContexts/services/core.yml @@ -17,8 +17,8 @@ services: - @service_container - %friendly.alice.providers% - friendly.alice.loader.yaml: - class: Knp\FriendlyContexts\Alice\Loader\Yaml + friendly.alice.fixtures.loader: + class: Knp\FriendlyContexts\Alice\Fixtures\Loader arguments: - %friendly.alice.locale% - @friendly.alice.provider_resolver