Extract FixturesBundle

This commit is contained in:
Kamil Kokot 2019-02-18 15:41:27 +01:00
parent 452471d26e
commit 27609f0dd5
No known key found for this signature in database
GPG key ID: 7BD76F7054D93C89
84 changed files with 1 additions and 4249 deletions

View file

@ -52,6 +52,7 @@
"sonata-project/intl-bundle": "^2.2",
"stof/doctrine-extensions-bundle": "^1.2",
"swiftmailer/swiftmailer": "^6.0",
"sylius/fixtures-bundle": "~1.1.15",
"sylius-labs/association-hydrator": "^1.0",
"symfony/monolog-bundle": "^3.0",
"symfony/polyfill-iconv": "^1.3",
@ -113,7 +114,6 @@
"sylius/currency-bundle": "self.version",
"sylius/customer": "self.version",
"sylius/customer-bundle": "self.version",
"sylius/fixtures-bundle": "self.version",
"sylius/grid": "self.version",
"sylius/grid-bundle": "self.version",
"sylius/inventory": "self.version",

View file

@ -29,7 +29,6 @@ suites:
CoreBundle: { namespace: Sylius\Bundle\CoreBundle, psr4_prefix: Sylius\Bundle\CoreBundle, spec_path: src/Sylius/Bundle/CoreBundle, src_path: src/Sylius/Bundle/CoreBundle }
CurrencyBundle: { namespace: Sylius\Bundle\CurrencyBundle, psr4_prefix: Sylius\Bundle\CurrencyBundle, spec_path: src/Sylius/Bundle/CurrencyBundle, src_path: src/Sylius/Bundle/CurrencyBundle }
CustomerBundle: { namespace: Sylius\Bundle\CustomerBundle, psr4_prefix: Sylius\Bundle\CustomerBundle, spec_path: src/Sylius/Bundle/CustomerBundle, src_path: src/Sylius/Bundle/CustomerBundle }
FixturesBundle: { namespace: Sylius\Bundle\FixturesBundle, psr4_prefix: Sylius\Bundle\FixturesBundle, spec_path: src/Sylius/Bundle/FixturesBundle, src_path: src/Sylius/Bundle/FixturesBundle }
GridBundle: { namespace: Sylius\Bundle\GridBundle, psr4_prefix: Sylius\Bundle\GridBundle, spec_path: src/Sylius/Bundle/GridBundle, src_path: src/Sylius/Bundle/GridBundle }
InventoryBundle: { namespace: Sylius\Bundle\InventoryBundle, psr4_prefix: Sylius\Bundle\InventoryBundle, spec_path: src/Sylius/Bundle/InventoryBundle, src_path: src/Sylius/Bundle/InventoryBundle }
LocaleBundle: { namespace: Sylius\Bundle\LocaleBundle, psr4_prefix: Sylius\Bundle\LocaleBundle, spec_path: src/Sylius/Bundle/LocaleBundle, src_path: src/Sylius/Bundle/LocaleBundle }

View file

@ -1,15 +0,0 @@
/vendor
/bin
/composer.phar
/composer.lock
test/app/cache
test/app/logs
/humbug.json
/phpspec.yml
/phpunit.xml
/humbuglog.txt
/humbuglog.json

View file

@ -1,87 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Command;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureRegistryInterface;
use Sylius\Bundle\FixturesBundle\Suite\SuiteRegistryInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
final class FixturesListCommand extends ContainerAwareCommand
{
/**
* {@inheritdoc}
*/
protected function configure(): void
{
$this
->setName('sylius:fixtures:list')
->setDescription('Lists available fixtures')
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): void
{
$this->listSuites($output);
$this->listFixtures($output);
}
/**
* @param OutputInterface $output
*/
private function listSuites(OutputInterface $output): void
{
$suites = $this->getSuiteRegistry()->getSuites();
$output->writeln('Available suites:');
foreach ($suites as $suite) {
$output->writeln(' - ' . $suite->getName());
}
}
/**
* @param OutputInterface $output
*/
private function listFixtures(OutputInterface $output): void
{
$fixtures = $this->getFixtureRegistry()->getFixtures();
$output->writeln('Available fixtures:');
foreach ($fixtures as $name => $fixture) {
$output->writeln(' - ' . $name);
}
}
/**
* @return SuiteRegistryInterface
*/
private function getSuiteRegistry(): SuiteRegistryInterface
{
return $this->getContainer()->get('sylius_fixtures.suite_registry');
}
/**
* @return FixtureRegistryInterface
*/
private function getFixtureRegistry(): FixtureRegistryInterface
{
return $this->getContainer()->get('sylius_fixtures.fixture_registry');
}
}

View file

@ -1,87 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Command;
use Sylius\Bundle\FixturesBundle\Loader\SuiteLoaderInterface;
use Sylius\Bundle\FixturesBundle\Suite\SuiteRegistryInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
final class FixturesLoadCommand extends ContainerAwareCommand
{
/**
* {@inheritdoc}
*/
protected function configure(): void
{
$this
->setName('sylius:fixtures:load')
->setDescription('Loads fixtures from given suite')
->addArgument('suite', InputArgument::OPTIONAL, 'Suite name', 'default')
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): void
{
if ($input->isInteractive()) {
/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getHelper('question');
$output->writeln(sprintf(
"\n<error>Warning! Loading fixtures will purge your database for the %s environment.</error>\n",
$input->getOption('env')
));
if (!$questionHelper->ask($input, $output, new ConfirmationQuestion('Continue? (y/N) ', false))) {
return;
}
}
$this->loadSuites($input);
}
/**
* @param InputInterface $input
*/
private function loadSuites(InputInterface $input): void
{
$suiteName = $input->getArgument('suite');
$suite = $this->getSuiteRegistry()->getSuite($suiteName);
$this->getSuiteLoader()->load($suite);
}
/**
* @return SuiteRegistryInterface
*/
private function getSuiteRegistry(): SuiteRegistryInterface
{
return $this->getContainer()->get('sylius_fixtures.suite_registry');
}
/**
* @return SuiteLoaderInterface
*/
private function getSuiteLoader(): SuiteLoaderInterface
{
return $this->getContainer()->get('sylius_fixtures.suite_loader');
}
}

View file

@ -1,38 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
final class FixtureRegistryPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container): void
{
if (!$container->has('sylius_fixtures.fixture_registry')) {
return;
}
$fixtureRegistry = $container->findDefinition('sylius_fixtures.fixture_registry');
$taggedServices = $container->findTaggedServiceIds('sylius_fixtures.fixture');
foreach (array_keys($taggedServices) as $id) {
$fixtureRegistry->addMethodCall('addFixture', [new Reference($id)]);
}
}
}

View file

@ -1,38 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
final class ListenerRegistryPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container): void
{
if (!$container->has('sylius_fixtures.listener_registry')) {
return;
}
$listenerRegistry = $container->findDefinition('sylius_fixtures.listener_registry');
$taggedServices = $container->findTaggedServiceIds('sylius_fixtures.listener');
foreach (array_keys($taggedServices) as $id) {
$listenerRegistry->addMethodCall('addListener', [new Reference($id)]);
}
}
}

View file

@ -1,139 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
final class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('sylius_fixtures');
$this->buildSuitesNode($rootNode);
return $treeBuilder;
}
/**
* @param ArrayNodeDefinition $rootNode
*/
private function buildSuitesNode(ArrayNodeDefinition $rootNode): void
{
/** @var ArrayNodeDefinition $suitesNode */
$suitesNode = $rootNode
->children()
->arrayNode('suites')
->useAttributeAsKey('name')
->arrayPrototype()
;
$suitesNode
->validate()
->ifArray()
->then(function (array $value) {
if (!isset($value['fixtures'])) {
return $value;
}
foreach ($value['fixtures'] as $fixtureKey => &$fixtureValue) {
if (!isset($fixtureValue['name'])) {
$fixtureValue['name'] = $fixtureKey;
}
}
return $value;
})
;
$this->buildFixturesNode($suitesNode);
$this->buildListenersNode($suitesNode);
}
/**
* @param ArrayNodeDefinition $suitesNode
*/
private function buildFixturesNode(ArrayNodeDefinition $suitesNode): void
{
/** @var ArrayNodeDefinition $fixturesNode */
$fixturesNode = $suitesNode
->children()
->arrayNode('fixtures')
->useAttributeAsKey('alias')
->arrayPrototype()
;
$fixturesNode->children()->scalarNode('name')->cannotBeEmpty();
$this->buildAttributesNode($fixturesNode);
}
/**
* @param ArrayNodeDefinition $suitesNode
*/
private function buildListenersNode(ArrayNodeDefinition $suitesNode): void
{
/** @var ArrayNodeDefinition $listenersNode */
$listenersNode = $suitesNode
->children()
->arrayNode('listeners')
->useAttributeAsKey('name')
->arrayPrototype()
;
$this->buildAttributesNode($listenersNode);
}
/**
* @param ArrayNodeDefinition $node
*/
private function buildAttributesNode(ArrayNodeDefinition $node): void
{
$attributesNodeBuilder = $node->canBeUnset()->children();
$attributesNodeBuilder->integerNode('priority')->defaultValue(0);
/** @var ArrayNodeDefinition $optionsNode */
$optionsNode = $attributesNodeBuilder->arrayNode('options');
$optionsNode->addDefaultChildrenIfNoneSet();
$optionsNode
->validate()
->ifTrue(function (array $values) {
foreach ($values as $value) {
if (!is_array($value)) {
return true;
}
}
return false;
})
->thenInvalid('Options have to be an array!')
;
$optionsNode
->beforeNormalization()
->always(function ($value) {
return [$value];
})
;
$optionsNode->variablePrototype()->cannotBeEmpty()->defaultValue([]);
}
}

View file

@ -1,70 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
final class SyliusFixturesExtension extends Extension implements PrependExtensionInterface
{
/**
* {@inheritdoc}
*/
public function load(array $config, ContainerBuilder $container): void
{
$config = $this->processConfiguration($this->getConfiguration([], $container), $config);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
$this->registerSuites($config, $container);
}
/**
* {@inheritdoc}
*/
public function prepend(ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$extensionsNamesToConfigurationFiles = [
'doctrine' => 'doctrine/orm.xml',
'doctrine_mongodb' => 'doctrine/mongodb-odm.xml',
'doctrine_phpcr' => 'doctrine/phpcr-odm.xml',
];
foreach ($extensionsNamesToConfigurationFiles as $extensionName => $configurationFile) {
if (!$container->hasExtension($extensionName)) {
continue;
}
$loader->load('services/integrations/' . $configurationFile);
}
}
/**
* @param array $config
* @param ContainerBuilder $container
*/
private function registerSuites(array $config, ContainerBuilder $container): void
{
$suiteRegistry = $container->findDefinition('sylius_fixtures.suite_registry');
foreach ($config['suites'] as $suiteName => $suiteConfiguration) {
$suiteRegistry->addMethodCall('addSuite', [$suiteName, $suiteConfiguration]);
}
}
}

View file

