Skip to content

Commit

Permalink
[Fixtures] Review fixes & small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pamil committed Jun 13, 2016
1 parent ec6fc19 commit 8c0a51c
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function process(ContainerBuilder $container)
$fixtureRegistry = $container->findDefinition('sylius_fixtures.fixture_registry');

$taggedServices = $container->findTaggedServiceIds('sylius_fixtures.fixture');
foreach ($taggedServices as $id => $tags) {
foreach (array_keys($taggedServices) as $id) {
$fixtureRegistry->addMethodCall('addFixture', [new Reference($id)]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function process(ContainerBuilder $container)
$listenerRegistry = $container->findDefinition('sylius_fixtures.listener_registry');

$taggedServices = $container->findTaggedServiceIds('sylius_fixtures.listener');
foreach ($taggedServices as $id => $tags) {
foreach (array_keys($taggedServices) as $id) {
$listenerRegistry->addMethodCall('addListener', [new Reference($id)]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ public function getConfigTreeBuilder()
private function buildSuitesNode(ArrayNodeDefinition $rootNode)
{
/** @var ArrayNodeDefinition $suitesNode */
$suitesNode = $rootNode->children()
->arrayNode('suites')
->useAttributeAsKey('name')
->prototype('array')
$suitesNode = $rootNode
->children()
->arrayNode('suites')
->useAttributeAsKey('name')
->prototype('array')
;

$this->buildFixturesNode($suitesNode);
Expand All @@ -55,10 +56,11 @@ private function buildSuitesNode(ArrayNodeDefinition $rootNode)
private function buildFixturesNode(ArrayNodeDefinition $suitesNode)
{
/** @var ArrayNodeDefinition $fixturesNode */
$fixturesNode = $suitesNode->children()
->arrayNode('fixtures')
->useAttributeAsKey('name')
->prototype('array')
$fixturesNode = $suitesNode
->children()
->arrayNode('fixtures')
->useAttributeAsKey('name')
->prototype('array')
;

$this->buildAttributesNode($fixturesNode);
Expand All @@ -70,10 +72,11 @@ private function buildFixturesNode(ArrayNodeDefinition $suitesNode)
private function buildListenersNode(ArrayNodeDefinition $suitesNode)
{
/** @var ArrayNodeDefinition $listenersNode */
$listenersNode = $suitesNode->children()
->arrayNode('listeners')
->useAttributeAsKey('name')
->prototype('array')
$listenersNode = $suitesNode
->children()
->arrayNode('listeners')
->useAttributeAsKey('name')
->prototype('array')
;

$this->buildAttributesNode($listenersNode);
Expand All @@ -88,14 +91,9 @@ private function buildAttributesNode(ArrayNodeDefinition $node)
$attributesNodeBuilder->integerNode('priority')->defaultValue(0);

/** @var ArrayNodeDefinition $optionsNode */
$optionsNode = $attributesNodeBuilder->arrayNode('options')->addDefaultChildrenIfNoneSet();
$optionsNode
->beforeNormalization()
->always(function ($value) {
return [$value];
})
;

$optionsNode = $attributesNodeBuilder->arrayNode('options');
$optionsNode->addDefaultChildrenIfNoneSet();
$optionsNode->beforeNormalization()->always(function ($value) { return [$value]; });
$optionsNode->prototype('variable');
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sylius\Bundle\FixturesBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
Expand Down
9 changes: 3 additions & 6 deletions src/Sylius/Bundle/FixturesBundle/Fixture/FixtureRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Sylius\Bundle\FixturesBundle\Fixture;

use Webmozart\Assert\Assert;

/**
* @author Kamil Kokot <kamil.kokot@lakion.com>
*/
Expand All @@ -26,12 +28,7 @@ final class FixtureRegistry implements FixtureRegistryInterface
*/
public function addFixture(FixtureInterface $fixture)
{
if (isset($this->fixtures[$fixture->getName()])) {
throw new \InvalidArgumentException(sprintf(
'Fixture with name "%s" is already registered.',
$fixture->getName()
));
}
Assert::keyNotExists($this->fixtures, $fixture->getName(), 'Fixture with name "%s" is already registered.');

$this->fixtures[$fixture->getName()] = $fixture;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface FixtureRegistryInterface
*
* @return FixtureInterface
*
* @throw FixtureNotFoundException
* @throws FixtureNotFoundException
*/
public function getFixture($name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Sylius\Bundle\FixturesBundle\Listener;

use Webmozart\Assert\Assert;

/**
* @author Kamil Kokot <kamil.kokot@lakion.com>
*/
Expand All @@ -26,12 +28,7 @@ final class ListenerRegistry implements ListenerRegistryInterface
*/
public function addListener(ListenerInterface $listener)
{
if (isset($this->listeners[$listener->getName()])) {
throw new \InvalidArgumentException(sprintf(
'Listener with name "%s" is already registered.',
$listener->getName()
));
}
Assert::keyNotExists($this->listeners, $listener->getName(), 'Listener with name "%s" is already registered.');

$this->listeners[$listener->getName()] = $listener;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface ListenerRegistryInterface
*
* @return ListenerInterface
*
* @throw ListenerNotFoundException
* @throws ListenerNotFoundException
*/
public function getListener($name);

Expand Down
18 changes: 15 additions & 3 deletions src/Sylius/Bundle/FixturesBundle/Listener/ORMPurgerListener.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sylius\Bundle\FixturesBundle\Listener;

use Doctrine\Common\DataFixtures\Purger\ORMPurger;
Expand Down Expand Up @@ -61,15 +70,18 @@ public function getName()
*/
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode)
{
$optionsNode->children()
$optionsNodeBuilder = $optionsNode->children();

$optionsNodeBuilder
->enumNode('mode')
->values(['delete', 'truncate'])
->defaultValue('delete')
->end()
;

$optionsNodeBuilder
->arrayNode('managers')
->defaultValue([null])
->prototype('scalar')
->end()
;
}
}
2 changes: 1 addition & 1 deletion src/Sylius/Bundle/FixturesBundle/Loader/FixtureLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ final class FixtureLoader implements FixtureLoaderInterface
*/
public function load(SuiteInterface $suite, FixtureInterface $fixture, array $options)
{
$fixture->load($options);
$fixture->load($options);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sylius\Bundle\FixturesBundle\Suite;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace spec\Sylius\Bundle\FixturesBundle\Loader;

use PhpSpec\ObjectBehavior;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace spec\Sylius\Bundle\FixturesBundle\Loader;

use PhpSpec\ObjectBehavior;
Expand Down
9 changes: 9 additions & 0 deletions src/Sylius/Bundle/FixturesBundle/spec/Suite/SuiteSpec.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace spec\Sylius\Bundle\FixturesBundle\Suite;

use PhpSpec\ObjectBehavior;
Expand Down

0 comments on commit 8c0a51c

Please sign in to comment.