@ -1,41 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Fixture;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
abstract class AbstractFixture implements FixtureInterface
{
/**
* {@inheritdoc}
*/
final public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$optionsNode = $treeBuilder->root($this->getName());
$this->configureOptionsNode($optionsNode);
return $treeBuilder;
}
/**
* @param ArrayNodeDefinition $optionsNode
*/
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
{
// empty
}
}

View file

@ -1,29 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Fixture;
use Symfony\Component\Config\Definition\ConfigurationInterface;
interface FixtureInterface extends ConfigurationInterface
{
/**
* @param array $options
*/
public function load(array $options): void;
/**
* @return string
*/
public function getName(): string;
}

View file

@ -1,26 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Fixture;
final class FixtureNotFoundException extends \InvalidArgumentException
{
/**
* @param string $name
* @param \Exception|null $previous
*/
public function __construct(string $name, ?\Exception $previous = null)
{
parent::__construct(sprintf('Fixture with name "%s" could not be found!', $name), 0, $previous);
}
}

View file

@ -1,54 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Fixture;
use Webmozart\Assert\Assert;
final class FixtureRegistry implements FixtureRegistryInterface
{
/**
* @var array
*/
private $fixtures = [];
/**
* @param FixtureInterface $fixture
*/
public function addFixture(FixtureInterface $fixture): void
{
Assert::keyNotExists($this->fixtures, $fixture->getName(), 'Fixture with name "%s" is already registered.');
$this->fixtures[$fixture->getName()] = $fixture;
}
/**
* {@inheritdoc}
*/
public function getFixture(string $name): FixtureInterface
{
if (!isset($this->fixtures[$name])) {
throw new FixtureNotFoundException($name);
}
return $this->fixtures[$name];
}
/**
* {@inheritdoc}
*/
public function getFixtures(): array
{
return $this->fixtures;
}
}

View file

@ -1,31 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Fixture;
interface FixtureRegistryInterface
{
/**
* @param string $name
*
* @return FixtureInterface
*
* @throws FixtureNotFoundException
*/
public function getFixture(string $name): FixtureInterface;
/**
* @return array|FixtureInterface[] Name indexed
*/
public function getFixtures(): array;
}

View file

@ -1,19 +0,0 @@
Copyright (c) 2011-2018 Paweł Jędrzejewski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View file

@ -1,41 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Listener;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
abstract class AbstractListener implements ListenerInterface
{
/**
* {@inheritdoc}
*/
final public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$optionsNode = $treeBuilder->root($this->getName());
$this->configureOptionsNode($optionsNode);
return $treeBuilder;
}
/**
* @param ArrayNodeDefinition $optionsNode
*/
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
{
// empty
}
}

View file

@ -1,23 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Listener;
interface AfterFixtureListenerInterface extends ListenerInterface
{
/**
* @param FixtureEvent $fixtureEvent
* @param array $options
*/
public function afterFixture(FixtureEvent $fixtureEvent, array $options): void;
}

View file

@ -1,23 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Listener;
interface AfterSuiteListenerInterface extends ListenerInterface
{
/**
* @param SuiteEvent $suiteEvent
* @param array $options
*/
public function afterSuite(SuiteEvent $suiteEvent, array $options): void;
}

View file

@ -1,23 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Listener;
interface BeforeFixtureListenerInterface extends ListenerInterface
{
/**
* @param FixtureEvent $fixtureEvent
* @param array $options
*/
public function beforeFixture(FixtureEvent $fixtureEvent, array $options): void;
}

View file

@ -1,23 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Listener;
interface BeforeSuiteListenerInterface extends ListenerInterface
{
/**
* @param SuiteEvent $suiteEvent
* @param array $options
*/
public function beforeSuite(SuiteEvent $suiteEvent, array $options): void;
}

View file

@ -1,71 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Listener;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
final class FixtureEvent
{
/**
* @var SuiteInterface
*/
private $suite;
/**
* @var FixtureInterface
*/
private $fixture;
/**
* @var array
*/
private $fixtureOptions;
/**
* @param SuiteInterface $suite
* @param FixtureInterface $fixture
* @param array $fixtureOptions
*/
public function __construct(SuiteInterface $suite, FixtureInterface $fixture, array $fixtureOptions)
{
$this->suite = $suite;
$this->fixture = $fixture;
$this->fixtureOptions = $fixtureOptions;
}
/**
* @return SuiteInterface
*/
public function suite(): SuiteInterface
{
return $this->suite;
}
/**
* @return FixtureInterface
*/
public function fixture(): FixtureInterface
{
return $this->fixture;
}
/**
* @return array
*/
public function fixtureOptions(): array
{
return $this->fixtureOptions;
}
}

View file

@ -1,24 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Listener;
use Symfony\Component\Config\Definition\ConfigurationInterface;
interface ListenerInterface extends ConfigurationInterface
{
/**
* @return string
*/
public function getName(): string;
}

View file

@ -1,26 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Listener;
final class ListenerNotFoundException extends \InvalidArgumentException
{
/**
* @param string $name
* @param \Exception|null $previous
*/
public function __construct(string $name, ?\Exception $previous = null)
{
parent::__construct(sprintf('Listener with name "%s" could not be found!', $name), 0, $previous);
}
}

View file

@ -1,54 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Listener;
use Webmozart\Assert\Assert;
final class ListenerRegistry implements ListenerRegistryInterface
{
/**
* @var array
*/
private $listeners = [];
/**
* @param ListenerInterface $listener
*/
public function addListener(ListenerInterface $listener): void
{
Assert::keyNotExists($this->listeners, $listener->getName(), 'Listener with name "%s" is already registered.');
$this->listeners[$listener->getName()] = $listener;
}
/**
* {@inheritdoc}
*/
public function getListener(string $name): ListenerInterface
{
if (!isset($this->listeners[$name])) {
throw new ListenerNotFoundException($name);
}
return $this->listeners[$name];
}
/**
* {@inheritdoc}
*/
public function getListeners(): array
{
return $this->listeners;
}
}

View file

@ -1,31 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Listener;
interface ListenerRegistryInterface
{
/**
* @param string $name
*
* @return ListenerInterface
*
* @throws ListenerNotFoundException
*/
public function getListener(string $name): ListenerInterface;
/**
* @return array|ListenerInterface[] Name indexed
*/
public function getListeners(): array;
}

View file

@ -1,56 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Listener;
use Psr\Log\LoggerInterface;
final class LoggerListener extends AbstractListener implements BeforeSuiteListenerInterface, BeforeFixtureListenerInterface
{
/**
* @var LoggerInterface
*/
private $logger;
/**
* @param LoggerInterface $logger
*/
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
/**
* {@inheritdoc}
*/
public function beforeSuite(SuiteEvent $suiteEvent, array $options): void
{
$this->logger->notice(sprintf('Running suite "%s"...', $suiteEvent->suite()->getName()));
}
/**
* {@inheritdoc}
*/
public function beforeFixture(FixtureEvent $fixtureEvent, array $options): void
{
$this->logger->notice(sprintf('Running fixture "%s"...', $fixtureEvent->fixture()->getName()));
}
/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'logger';
}
}

View file

@ -1,70 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Listener;
use Doctrine\Common\DataFixtures\Purger\MongoDBPurger;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ODM\MongoDB\DocumentManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
final class MongoDBPurgerListener extends AbstractListener implements BeforeSuiteListenerInterface
{
/**
* @var ManagerRegistry
*/
private $managerRegistry;
/**
* @param ManagerRegistry $managerRegistry
*/
public function __construct(ManagerRegistry $managerRegistry)
{
$this->managerRegistry = $managerRegistry;
}
/**
* {@inheritdoc}
*/
public function beforeSuite(SuiteEvent $suiteEvent, array $options): void
{
foreach ($options['managers'] as $managerName) {
/** @var DocumentManager $manager */
$manager = $this->managerRegistry->getManager($managerName);
$purger = new MongoDBPurger($manager);
$purger->purge();
}
}
/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'mongodb_purger';
}
/**
* {@inheritdoc}
*/
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
{
$optionsNode
->children()
->arrayNode('managers')
->defaultValue([null])
->scalarPrototype()
;
}
}

View file

@ -1,92 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Listener;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
final class ORMPurgerListener extends AbstractListener implements BeforeSuiteListenerInterface
{
/**
* @var ManagerRegistry
*/
private $managerRegistry;
/**
* @var array
*/
private static $purgeModes = [
'delete' => ORMPurger::PURGE_MODE_DELETE,
'truncate' => ORMPurger::PURGE_MODE_TRUNCATE,
];
/**
* @param ManagerRegistry $managerRegistry
*/
public function __construct(ManagerRegistry $managerRegistry)
{
$this->managerRegistry = $managerRegistry;
}
/**
* {@inheritdoc}
*/
public function beforeSuite(SuiteEvent $suiteEvent, array $options): void
{
foreach ($options['managers'] as $managerName) {
/** @var EntityManagerInterface $manager */
$manager = $this->managerRegistry->getManager($managerName);
$purger = new ORMPurger($manager, $options['exclude']);
$purger->setPurgeMode(static::$purgeModes[$options['mode']]);
$purger->purge();
}
}
/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'orm_purger';
}
/**
* {@inheritdoc}
*/
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
{
$optionsNodeBuilder = $optionsNode->children();
$optionsNodeBuilder
->enumNode('mode')
->values(['delete', 'truncate'])
->defaultValue('delete')
;
$optionsNodeBuilder
->arrayNode('managers')
->defaultValue([null])
->scalarPrototype()
;
$optionsNodeBuilder
->arrayNode('exclude')
->defaultValue([])
->scalarPrototype()
;
}
}

View file

@ -1,70 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Listener;
use Doctrine\Common\DataFixtures\Purger\PHPCRPurger;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ODM\PHPCR\DocumentManagerInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
final class PHPCRPurgerListener extends AbstractListener implements BeforeSuiteListenerInterface
{
/**
* @var ManagerRegistry
*/
private $managerRegistry;
/**
* @param ManagerRegistry $managerRegistry
*/
public function __construct(ManagerRegistry $managerRegistry)
{
$this->managerRegistry = $managerRegistry;
}
/**
* {@inheritdoc}
*/
public function beforeSuite(SuiteEvent $suiteEvent, array $options): void
{
foreach ($options['managers'] as $managerName) {
/** @var DocumentManagerInterface $manager */
$manager = $this->managerRegistry->getManager($managerName);
$purger = new PHPCRPurger($manager);
$purger->purge();
}
}
/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'phpcr_purger';
}
/**
* {@inheritdoc}
*/
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
{
$optionsNode
->children()
->arrayNode('managers')
->defaultValue([null])
->scalarPrototype()
;
}
}

View file

@ -1,40 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Listener;
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
final class SuiteEvent
{
/**
* @var SuiteInterface
*/
private $suite;
/**
* @param SuiteInterface $suite
*/
public function __construct(SuiteInterface $suite)
{
$this->suite = $suite;
}
/**
* @return SuiteInterface
*/
public function suite(): SuiteInterface
{
return $this->suite;
}
}

View file

@ -1,28 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Loader;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
final class FixtureLoader implements FixtureLoaderInterface
{
/**
* {@inheritdoc}
*/
public function load(SuiteInterface $suite, FixtureInterface $fixture, array $options): void
{
$fixture->load($options);
}
}

View file

@ -1,27 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Loader;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
interface FixtureLoaderInterface
{
/**
* @param SuiteInterface $suite
* @param FixtureInterface $fixture
* @param array $options
*/
public function load(SuiteInterface $suite, FixtureInterface $fixture, array $options): void;
}

View file

@ -1,80 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Loader;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Sylius\Bundle\FixturesBundle\Listener\AfterFixtureListenerInterface;
use Sylius\Bundle\FixturesBundle\Listener\BeforeFixtureListenerInterface;
use Sylius\Bundle\FixturesBundle\Listener\FixtureEvent;
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
final class HookableFixtureLoader implements FixtureLoaderInterface
{
/**
* @var FixtureLoaderInterface
*/
private $decoratedFixtureLoader;
/**
* @param FixtureLoaderInterface $decoratedFixtureLoader
*/
public function __construct(FixtureLoaderInterface $decoratedFixtureLoader)
{
$this->decoratedFixtureLoader = $decoratedFixtureLoader;
}
/**
* {@inheritdoc}
*/
public function load(SuiteInterface $suite, FixtureInterface $fixture, array $options): void
{
$fixtureEvent = new FixtureEvent($suite, $fixture, $options);
$this->executeBeforeFixtureListeners($suite, $fixtureEvent);
$this->decoratedFixtureLoader->load($suite, $fixture, $options);
$this->executeAfterFixtureListeners($suite, $fixtureEvent);
}
/**
* @param SuiteInterface $suite
* @param FixtureEvent $fixtureEvent
*/
private function executeBeforeFixtureListeners(SuiteInterface $suite, FixtureEvent $fixtureEvent): void
{
foreach ($suite->getListeners() as $listener => $listenerOptions) {
if (!$listener instanceof BeforeFixtureListenerInterface) {
continue;
}
$listener->beforeFixture($fixtureEvent, $listenerOptions);
}
}
/**
* @param SuiteInterface $suite
* @param FixtureEvent $fixtureEvent
*/
private function executeAfterFixtureListeners(SuiteInterface $suite, FixtureEvent $fixtureEvent): void
{
foreach ($suite->getListeners() as $listener => $listenerOptions) {
if (!$listener instanceof AfterFixtureListenerInterface) {
continue;
}
$listener->afterFixture($fixtureEvent, $listenerOptions);
}
}
}

View file

@ -1,79 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Loader;
use Sylius\Bundle\FixturesBundle\Listener\AfterSuiteListenerInterface;
use Sylius\Bundle\FixturesBundle\Listener\BeforeSuiteListenerInterface;
use Sylius\Bundle\FixturesBundle\Listener\SuiteEvent;
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
final class HookableSuiteLoader implements SuiteLoaderInterface
{
/**
* @var SuiteLoaderInterface
*/
private $decoratedSuiteLoader;
/**
* @param SuiteLoaderInterface $decoratedSuiteLoader
*/
public function __construct(SuiteLoaderInterface $decoratedSuiteLoader)
{
$this->decoratedSuiteLoader = $decoratedSuiteLoader;
}
/**
* {@inheritdoc}
*/
public function load(SuiteInterface $suite): void
{
$suiteEvent = new SuiteEvent($suite);
$this->executeBeforeSuiteListeners($suite, $suiteEvent);
$this->decoratedSuiteLoader->load($suite);
$this->executeAfterSuiteListeners($suite, $suiteEvent);
}
/**
* @param SuiteInterface $suite
* @param SuiteEvent $suiteEvent
*/
private function executeBeforeSuiteListeners(SuiteInterface $suite, SuiteEvent $suiteEvent): void
{
foreach ($suite->getListeners() as $listener => $listenerOptions) {
if (!$listener instanceof BeforeSuiteListenerInterface) {
continue;
}
$listener->beforeSuite($suiteEvent, $listenerOptions);
}
}
/**
* @param SuiteInterface $suite
* @param SuiteEvent $suiteEvent
*/
private function executeAfterSuiteListeners(SuiteInterface $suite, SuiteEvent $suiteEvent): void
{
foreach ($suite->getListeners() as $listener => $listenerOptions) {
if (!$listener instanceof AfterSuiteListenerInterface) {
continue;
}
$listener->afterSuite($suiteEvent, $listenerOptions);
}
}
}

View file

@ -1,45 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Loader;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
final class SuiteLoader implements SuiteLoaderInterface
{
/**
* @var FixtureLoaderInterface
*/
private $fixtureLoader;
/**
* @param FixtureLoaderInterface $fixtureLoader
*/
public function __construct(FixtureLoaderInterface $fixtureLoader)
{
$this->fixtureLoader = $fixtureLoader;
}
/**
* {@inheritdoc}
*/
public function load(SuiteInterface $suite): void
{
/** @var FixtureInterface $fixture */
/** @var array $fixtureOptions */
foreach ($suite->getFixtures() as $fixture => $fixtureOptions) {
$this->fixtureLoader->load($suite, $fixture, $fixtureOptions);
}
}
}

View file

@ -1,24 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Loader;
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
interface SuiteLoaderInterface
{
/**
* @param SuiteInterface $suite
*/
public function load(SuiteInterface $suite): void;
}

View file

@ -1,47 +0,0 @@
SyliusFixturesBundle [![Build status...](https://secure.travis-ci.org/Sylius/SyliusFixturesBundle.png?branch=master)](http://travis-ci.org/Sylius/SyliusFixturesBundle)
====================
Configurable fixtures for Symfony2 applications.
Sylius
------
![Sylius](https://demo.sylius.com/assets/shop/img/logo.png)
Sylius is an Open Source eCommerce solution built from decoupled components with powerful API and the highest quality code. [Read more on sylius.com](http://sylius.com).
Documentation
-------------
Documentation is available on [**docs.sylius.com**](http://docs.sylius.com/en/latest/components_and_bundles/bundles/SyliusFixturesBundle/index.html).
Contributing
------------
[This page](http://docs.sylius.com/en/latest/contributing/index.html) contains all the information about contributing to Sylius.
Follow Sylius' Development
--------------------------
If you want to keep up with the updates and latest features, follow us on the following channels:
* [Official Blog](https://sylius.com/blog)
* [Sylius on Twitter](https://twitter.com/Sylius)
* [Sylius on Facebook](https://facebook.com/SyliusEcommerce)
Bug tracking
------------
Sylius uses [GitHub issues](https://github.com/Sylius/Sylius/issues).
If you have found bug, please create an issue.
MIT License
-----------
License can be found [here](https://github.com/Sylius/Sylius/blob/master/LICENSE).
Authors
-------
The bundle was originally created by [Kamil Kokot](http://kamil.kokot.me).
See the list of [contributors](https://github.com/Sylius/Sylius/contributors).

View file

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<imports>
<import resource="services/fixture.xml"/>
<import resource="services/listener.xml"/>
<import resource="services/loader.xml"/>
<import resource="services/logger.xml"/>
<import resource="services/suite.xml"/>
</imports>
</container>

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sylius_fixtures.fixture_registry" class="Sylius\Bundle\FixturesBundle\Fixture\FixtureRegistry" />
</services>
</container>

View file

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sylius_fixtures.listener.mongodb_purger" class="Sylius\Bundle\FixturesBundle\Listener\MongoDBPurgerListener" public="false">
<argument type="service" id="doctrine_mongodb" />
<tag name="sylius_fixtures.listener" />
</service>
</services>
</container>

View file

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sylius_fixtures.listener.orm_purger" class="Sylius\Bundle\FixturesBundle\Listener\ORMPurgerListener" public="false">
<argument type="service" id="doctrine" />
<tag name="sylius_fixtures.listener" />
</service>
</services>
</container>

View file

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sylius_fixtures.listener.phpcr_purger" class="Sylius\Bundle\FixturesBundle\Listener\PHPCRPurgerListener" public="false">
<argument type="service" id="doctrine_phpcr" />
<tag name="sylius_fixtures.listener" />
</service>
</services>
</container>

View file

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sylius_fixtures.listener_registry" class="Sylius\Bundle\FixturesBundle\Listener\ListenerRegistry" public="false" />
<service id="sylius_fixtures.listener.logger" class="Sylius\Bundle\FixturesBundle\Listener\LoggerListener" public="false">
<argument type="service" id="sylius_fixtures.logger" />
<tag name="sylius_fixtures.listener" />
</service>
</services>
</container>

View file

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sylius_fixtures.fixture_loader" class="Sylius\Bundle\FixturesBundle\Loader\HookableFixtureLoader">
<argument type="service">
<service class="Sylius\Bundle\FixturesBundle\Loader\FixtureLoader" />
</argument>
</service>
<service id="sylius_fixtures.suite_loader" class="Sylius\Bundle\FixturesBundle\Loader\HookableSuiteLoader">
<argument type="service">
<service class="Sylius\Bundle\FixturesBundle\Loader\SuiteLoader">
<argument type="service" id="sylius_fixtures.fixture_loader" />
</service>
</argument>
</service>
</services>
</container>

View file

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sylius_fixtures.logger" class="Monolog\Logger">
<argument>sylius_fixtures</argument>
<argument type="collection">
<argument type="service" id="sylius_fixtures.logger.handler.console" />
</argument>
</service>
<service id="sylius_fixtures.logger.handler.console" class="Symfony\Bridge\Monolog\Handler\ConsoleHandler">
<argument>null</argument>
<argument>true</argument>
<argument type="collection">
<argument key="32" type="constant">\Monolog\Logger::NOTICE</argument> <!-- 32 = OutputInterface::VERBOSITY_NORMAL -->
<argument key="64" type="constant">\Monolog\Logger::INFO</argument> <!-- 64 = OutputInterface::VERBOSITY_VERBOSE -->
</argument>
<tag name="kernel.event_subscriber" />
<call method="setFormatter">
<argument type="service" id="sylius_fixtures.logger.formatter.console" />
</call>
</service>
<service id="sylius_fixtures.logger.formatter.console" class="Symfony\Bridge\Monolog\Formatter\ConsoleFormatter">
<argument>%%message%% %%context%% %%extra%%&#10;</argument>
</service>
</services>
</container>

View file

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sylius_fixtures.suite_factory" class="Sylius\Bundle\FixturesBundle\Suite\SuiteFactory" public="false">
<argument type="service" id="sylius_fixtures.fixture_registry" />
<argument type="service" id="sylius_fixtures.listener_registry" />
<argument type="service">
<service class="Symfony\Component\Config\Definition\Processor" />
</argument>
</service>
<service id="sylius_fixtures.suite_registry" class="Sylius\Bundle\FixturesBundle\Suite\LazySuiteRegistry">
<argument type="service" id="sylius_fixtures.suite_factory" />
</service>
</services>
</container>

View file

@ -1,78 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Suite;
final class LazySuiteRegistry implements SuiteRegistryInterface
{
/**
* @var SuiteFactoryInterface
*/
private $suiteFactory;
/**
* @var array
*/
private $suiteDefinitions = [];
/**
* @var array
*/
private $suites = [];
/**
* @param SuiteFactoryInterface $suiteFactory
*/
public function __construct(SuiteFactoryInterface $suiteFactory)
{
$this->suiteFactory = $suiteFactory;
}
/**
* @param string $name
* @param array $configuration
*/
public function addSuite(string $name, array $configuration): void
{
$this->suiteDefinitions[$name] = $configuration;
}
/**
* {@inheritdoc}
*/
public function getSuite(string $name): SuiteInterface
{
if (isset($this->suites[$name])) {
return $this->suites[$name];
}
if (!isset($this->suiteDefinitions[$name])) {
throw new SuiteNotFoundException($name);
}
return $this->suites[$name] = $this->suiteFactory->createSuite($name, $this->suiteDefinitions[$name]);
}
/**
* {@inheritdoc}
*/
public function getSuites(): array
{
$suites = [];
foreach (array_keys($this->suiteDefinitions) as $name) {
$suites[$name] = $this->getSuite($name);
}
return $suites;
}
}

View file

@ -1,96 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Suite;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Sylius\Bundle\FixturesBundle\Listener\ListenerInterface;
use Zend\Stdlib\SplPriorityQueue;
final class Suite implements SuiteInterface
{
/**
* @var string
*/
private $name;
/**
* @var SplPriorityQueue
*/
private $fixtures;
/**
* @var SplPriorityQueue
*/
private $listeners;
/**
* @param string $name
*/
public function __construct(string $name)
{
$this->name = $name;
$this->fixtures = new SplPriorityQueue();
$this->listeners = new SplPriorityQueue();
}
/**
* @param FixtureInterface $fixture
* @param array $options
* @param int $priority
*/
public function addFixture(FixtureInterface $fixture, array $options, int $priority = 0): void
{
$this->fixtures->insert(['fixture' => $fixture, 'options' => $options], $priority);
}
/**
* @param ListenerInterface $listener
* @param array $options
* @param int $priority
*/
public function addListener(ListenerInterface $listener, array $options, int $priority = 0): void
{
$this->listeners->insert(['listener' => $listener, 'options' => $options], $priority);
}
/**
* {@inheritdoc}
*/
public function getName(): string
{
return $this->name;
}
/**
* {@inheritdoc}
*/
public function getFixtures(): iterable
{
$fixtures = clone $this->fixtures;
foreach ($fixtures as $fixture) {
yield $fixture['fixture'] => $fixture['options'];
}
}
/**
* {@inheritdoc}
*/
public function getListeners(): iterable
{
$listeners = clone $this->listeners;
foreach ($listeners as $listener) {
yield $listener['listener'] => $listener['options'];
}
}
}

View file

@ -1,106 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Suite;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureRegistryInterface;
use Sylius\Bundle\FixturesBundle\Listener\ListenerRegistryInterface;
use Symfony\Component\Config\Definition\Processor;
use Webmozart\Assert\Assert;
final class SuiteFactory implements SuiteFactoryInterface
{
/**
* @var FixtureRegistryInterface
*/
private $fixtureRegistry;
/**
* @var ListenerRegistryInterface
*/
private $listenerRegistry;
/**
* @var Processor
*/
private $optionsProcessor;
/**
* @param FixtureRegistryInterface $fixtureRegistry
* @param ListenerRegistryInterface $listenerRegistry
* @param Processor $optionsProcessor
*/
public function __construct(
FixtureRegistryInterface $fixtureRegistry,
ListenerRegistryInterface $listenerRegistry,
Processor $optionsProcessor
) {
$this->fixtureRegistry = $fixtureRegistry;
$this->listenerRegistry = $listenerRegistry;
$this->optionsProcessor = $optionsProcessor;
}
/**
* {@inheritdoc}
*/
public function createSuite(string $name, array $configuration): SuiteInterface
{
Assert::keyExists($configuration, 'fixtures');
Assert::keyExists($configuration, 'listeners');
$suite = new Suite($name);
foreach ($configuration['fixtures'] as $fixtureAlias => $fixtureAttributes) {
$this->addFixtureToSuite($suite, $fixtureAlias, $fixtureAttributes);
}
foreach ($configuration['listeners'] as $listenerName => $listenerAttributes) {
$this->addListenerToSuite($suite, $listenerName, $listenerAttributes);
}
return $suite;
}
/**
* @param Suite $suite
* @param string $fixtureAlias
* @param array $fixtureAttributes
*/
private function addFixtureToSuite(Suite $suite, string $fixtureAlias, array $fixtureAttributes): void
{
Assert::keyExists($fixtureAttributes, 'name');
Assert::keyExists($fixtureAttributes, 'options');
$fixture = $this->fixtureRegistry->getFixture($fixtureAttributes['name']);
$fixtureOptions = $this->optionsProcessor->processConfiguration($fixture, $fixtureAttributes['options']);
$fixturePriority = $fixtureAttributes['priority'] ?? 0;
$suite->addFixture($fixture, $fixtureOptions, $fixturePriority);
}
/**
* @param Suite $suite
* @param string $listenerName
* @param array $listenerAttributes
*/
private function addListenerToSuite(Suite $suite, string $listenerName, array $listenerAttributes): void
{
Assert::keyExists($listenerAttributes, 'options');
$listener = $this->listenerRegistry->getListener($listenerName);
$listenerOptions = $this->optionsProcessor->processConfiguration($listener, $listenerAttributes['options']);
$listenerPriority = $listenerAttributes['priority'] ?? 0;
$suite->addListener($listener, $listenerOptions, $listenerPriority);
}
}

View file

@ -1,25 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Suite;
interface SuiteFactoryInterface
{
/**
* @param string $name
* @param array $configuration
*
* @return SuiteInterface
*/
public function createSuite(string $name, array $configuration): SuiteInterface;
}

View file

@ -1,37 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Suite;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Sylius\Bundle\FixturesBundle\Listener\ListenerInterface;
interface SuiteInterface
{
/**
* @return string
*/
public function getName(): string;
/**
* @return iterable|FixtureInterface[] Fixtures as keys, options as values
*/
public function getFixtures(): iterable;
/**
* @see \Sylius\Bundle\FixturesBundle\Listener\ListenerInterface
*
* @return iterable|ListenerInterface[] Listeners as keys, options as values
*/
public function getListeners(): iterable;
}

View file

@ -1,26 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Suite;
final class SuiteNotFoundException extends \InvalidArgumentException
{
/**
* @param string $name
* @param \Exception|null $previous
*/
public function __construct(string $name, ?\Exception $previous = null)
{
parent::__construct(sprintf('Suite with name "%s" could not be found!', $name), 0, $previous);
}
}

View file

@ -1,31 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Suite;
interface SuiteRegistryInterface
{
/**
* @param string $name
*
* @return SuiteInterface
*
* @throws SuiteNotFoundException
*/
public function getSuite(string $name): SuiteInterface;
/**
* @return array|SuiteInterface[]
*/
public function getSuites(): array;
}

View file

@ -1,33 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle;
use Sylius\Bundle\FixturesBundle\DependencyInjection\Compiler\FixtureRegistryPass;
use Sylius\Bundle\FixturesBundle\DependencyInjection\Compiler\ListenerRegistryPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
final class SyliusFixturesBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container): void
{
parent::build($container);
$container->addCompilerPass(new FixtureRegistryPass());
$container->addCompilerPass(new ListenerRegistryPass());
}
}

View file

@ -1,48 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Tests\DependencyInjection\Compiler;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
use Sylius\Bundle\FixturesBundle\DependencyInjection\Compiler\FixtureRegistryPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
final class FixtureRegistryPassTest extends AbstractCompilerPassTestCase
{
/**
* @test
*/
public function it_registers_fixtures(): void
{
$this->setDefinition('sylius_fixtures.fixture_registry', new Definition());
$this->setDefinition('acme.fixture', (new Definition())->addTag('sylius_fixtures.fixture'));
$this->compile();
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
'sylius_fixtures.fixture_registry',
'addFixture',
[new Reference('acme.fixture')]
);
}
/**
* {@inheritdoc}
*/
protected function registerCompilerPass(ContainerBuilder $container): void
{
$container->addCompilerPass(new FixtureRegistryPass());
}
}

View file

@ -1,48 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Tests\DependencyInjection\Compiler;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
use Sylius\Bundle\FixturesBundle\DependencyInjection\Compiler\ListenerRegistryPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
final class ListenerRegistryPassTest extends AbstractCompilerPassTestCase
{
/**
* @test
*/
public function it_registers_listeners(): void
{
$this->setDefinition('sylius_fixtures.listener_registry', new Definition());
$this->setDefinition('acme.listener', (new Definition())->addTag('sylius_fixtures.listener'));
$this->compile();
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
'sylius_fixtures.listener_registry',
'addListener',
[new Reference('acme.listener')]
);
}
/**
* {@inheritdoc}
*/
protected function registerCompilerPass(ContainerBuilder $container): void
{
$container->addCompilerPass(new ListenerRegistryPass());
}
}

View file

@ -1,338 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Tests\DependencyInjection;
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
use PHPUnit\Framework\TestCase;
use Sylius\Bundle\FixturesBundle\DependencyInjection\Configuration;
use Symfony\Component\Config\Definition\ConfigurationInterface;
final class ConfigurationTest extends TestCase
{
use ConfigurationTestCaseTrait;
/**
* @test
*/
public function suite_can_have_one_fixture(): void
{
$this->assertConfigurationIsValid(
[['suites' => ['suite' => ['fixtures' => ['fixture' => null]]]]],
'suites.*.fixtures'
);
}
/**
* @test
*/
public function multiple_suites_are_allowed(): void
{
$this->assertConfigurationIsValid(
[['suites' => [
'first_suite' => ['fixtures' => ['fixture' => null]],
'second_suite' => ['fixtures' => ['fixture' => null]],
]]],
'suites.*.fixtures'
);
}
/**
* @test
*/
public function consecutive_configurations_can_add_suites(): void
{
$this->assertProcessedConfigurationEquals(
[
['suites' => [
'first_suite' => ['fixtures' => ['fixture' => null]],
]],
['suites' => [
'second_suite' => ['fixtures' => ['fixture' => null]],
]],
],
['suites' => [
'first_suite' => ['fixtures' => ['fixture' => ['name' => 'fixture', 'options' => [[]], 'priority' => 0]]],
'second_suite' => ['fixtures' => ['fixture' => ['name' => 'fixture', 'options' => [[]], 'priority' => 0]]],
]],
'suites.*.fixtures'
);
}
/**
* @test
*/
public function suite_can_have_multiple_fixtures(): void
{
$this->assertConfigurationIsValid(
[['suites' => ['suite' => ['fixtures' => [
'first_fixture' => null,
'second_fixture' => null,
]]]]],
'suites.*.fixtures'
);
}
/**
* @test
*/
public function consecutive_configurations_can_remove_a_fixture_from_the_suite(): void
{
$this->assertProcessedConfigurationEquals(
[
['suites' => ['suite' => ['fixtures' => [
'first_fixture' => null,
'second_fixture' => null,
]]]],
['suites' => ['suite' => ['fixtures' => [
'second_fixture' => false,
]]]],
],
['suites' => ['suite' => ['fixtures' => [
'first_fixture' => ['name' => 'first_fixture', 'options' => [[]], 'priority' => 0],
]]]],
'suites.*.fixtures'
);
}
/**
* @test
*/
public function consecutive_configurations_can_add_fixtures_to_the_suite(): void
{
$this->assertProcessedConfigurationEquals(
[
['suites' => ['suite' => ['fixtures' => [
'first_fixture' => null,
]]]],
['suites' => ['suite' => ['fixtures' => [
'second_fixture' => null,
]]]],
],
['suites' => ['suite' => ['fixtures' => [
'first_fixture' => ['name' => 'first_fixture', 'options' => [[]], 'priority' => 0],
'second_fixture' => ['name' => 'second_fixture', 'options' => [[]], 'priority' => 0],
]]]],
'suites.*.fixtures'
);
}
/**
* @test
*/
public function all_fixture_options_from_consecutive_configurations_are_collected(): void
{
$this->assertProcessedConfigurationEquals(
[
['suites' => ['suite' => ['fixtures' => [
'fixture' => ['options' => ['option' => 4]],
]]]],
['suites' => ['suite' => ['fixtures' => [
'fixture' => ['options' => ['option' => 2]],
]]]],
],
['suites' => ['suite' => ['fixtures' => [
'fixture' => ['name' => 'fixture', 'options' => [['option' => 4], ['option' => 2]], 'priority' => 0],
]]]],
'suites.*.fixtures'
);
}
/**
* @test
*/
public function fixture_options_are_not_replaced_implicitly(): void
{
$this->assertProcessedConfigurationEquals(
[
['suites' => ['suite' => ['fixtures' => [
'fixture' => ['options' => ['option' => 4]],
]]]],
['suites' => ['suite' => ['fixtures' => [
'fixture' => null,
]]]],
],
['suites' => ['suite' => ['fixtures' => [
'fixture' => ['name' => 'fixture', 'options' => [['option' => 4]], 'priority' => 0],
]]]],
'suites.*.fixtures'
);
}
/**
* @test
*/
public function fixtures_options_are_an_array(): void
{
$this->assertPartialConfigurationIsInvalid(
[['suites' => ['suite' => ['fixtures' => ['fixture' => [
'options' => 42,
]]]]]],
'suites.*.fixtures'
);
$this->assertPartialConfigurationIsInvalid(
[['suites' => ['suite' => ['fixtures' => ['fixture' => [
'options' => 'string string',
]]]]]],
'suites.*.fixtures'
);
}
/**
* @test
*/
public function fixtures_options_may_contain_nested_arrays(): void
{
$this->assertProcessedConfigurationEquals(
[['suites' => ['suite' => ['fixtures' => ['fixture' => [
'options' => ['nested' => ['key' => 'value']],
]]]]]],
['suites' => ['suite' => ['fixtures' => ['fixture' => [
'options' => [['nested' => ['key' => 'value']]],
'name' => 'fixture', // FIXME: something is wrong inside the test library and it's not excluded
]]]]],
'suites.*.fixtures.*.options'
);
}
/**
* @test
*/
public function listeners_options_are_an_array(): void
{
$this->assertPartialConfigurationIsInvalid(
[['suites' => ['suite' => ['listeners' => ['listener' => [
'options' => 42,
]]]]]],
'suites.*.listeners'
);
$this->assertPartialConfigurationIsInvalid(
[['suites' => ['suite' => ['listeners' => ['listener' => [
'options' => 'string string',
]]]]]],
'suites.*.listeners'
);
}
/**
* @test
*/
public function listeners_options_may_contain_nested_arrays(): void
{
$this->assertProcessedConfigurationEquals(
[['suites' => ['suite' => ['listeners' => ['listener' => [
'options' => ['nested' => ['key' => 'value']],
]]]]]],
['suites' => ['suite' => ['listeners' => ['listener' => [
'options' => [['nested' => ['key' => 'value']]],
]]]]],
'suites.*.listeners.*.options'
);
}
/**
* @test
*/
public function consecutive_configurations_can_remove_a_listener_from_the_suite(): void
{
$this->assertProcessedConfigurationEquals(
[
['suites' => ['suite' => ['listeners' => [
'first_listener' => null,
'second_listener' => null,
]]]],
['suites' => ['suite' => ['listeners' => [
'second_listener' => false,
]]]],
],
['suites' => ['suite' => ['listeners' => [
'first_listener' => ['options' => [[]], 'priority' => 0],
]]]],
'suites.*.listeners'
);
}
/**
* @test
*/
public function consecutive_configurations_can_add_a_listener_to_the_suite(): void
{
$this->assertProcessedConfigurationEquals(
[
['suites' => ['suite' => ['listeners' => [
'first_listener' => null,
]]]],
['suites' => ['suite' => ['listeners' => [
'second_listener' => null,
]]]],
],
['suites' => ['suite' => ['listeners' => [
'first_listener' => ['options' => [[]], 'priority' => 0],
'second_listener' => ['options' => [[]], 'priority' => 0],
]]]],
'suites.*.listeners'
);
}
/**
* @test
*/
public function fixtures_can_be_aliased_with_different_names(): void
{
$this->assertProcessedConfigurationEquals(
[
['suites' => ['suite' => ['fixtures' => [
'admin_user' => ['name' => 'user', 'options' => ['admin' => true]],
'regular_user' => ['name' => 'user', 'options' => ['admin' => false]],
]]]],
],
['suites' => ['suite' => ['fixtures' => [
'admin_user' => ['name' => 'user', 'options' => [['admin' => true]], 'priority' => 0],
'regular_user' => ['name' => 'user', 'options' => [['admin' => false]], 'priority' => 0],
]]]],
'suites.*.fixtures'
);
}
/**
* @test
*/
public function consecutive_configurations_can_add_aliased_fixtures_to_the_suite(): void
{
$this->assertProcessedConfigurationEquals(
[
['suites' => ['suite' => ['fixtures' => [
'admin_user' => ['name' => 'user', 'options' => ['admin' => true]],
]]]],
['suites' => ['suite' => ['fixtures' => [
'regular_user' => ['name' => 'user', 'options' => ['admin' => false]],
]]]],
],
['suites' => ['suite' => ['fixtures' => [
'admin_user' => ['name' => 'user', 'options' => [['admin' => true]], 'priority' => 0],
'regular_user' => ['name' => 'user', 'options' => [['admin' => false]], 'priority' => 0],
]]]],
'suites.*.fixtures'
);
}
/**
* {@inheritdoc}
*/
protected function getConfiguration(): ConfigurationInterface
{
return new Configuration();
}
}

View file

@ -1,52 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Tests\DependencyInjection;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Sylius\Bundle\FixturesBundle\DependencyInjection\SyliusFixturesExtension;
final class SyliusFixturesExtensionTest extends AbstractExtensionTestCase
{
/**
* @test
*/
public function it_does_not_crash_if_no_suite_is_configured(): void
{
$this->load();
}
/**
* @test
*/
public function it_registers_configured_suites(): void
{
$this->load(['suites' => [
'suite_name' => [],
]]);
$suiteRegistryDefinition = $this->container->findDefinition('sylius_fixtures.suite_registry');
$suiteMethodCall = $suiteRegistryDefinition->getMethodCalls()[0];
static::assertSame('addSuite', $suiteMethodCall[0]);
static::assertSame('suite_name', $suiteMethodCall[1][0]);
}
/**
* {@inheritdoc}
*/
protected function getContainerExtensions(): array
{
return [new SyliusFixturesExtension()];
}
}

View file

@ -1,49 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Tests\Listener;
use Doctrine\Common\Persistence\ManagerRegistry;
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
use PHPUnit\Framework\TestCase;
use Sylius\Bundle\FixturesBundle\Listener\MongoDBPurgerListener;
use Symfony\Component\Config\Definition\ConfigurationInterface;
final class MongoDBPurgerListenerTest extends TestCase
{
use ConfigurationTestCaseTrait;
/**
* @test
*/
public function managers_are_set_to_null_by_default(): void
{
$this->assertProcessedConfigurationEquals([[]], ['managers' => [null]], 'managers');
}
/**
* @test
*/
public function managers_are_optional(): void
{
$this->assertProcessedConfigurationEquals([['managers' => ['custom']]], ['managers' => ['custom']], 'managers');
}
/**
* {@inheritdoc}
*/
protected function getConfiguration(): ConfigurationInterface
{
return new MongoDBPurgerListener($this->getMockBuilder(ManagerRegistry::class)->getMock());
}
}

View file

@ -1,73 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Tests\Listener;
use Doctrine\Common\Persistence\ManagerRegistry;
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
use PHPUnit\Framework\TestCase;
use Sylius\Bundle\FixturesBundle\Listener\ORMPurgerListener;
use Symfony\Component\Config\Definition\ConfigurationInterface;
final class ORMPurgerListenerTest extends TestCase
{
use ConfigurationTestCaseTrait;
/**
* @test
*/
public function purge_mode_is_set_to_delete_by_default(): void
{
$this->assertProcessedConfigurationEquals([[]], ['mode' => 'delete'], 'mode');
}
/**
* @test
*/
public function purge_mode_can_be_changed_to_truncate(): void
{
$this->assertProcessedConfigurationEquals([['mode' => 'truncate']], ['mode' => 'truncate'], 'mode');
}
/**
* @test
*/
public function purge_mode_can_be_either_delete_or_truncate(): void
{
$this->assertPartialConfigurationIsInvalid([['mode' => 'lol']], 'mode');
}
/**
* @test
*/
public function managers_are_set_to_null_by_default(): void
{
$this->assertProcessedConfigurationEquals([[]], ['managers' => [null]], 'managers');
}
/**
* @test
*/
public function managers_are_optional(): void
{
$this->assertProcessedConfigurationEquals([['managers' => ['custom']]], ['managers' => ['custom']], 'managers');
}
/**
* {@inheritdoc}
*/
protected function getConfiguration(): ConfigurationInterface
{
return new ORMPurgerListener($this->getMockBuilder(ManagerRegistry::class)->getMock());
}
}

View file

@ -1,49 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Tests\Listener;
use Doctrine\Common\Persistence\ManagerRegistry;
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
use PHPUnit\Framework\TestCase;
use Sylius\Bundle\FixturesBundle\Listener\PHPCRPurgerListener;
use Symfony\Component\Config\Definition\ConfigurationInterface;
final class PHPCRPurgerListenerTest extends TestCase
{
use ConfigurationTestCaseTrait;
/**
* @test
*/
public function managers_are_set_to_null_by_default(): void
{
$this->assertProcessedConfigurationEquals([[]], ['managers' => [null]], 'managers');
}
/**
* @test
*/
public function managers_are_optional(): void
{
$this->assertProcessedConfigurationEquals([['managers' => ['custom']]], ['managers' => ['custom']], 'managers');
}
/**
* {@inheritdoc}
*/
protected function getConfiguration(): ConfigurationInterface
{
return new PHPCRPurgerListener($this->getMockBuilder(ManagerRegistry::class)->getMock());
}
}

View file

@ -1,73 +0,0 @@
{
"name": "sylius/fixtures-bundle",
"type": "symfony-bundle",
"description": "Configurable fixtures for Symfony applications.",
"keywords": ["sylius", "fixtures", "symfony"],
"homepage": "http://sylius.com",
"license": "MIT",
"authors": [
{
"name": "Kamil Kokot",
"homepage": "http://kamil.kokot.me"
},
{
"name": "Sylius project",
"homepage": "http://sylius.com"
},
{
"name": "Community contributions",
"homepage": "http://github.com/Sylius/Sylius/contributors"
}
],
"require": {
"php": "^7.1",
"doctrine/data-fixtures": "^1.2",
"monolog/monolog": "^1.8",
"symfony/framework-bundle": "^3.4",
"symfony/monolog-bridge": "^3.4",
"webmozart/assert": "^1.0",
"zendframework/zend-stdlib": "^3.0"
},
"require-dev": {
"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^1.3",
"matthiasnoback/symfony-config-test": "^3.0",
"matthiasnoback/symfony-dependency-injection-test": "^2.0",
"phpspec/phpspec": "^4.0",
"phpunit/phpunit": "^6.5",
"twig/twig": "^2.0",
"symfony/browser-kit": "^3.4",
"symfony/dependency-injection": "^3.4",
"symfony/templating": "^3.4",
"symfony/translation": "^3.4",
"symfony/twig-bundle": "^3.4",
"symfony/security-csrf": "^3.4",
"polishsymfonycommunity/symfony-mocker-container": "^1.0"
},
"config": {
"bin-dir": "bin"
},
"autoload": {
"psr-4": { "Sylius\\Bundle\\FixturesBundle\\": "" }
},
"autoload-dev": {
"psr-4": {
"Sylius\\Bundle\\FixturesBundle\\spec\\": "spec/",
"AppBundle\\": "test/src/AppBundle/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": [
{
"type": "path",
"url": "../../*/*"
}
],
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
}
}

View file

@ -1,17 +0,0 @@
{
"source": {
"directories": [
"."
],
"excludes": [
"bin",
"spec",
"Tests",
"vendor"
]
},
"timeout": 2,
"logs": {
"text": "humbuglog.txt"
}
}

View file

@ -1,5 +0,0 @@
suites:
main:
namespace: Sylius\Bundle\FixturesBundle
psr4_prefix: Sylius\Bundle\FixturesBundle
src_path: .

View file

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<server name="KERNEL_DIR" value="test/app/" />
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />
</php>
<testsuites>
<testsuite name="Sylius Test Suite">
<directory>./Tests</directory>
</testsuite>
<testsuite name="SyliusFixturesBundle Test Suite">
<directory>./test/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./Tests</directory>
</whitelist>
</filter>
</phpunit>

View file

@ -1,34 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace spec\Sylius\Bundle\FixturesBundle\Fixture;
use PhpSpec\ObjectBehavior;
final class FixtureNotFoundExceptionSpec extends ObjectBehavior
{
function let(): void
{
$this->beConstructedWith('fixture_name');
}
function it_is_an_invalid_argument_exception(): void
{
$this->shouldHaveType(\InvalidArgumentException::class);
}
function it_has_preformatted_message(): void
{
$this->getMessage()->shouldReturn('Fixture with name "fixture_name" could not be found!');
}
}

View file

@ -1,59 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace spec\Sylius\Bundle\FixturesBundle\Fixture;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureNotFoundException;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureRegistryInterface;
final class FixtureRegistrySpec extends ObjectBehavior
{
function it_implements_fixture_registry_interface(): void
{
$this->shouldImplement(FixtureRegistryInterface::class);
}
function it_has_a_fixtures(FixtureInterface $fixture): void
{
$fixture->getName()->willReturn('fixture');
$this->addFixture($fixture);
$this->getFixture('fixture')->shouldReturn($fixture);
$this->getFixtures()->shouldReturn(['fixture' => $fixture]);
}
function it_throws_an_exception_if_trying_to_another_fixture_with_the_same_name(
FixtureInterface $fixture,
FixtureInterface $anotherFixture
): void {
$fixture->getName()->willReturn('fixture');
$anotherFixture->getName()->willReturn('fixture');
$this->addFixture($fixture);
$this->shouldThrow(\InvalidArgumentException::class)->during('addFixture', [$fixture]);
$this->shouldThrow(\InvalidArgumentException::class)->during('addFixture', [$anotherFixture]);
}
function it_returns_an_empty_fixtures_list_if_it_does_not_have_any_fixtures(): void
{
$this->getFixtures()->shouldReturn([]);
}
function it_throws_an_exception_if_trying_to_get_unexisting_fixture_by_name(): void
{
$this->shouldThrow(FixtureNotFoundException::class)->during('getFixture', ['fixture']);
}
}

View file

@ -1,34 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace spec\Sylius\Bundle\FixturesBundle\Listener;
use PhpSpec\ObjectBehavior;
final class ListenerNotFoundExceptionSpec extends ObjectBehavior
{
function let(): void
{
$this->beConstructedWith('listener_name');
}
function it_is_an_invalid_argument_exception(): void
{
$this->shouldHaveType(\InvalidArgumentException::class);
}
function it_has_preformatted_message(): void
{
$this->getMessage()->shouldReturn('Listener with name "listener_name" could not be found!');
}
}

View file

@ -1,59 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace spec\Sylius\Bundle\FixturesBundle\Listener;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\FixturesBundle\Listener\ListenerInterface;
use Sylius\Bundle\FixturesBundle\Listener\ListenerNotFoundException;
use Sylius\Bundle\FixturesBundle\Listener\ListenerRegistryInterface;
final class ListenerRegistrySpec extends ObjectBehavior
{
function it_implements_listener_registry_interface(): void
{
$this->shouldImplement(ListenerRegistryInterface::class);
}
function it_has_a_listener(ListenerInterface $listener): void
{
$listener->getName()->willReturn('listener_name');
$this->addListener($listener);
$this->getListener('listener_name')->shouldReturn($listener);
$this->getListeners()->shouldReturn(['listener_name' => $listener]);
}
function it_throws_an_exception_if_trying_to_another_listener_with_the_same_name(
ListenerInterface $listener,
ListenerInterface $anotherListener
): void {
$listener->getName()->willReturn('listener_name');
$anotherListener->getName()->willReturn('listener_name');
$this->addListener($listener);
$this->shouldThrow(\InvalidArgumentException::class)->during('addListener', [$listener]);
$this->shouldThrow(\InvalidArgumentException::class)->during('addListener', [$anotherListener]);
}
function it_returns_an_empty_listeners_list_if_it_does_not_have_any_listeners(): void
{
$this->getListeners()->shouldReturn([]);
}
function it_throws_an_exception_if_trying_to_get_unexisting_listener_by_name(): void
{
$this->shouldThrow(ListenerNotFoundException::class)->during('getListener', ['listener_name']);
}
}

View file

@ -1,70 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace spec\Sylius\Bundle\FixturesBundle\Listener;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Psr\Log\LoggerInterface;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Sylius\Bundle\FixturesBundle\Listener\BeforeFixtureListenerInterface;
use Sylius\Bundle\FixturesBundle\Listener\BeforeSuiteListenerInterface;
use Sylius\Bundle\FixturesBundle\Listener\FixtureEvent;
use Sylius\Bundle\FixturesBundle\Listener\ListenerInterface;
use Sylius\Bundle\FixturesBundle\Listener\SuiteEvent;
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
final class LoggerListenerSpec extends ObjectBehavior
{
function let(LoggerInterface $logger): void
{
$this->beConstructedWith($logger);
}
function it_implements_listener_interface(): void
{
$this->shouldImplement(ListenerInterface::class);
}
function it_listens_for_before_suite_events(): void
{
$this->shouldImplement(BeforeSuiteListenerInterface::class);
}
function it_listens_for_before_fixture_events(): void
{
$this->shouldImplement(BeforeFixtureListenerInterface::class);
}
function it_logs_suite_name_on_before_suite_event(LoggerInterface $logger, SuiteInterface $suite): void
{
$suite->getName()->willReturn('uber_suite');
$logger->notice(Argument::that(function ($argument) use ($suite) {
return false !== strpos($argument, $suite->getWrappedObject()->getName());
}))->shouldBeCalled();
$this->beforeSuite(new SuiteEvent($suite->getWrappedObject()), []);
}
function it_logs_fixture_name_on_before_fixture_event(LoggerInterface $logger, SuiteInterface $suite, FixtureInterface $fixture): void
{
$fixture->getName()->willReturn('uber_fixture');
$logger->notice(Argument::that(function ($argument) use ($fixture) {
return false !== strpos($argument, $fixture->getWrappedObject()->getName());
}))->shouldBeCalled();
$this->beforeFixture(new FixtureEvent($suite->getWrappedObject(), $fixture->getWrappedObject(), []), []);
}
}

View file

@ -1,34 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace spec\Sylius\Bundle\FixturesBundle\Loader;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Sylius\Bundle\FixturesBundle\Loader\FixtureLoaderInterface;
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
final class FixtureLoaderSpec extends ObjectBehavior
{
function it_implements_fixture_loader_interface(): void
{
$this->shouldImplement(FixtureLoaderInterface::class);
}
function it_loads_a_fixture(SuiteInterface $suite, FixtureInterface $fixture): void
{
$fixture->load(['options'])->shouldBeCalled();
$this->load($suite, $fixture, ['options']);
}
}

View file

@ -1,104 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace spec\Sylius\Bundle\FixturesBundle\Loader;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Sylius\Bundle\FixturesBundle\Listener\AfterFixtureListenerInterface;
use Sylius\Bundle\FixturesBundle\Listener\BeforeFixtureListenerInterface;
use Sylius\Bundle\FixturesBundle\Listener\FixtureEvent;
use Sylius\Bundle\FixturesBundle\Loader\FixtureLoaderInterface;
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
final class HookableFixtureLoaderSpec extends ObjectBehavior
{
function let(FixtureLoaderInterface $decoratedFixtureLoader): void
{
$this->beConstructedWith($decoratedFixtureLoader);
}
function it_implements_fixture_loader_interface(): void
{
$this->shouldImplement(FixtureLoaderInterface::class);
}
function it_delegates_fixture_loading_to_the_base_loader(
FixtureLoaderInterface $decoratedFixtureLoader,
SuiteInterface $suite,
FixtureInterface $fixture
): void {
$suite->getListeners()->willReturn([]);
$decoratedFixtureLoader->load($suite, $fixture, ['fixture_option' => 'fixture_value'])->shouldBeCalled();
$this->load($suite, $fixture, ['fixture_option' => 'fixture_value']);
}
function it_executes_before_fixture_listeners(
FixtureLoaderInterface $decoratedFixtureLoader,
SuiteInterface $suite,
FixtureInterface $fixture,
BeforeFixtureListenerInterface $beforeFixtureListener
): void {
$suite->getListeners()->will(function () use ($beforeFixtureListener) {
yield $beforeFixtureListener->getWrappedObject() => [];
});
$beforeFixtureListener->beforeFixture(new FixtureEvent($suite->getWrappedObject(), $fixture->getWrappedObject(), ['fixture_option' => 'fixture_value']), [])->shouldBeCalledTimes(1);
$decoratedFixtureLoader->load($suite, $fixture, ['fixture_option' => 'fixture_value'])->shouldBeCalled();
$this->load($suite, $fixture, ['fixture_option' => 'fixture_value']);
}
function it_executes_after_fixture_listeners(
FixtureLoaderInterface $decoratedFixtureLoader,
SuiteInterface $suite,
FixtureInterface $fixture,
AfterFixtureListenerInterface $afterFixtureListener
): void {
$suite->getListeners()->will(function () use ($afterFixtureListener) {
yield $afterFixtureListener->getWrappedObject() => [];
});
$decoratedFixtureLoader->load($suite, $fixture, ['fixture_option' => 'fixture_value'])->shouldBeCalled();
$afterFixtureListener->afterFixture(new FixtureEvent($suite->getWrappedObject(), $fixture->getWrappedObject(), ['fixture_option' => 'fixture_value']), [])->shouldBeCalledTimes(1);
$this->load($suite, $fixture, ['fixture_option' => 'fixture_value']);
}
function it_executes_customized_fixture_listeners(
FixtureLoaderInterface $decoratedFixtureLoader,
SuiteInterface $suite,
FixtureInterface $fixture,
BeforeFixtureListenerInterface $beforeFixtureListener,
AfterFixtureListenerInterface $afterFixtureListener
): void {
$suite->getListeners()->will(function () use ($beforeFixtureListener, $afterFixtureListener) {
yield $beforeFixtureListener->getWrappedObject() => ['listener_option1' => 'listener_value1'];
yield $afterFixtureListener->getWrappedObject() => ['listener_option2' => 'listener_value2'];
});
$fixtureEvent = new FixtureEvent($suite->getWrappedObject(), $fixture->getWrappedObject(), ['fixture_option' => 'fixture_value']);
$beforeFixtureListener->beforeFixture($fixtureEvent, ['listener_option1' => 'listener_value1'])->shouldBeCalledTimes(1);
$decoratedFixtureLoader->load($suite, $fixture, ['fixture_option' => 'fixture_value'])->shouldBeCalled();
$afterFixtureListener->afterFixture($fixtureEvent, ['listener_option2' => 'listener_value2'])->shouldBeCalledTimes(1);
$this->load($suite, $fixture, ['fixture_option' => 'fixture_value']);
}
}

View file

@ -1,95 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace spec\Sylius\Bundle\FixturesBundle\Loader;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\FixturesBundle\Listener\AfterSuiteListenerInterface;
use Sylius\Bundle\FixturesBundle\Listener\BeforeSuiteListenerInterface;
use Sylius\Bundle\FixturesBundle\Listener\SuiteEvent;
use Sylius\Bundle\FixturesBundle\Loader\SuiteLoaderInterface;
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
final class HookableSuiteLoaderSpec extends ObjectBehavior
{
function let(SuiteLoaderInterface $decoratedSuiteLoader): void
{
$this->beConstructedWith($decoratedSuiteLoader);
}
function it_implements_suite_loader_interface(): void
{
$this->shouldImplement(SuiteLoaderInterface::class);
}
function it_delegates_suite_loading_to_the_base_loader(SuiteLoaderInterface $decoratedSuiteLoader, SuiteInterface $suite): void
{
$suite->getListeners()->willReturn([]);
$decoratedSuiteLoader->load($suite)->shouldBeCalled();
$this->load($suite);
}
function it_executes_before_suite_listeners(
SuiteLoaderInterface $decoratedSuiteLoader,
SuiteInterface $suite,
BeforeSuiteListenerInterface $beforeSuiteListener
): void {
$suite->getListeners()->will(function () use ($beforeSuiteListener) {
yield $beforeSuiteListener->getWrappedObject() => [];
});
$beforeSuiteListener->beforeSuite(new SuiteEvent($suite->getWrappedObject()), [])->shouldBeCalledTimes(1);
$decoratedSuiteLoader->load($suite)->shouldBeCalled();
$this->load($suite);
}
function it_executes_after_suite_listeners(
SuiteLoaderInterface $decoratedSuiteLoader,
SuiteInterface $suite,
AfterSuiteListenerInterface $afterSuiteListener
): void {
$suite->getListeners()->will(function () use ($afterSuiteListener) {
yield $afterSuiteListener->getWrappedObject() => [];
});
$decoratedSuiteLoader->load($suite)->shouldBeCalled();
$afterSuiteListener->afterSuite(new SuiteEvent($suite->getWrappedObject()), [])->shouldBeCalledTimes(1);
$this->load($suite);
}
function it_executes_customized_suite_listeners(
SuiteLoaderInterface $decoratedSuiteLoader,
SuiteInterface $suite,
BeforeSuiteListenerInterface $beforeSuiteListener,
AfterSuiteListenerInterface $afterSuiteListener
): void {
$suite->getListeners()->will(function () use ($beforeSuiteListener, $afterSuiteListener) {
yield $beforeSuiteListener->getWrappedObject() => ['listener_option1' => 'listener_value1'];
yield $afterSuiteListener->getWrappedObject() => ['listener_option2' => 'listener_value2'];
});
$beforeSuiteListener->beforeSuite(new SuiteEvent($suite->getWrappedObject()), ['listener_option1' => 'listener_value1'])->shouldBeCalledTimes(1);
$decoratedSuiteLoader->load($suite)->shouldBeCalled();
$afterSuiteListener->afterSuite(new SuiteEvent($suite->getWrappedObject()), ['listener_option2' => 'listener_value2'])->shouldBeCalledTimes(1);
$this->load($suite);
}
}

View file

@ -1,50 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace spec\Sylius\Bundle\FixturesBundle\Loader;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Sylius\Bundle\FixturesBundle\Loader\FixtureLoaderInterface;
use Sylius\Bundle\FixturesBundle\Loader\SuiteLoaderInterface;
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
final class SuiteLoaderSpec extends ObjectBehavior
{
function let(FixtureLoaderInterface $fixtureLoader): void
{
$this->beConstructedWith($fixtureLoader);
}
function it_implements_suite_loader_interface(): void
{
$this->shouldImplement(SuiteLoaderInterface::class);
}
function it_loads_suite_fixtures(
FixtureLoaderInterface $fixtureLoader,
SuiteInterface $suite,
FixtureInterface $firstFixture,
FixtureInterface $secondFixture
): void {
$suite->getFixtures()->will(function () use ($firstFixture, $secondFixture) {
yield $firstFixture->getWrappedObject() => ['options 1'];
yield $secondFixture->getWrappedObject() => ['options 2'];
});
$fixtureLoader->load($suite, $firstFixture, ['options 1'])->shouldBeCalled();
$fixtureLoader->load($suite, $secondFixture, ['options 2'])->shouldBeCalled();
$this->load($suite);
}
}

View file

@ -1,63 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace spec\Sylius\Bundle\FixturesBundle\Suite;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\FixturesBundle\Suite\SuiteFactoryInterface;
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
use Sylius\Bundle\FixturesBundle\Suite\SuiteNotFoundException;
use Sylius\Bundle\FixturesBundle\Suite\SuiteRegistryInterface;
final class LazySuiteRegistrySpec extends ObjectBehavior
{
function let(SuiteFactoryInterface $suiteFactory): void
{
$this->beConstructedWith($suiteFactory);
}
function it_implements_suite_registry_interface(): void
{
$this->shouldImplement(SuiteRegistryInterface::class);
}
function it_returns_a_constructed_suite(SuiteFactoryInterface $suiteFactory, SuiteInterface $suite): void
{
$this->addSuite('suite_name', ['fixtures' => []]);
$suiteFactory->createSuite('suite_name', ['fixtures' => []])->willReturn($suite);
$this->getSuite('suite_name')->shouldReturn($suite);
$this->getSuites()->shouldReturn(['suite_name' => $suite]);
}
function it_constructs_a_suite_only_once(SuiteFactoryInterface $suiteFactory, SuiteInterface $suite): void
{
$this->addSuite('suite_name', ['fixtures' => []]);
$suiteFactory->createSuite('suite_name', ['fixtures' => []])->shouldBeCalledTimes(1)->willReturn($suite);
$this->getSuite('suite_name')->shouldReturn($suite);
$this->getSuite('suite_name')->shouldReturn($suite);
}
function it_returns_an_empty_suites_list_if_none_was_registered(): void
{
$this->getSuites()->shouldReturn([]);
}
function it_throws_an_exception_if_trying_to_get_unexisting_suite(): void
{
$this->shouldThrow(SuiteNotFoundException::class)->during('getSuite', ['the_river_snake_is_dangerous']);
}
}

View file

@ -1,223 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace spec\Sylius\Bundle\FixturesBundle\Suite;
use PhpSpec\ObjectBehavior;
use PhpSpec\Wrapper\Collaborator;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureRegistryInterface;
use Sylius\Bundle\FixturesBundle\Listener\ListenerInterface;
use Sylius\Bundle\FixturesBundle\Listener\ListenerRegistryInterface;
use Sylius\Bundle\FixturesBundle\Suite\SuiteFactoryInterface;
use Symfony\Component\Config\Definition\Processor;
final class SuiteFactorySpec extends ObjectBehavior
{
function let(FixtureRegistryInterface $fixtureRegistry, ListenerRegistryInterface $listenerRegistry, Processor $optionsProcessor): void
{
$this->beConstructedWith($fixtureRegistry, $listenerRegistry, $optionsProcessor);
}
function it_implements_suite_factory_interface(): void
{
$this->shouldImplement(SuiteFactoryInterface::class);
}
function it_creates_a_new_empty_suite(): void
{
$suite = $this->createSuite('suite_name', ['listeners' => [], 'fixtures' => []]);
$suite->getName()->shouldReturn('suite_name');
$suite->getFixtures()->shouldIterateAs([]);
}
function it_creates_a_new_suite_with_fixtures(
FixtureRegistryInterface $fixtureRegistry,
Processor $optionsProcessor,
FixtureInterface $firstFixture,
FixtureInterface $secondFixture
): void {
$fixtureRegistry->getFixture('first_fixture')->willReturn($firstFixture);
$fixtureRegistry->getFixture('second_fixture')->willReturn($secondFixture);
$optionsProcessor->processConfiguration($firstFixture, [[]])->willReturn([]);
$optionsProcessor->processConfiguration($secondFixture, [[]])->willReturn([]);
$suite = $this->createSuite('suite_name', ['listeners' => [], 'fixtures' => [
'first_fixture' => ['name' => 'first_fixture', 'options' => [[]]],
'second_fixture' => ['name' => 'second_fixture', 'options' => [[]]],
]]);
$suite->getName()->shouldReturn('suite_name');
$suite->getFixtures()->shouldIterateAs($this->createGenerator($firstFixture, $secondFixture));
}
function it_creates_a_new_suite_with_fixtures_based_on_its_name_rather_than_alias(
FixtureRegistryInterface $fixtureRegistry,
Processor $optionsProcessor,
FixtureInterface $fixture
): void {
$fixtureRegistry->getFixture('fixture_name')->shouldBeCalled()->willReturn($fixture);
$fixtureRegistry->getFixture('fixture_alias')->shouldNotBeCalled();
$optionsProcessor->processConfiguration($fixture, [[]])->willReturn([]);
$suite = $this->createSuite('suite_name', ['listeners' => [], 'fixtures' => [
'fixture_alias' => ['name' => 'fixture_name', 'options' => [[]]],
]]);
$suite->getName()->shouldReturn('suite_name');
$suite->getFixtures()->shouldIterateAs($this->createGenerator($fixture));
}
function it_creates_a_new_suite_with_prioritized_fixtures(
FixtureRegistryInterface $fixtureRegistry,
Processor $optionsProcessor,
FixtureInterface $fixture,
FixtureInterface $higherPriorityFixture
): void {
$fixtureRegistry->getFixture('fixture')->willReturn($fixture);
$fixtureRegistry->getFixture('higher_priority_fixture')->willReturn($higherPriorityFixture);
$optionsProcessor->processConfiguration($fixture, [[]])->willReturn([]);
$optionsProcessor->processConfiguration($higherPriorityFixture, [[]])->willReturn([]);
$suite = $this->createSuite('suite_name', ['listeners' => [], 'fixtures' => [
'fixture' => ['name' => 'fixture', 'priority' => 5, 'options' => [[]]],
'higher_priority_fixture' => ['name' => 'higher_priority_fixture', 'priority' => 10, 'options' => [[]]],
]]);
$suite->getName()->shouldReturn('suite_name');
$suite->getFixtures()->shouldIterateAs($this->createGenerator($higherPriorityFixture, $fixture));
}
function it_creates_a_new_suite_with_customized_fixture(
FixtureRegistryInterface $fixtureRegistry,
Processor $optionsProcessor,
FixtureInterface $fixture
): void {
$fixtureRegistry->getFixture('fixture')->willReturn($fixture);
$optionsProcessor->processConfiguration($fixture, [['fixture_option' => 'fixture_value']])->willReturn(['fixture_option' => 'fixture_value']);
$suite = $this->createSuite('suite_name', ['listeners' => [], 'fixtures' => [
'fixture' => ['name' => 'fixture', 'options' => [['fixture_option' => 'fixture_value']]],
]]);
$suite->getName()->shouldReturn('suite_name');
$suite->getFixtures()->shouldHaveKeyWithValue($fixture, ['fixture_option' => 'fixture_value']);
}
function it_creates_a_new_suite_with_listeners(
ListenerRegistryInterface $listenerRegistry,
Processor $optionsProcessor,
ListenerInterface $firstListener,
ListenerInterface $secondListener
): void {
$listenerRegistry->getListener('first_listener')->willReturn($firstListener);
$listenerRegistry->getListener('second_listener')->willReturn($secondListener);
$optionsProcessor->processConfiguration($firstListener, [[]])->willReturn([]);
$optionsProcessor->processConfiguration($secondListener, [[]])->willReturn([]);
$suite = $this->createSuite('suite_name', ['fixtures' => [], 'listeners' => [
'first_listener' => ['options' => [[]]],
'second_listener' => ['options' => [[]]],
]]);
$suite->getName()->shouldReturn('suite_name');
$suite->getListeners()->shouldIterateAs($this->createGenerator($firstListener, $secondListener));
}
function it_creates_a_new_suite_with_prioritized_listeners(
ListenerRegistryInterface $listenerRegistry,
Processor $optionsProcessor,
ListenerInterface $listener,
ListenerInterface $higherPriorityListener
): void {
$listenerRegistry->getListener('listener')->willReturn($listener);
$listenerRegistry->getListener('higher_priority_listener')->willReturn($higherPriorityListener);
$optionsProcessor->processConfiguration($listener, [[]])->willReturn([]);
$optionsProcessor->processConfiguration($higherPriorityListener, [[]])->willReturn([]);
$suite = $this->createSuite('suite_name', ['fixtures' => [], 'listeners' => [
'listener' => ['priority' => 5, 'options' => [[]]],
'higher_priority_listener' => ['priority' => 10, 'options' => [[]]],
]]);
$suite->getName()->shouldReturn('suite_name');
$suite->getListeners()->shouldIterateAs($this->createGenerator($higherPriorityListener, $listener));
}
function it_creates_a_new_suite_with_customized_listener(
ListenerRegistryInterface $listenerRegistry,
Processor $optionsProcessor,
ListenerInterface $listener
): void {
$listenerRegistry->getListener('listener')->willReturn($listener);
$optionsProcessor->processConfiguration($listener, [['listener_option' => 'listener_value']])->willReturn(['listener_option' => 'listener_value']);
$suite = $this->createSuite('suite_name', ['fixtures' => [], 'listeners' => [
'listener' => ['options' => [['listener_option' => 'listener_value']]],
]]);
$suite->getName()->shouldReturn('suite_name');
$suite->getListeners()->shouldHaveKeyWithValue($listener, ['listener_option' => 'listener_value']);
}
function it_throws_an_exception_if_suite_options_does_not_have_fixtures(): void
{
$this->shouldThrow(\InvalidArgumentException::class)->during('createSuite', ['suite_name', ['listeners' => []]]);
}
function it_throws_an_exception_if_suite_options_does_not_have_listeners(): void
{
$this->shouldThrow(\InvalidArgumentException::class)->during('createSuite', ['suite_name', ['fixtures' => []]]);
}
function it_throws_an_exception_if_fixture_does_not_have_options_defined(): void
{
$this->shouldThrow(\InvalidArgumentException::class)->during('createSuite', ['suite_name', ['listeners' => [], 'fixtures' => [
'fixture' => ['name' => 'fixture'],
]]]);
}
function it_throws_an_exception_if_fixture_does_not_have_name_defined(): void
{
$this->shouldThrow(\InvalidArgumentException::class)->during('createSuite', ['suite_name', ['listeners' => [], 'fixtures' => [
'fixture' => ['options' => []],
]]]);
}
function it_throws_an_exception_if_listener_does_not_have_options_defined(): void
{
$this->shouldThrow(\InvalidArgumentException::class)->during('createSuite', ['suite_name', ['fixtures' => [], 'listeners' => [
'listener' => [],
]]]);
}
/**
* @param Collaborator[] ...$collaborators
*
* @return \Generator
*/
private function createGenerator(Collaborator ...$collaborators): \Generator
{
foreach ($collaborators as $collaborator) {
yield $collaborator->getWrappedObject() => [];
}
}
}

View file

@ -1,34 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace spec\Sylius\Bundle\FixturesBundle\Suite;
use PhpSpec\ObjectBehavior;
final class SuiteNotFoundExceptionSpec extends ObjectBehavior
{
function let(): void
{
$this->beConstructedWith('suite_name');
}
function it_is_an_invalid_argument_exception(): void
{
$this->shouldHaveType(\InvalidArgumentException::class);
}
function it_has_preformatted_message(): void
{
$this->getMessage()->shouldReturn('Suite with name "suite_name" could not be found!');
}
}

View file

@ -1,88 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace spec\Sylius\Bundle\FixturesBundle\Suite;
use PhpSpec\ObjectBehavior;
use PhpSpec\Wrapper\Collaborator;
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
final class SuiteSpec extends ObjectBehavior
{
function let(): void
{
$this->beConstructedWith('suite_name');
}
function it_implements_suite_interface(): void
{
$this->shouldImplement(SuiteInterface::class);
}
function it_has_name(): void
{
$this->getName()->shouldReturn('suite_name');
}
function it_has_no_fixtures_by_default(): void
{
$this->getFixtures()->shouldIterateAs([]);
}
function it_allows_for_adding_a_fixture(FixtureInterface $fixture): void
{
$this->addFixture($fixture, []);
$this->getFixtures()->shouldHaveKey($fixture);
}
function it_stores_a_fixture_with_its_options(FixtureInterface $fixture): void
{
$this->addFixture($fixture, ['fixture_option' => 'fixture_name']);
$this->getFixtures()->shouldHaveKeyWithValue($fixture, ['fixture_option' => 'fixture_name']);
}
function it_stores_multiple_fixtures_as_queue(FixtureInterface $firstFixture, FixtureInterface $secondFixture): void
{
$this->addFixture($firstFixture, []);
$this->addFixture($secondFixture, []);
$this->getFixtures()->shouldIterateAs($this->createGenerator($firstFixture, $secondFixture));
}
function it_keeps_the_priority_of_fixtures(
FixtureInterface $regularFixture,
FixtureInterface $higherPriorityFixture,
FixtureInterface $lowerPriorityFixture
): void {
$this->addFixture($regularFixture, []);
$this->addFixture($higherPriorityFixture, [], 10);
$this->addFixture($lowerPriorityFixture, [], -10);
$this->getFixtures()->shouldIterateAs($this->createGenerator($higherPriorityFixture, $regularFixture, $lowerPriorityFixture));
}
/**
* @param Collaborator[] ...$collaborators
*
* @return \Generator
*/
private function createGenerator(Collaborator ...$collaborators): \Generator
{
foreach ($collaborators as $collaborator) {
yield $collaborator->getWrappedObject() => [];
}
}
}

View file

@ -1,60 +0,0 @@
<?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.
*/
declare(strict_types=1);
/*
* 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.
*/
use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;
class AppKernel extends Kernel
{
/**
* {@inheritdoc}
*/
public function registerBundles()
{
return [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sylius\Bundle\FixturesBundle\SyliusFixturesBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
];
}
/**
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__ . '/config/config.yml');
}
/**
* {@inheritdoc}
*/
protected function getContainerBaseClass()
{
if ('test' === $this->environment) {
return MockerContainer::class;
}
return parent::getContainerBaseClass();
}
}

View file

@ -1,30 +0,0 @@
<?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.
*/
declare(strict_types=1);
/*
* 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.
*/
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__ . '/../../vendor/autoload.php';
require __DIR__ . '/AppKernel.php';
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
return $loader;

View file

@ -1,32 +0,0 @@
imports:
- { resource: "@SyliusFixturesBundle/test/app/config/parameters.yml" }
framework:
assets: false
translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
csrf_protection: true
templating:
engines: ['twig']
default_locale: "%locale%"
session:
handler_id: ~
storage_id: session.storage.mock_file
http_method_override: true
test: ~
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
doctrine:
dbal:
driver: "%database_driver%"
path: "%database_path%"
charset: UTF8
orm:
entity_managers:
default:
auto_mapping: true

View file

@ -1,6 +0,0 @@
parameters:
database_driver: pdo_sqlite
database_path: "%kernel.root_dir%/db.sql"
locale: en_US
secret: "Three can keep a secret, if two of them are dead."

View file

@ -1,24 +0,0 @@
#!/usr/bin/env php
<?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.
*/
set_time_limit(0);
require_once __DIR__ . "/../../vendor/autoload.php";
require_once __DIR__.'/AppKernel.php';
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
$input = new ArgvInput();
$application = new Application(new AppKernel('test', true));
$application->run($input);

View file

@ -1,39 +0,0 @@
<?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.
*/
declare(strict_types=1);
namespace Sylius\Bundle\FixturesBundle\Tests;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SyliusFixturesBundleTest extends WebTestCase
{
/**
* @test
*/
public function its_services_are_initializable()
{
/** @var ContainerInterface $container */
$container = self::createClient()->getContainer();
$services = $container->getServiceIds();
$services = array_filter($services, function ($serviceId) {
return 0 === strpos($serviceId, 'sylius.');
});
foreach ($services as $id) {
$container->get($id);
}
}
}