mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
Merge branch '1.2' into 1.3
* 1.2: Extract ThemeBundle Extract FixturesBundle
This commit is contained in:
commit
811adfc686
324 changed files with 3 additions and 15920 deletions
|
|
@ -49,6 +49,8 @@
|
|||
"stof/doctrine-extensions-bundle": "^1.2",
|
||||
"swiftmailer/swiftmailer": "^6.0",
|
||||
"sylius-labs/association-hydrator": "^1.1",
|
||||
"sylius/fixtures-bundle": "~1.3.8",
|
||||
"sylius/theme-bundle": "~1.3.8",
|
||||
"symfony/asset": "^3.4|^4.1",
|
||||
"symfony/config": "^3.4|^4.1",
|
||||
"symfony/console": "^3.4|^4.1",
|
||||
|
|
@ -104,8 +106,8 @@
|
|||
"friends-of-behat/symfony-extension": "^1.2.1",
|
||||
"friends-of-behat/variadic-extension": "^1.1",
|
||||
"hwi/oauth-bundle": "^0.6",
|
||||
"lchrusciel/api-test-case": "^3.1.0",
|
||||
"lakion/mink-debug-extension": "^1.2.3",
|
||||
"lchrusciel/api-test-case": "^3.1.0",
|
||||
"matthiasnoback/symfony-config-test": "^4.0",
|
||||
"matthiasnoback/symfony-dependency-injection-test": "^3.0",
|
||||
"mikey179/vfsstream": "^1.6",
|
||||
|
|
@ -142,7 +144,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",
|
||||
|
|
@ -173,7 +174,6 @@
|
|||
"sylius/taxation-bundle": "self.version",
|
||||
"sylius/taxonomy": "self.version",
|
||||
"sylius/taxonomy-bundle": "self.version",
|
||||
"sylius/theme-bundle": "self.version",
|
||||
"sylius/ui-bundle": "self.version",
|
||||
"sylius/user": "self.version",
|
||||
"sylius/user-bundle": "self.version"
|
||||
|
|
@ -234,7 +234,6 @@
|
|||
"spec\\Sylius\\Bundle\\CoreBundle\\": "src/Sylius/Bundle/CoreBundle/spec/",
|
||||
"spec\\Sylius\\Bundle\\CurrencyBundle\\": "src/Sylius/Bundle/CurrencyBundle/spec/",
|
||||
"spec\\Sylius\\Bundle\\CustomerBundle\\": "src/Sylius/Bundle/CustomerBundle/spec/",
|
||||
"spec\\Sylius\\Bundle\\FixturesBundle\\": "src/Sylius/Bundle/FixturesBundle/spec/",
|
||||
"spec\\Sylius\\Bundle\\GridBundle\\": "src/Sylius/Bundle/GridBundle/spec/",
|
||||
"spec\\Sylius\\Bundle\\InventoryBundle\\": "src/Sylius/Bundle/InventoryBundle/spec/",
|
||||
"spec\\Sylius\\Bundle\\LocaleBundle\\": "src/Sylius/Bundle/LocaleBundle/spec/",
|
||||
|
|
@ -251,7 +250,6 @@
|
|||
"spec\\Sylius\\Bundle\\ShopBundle\\": "src/Sylius/Bundle/ShopBundle/spec/",
|
||||
"spec\\Sylius\\Bundle\\TaxationBundle\\": "src/Sylius/Bundle/TaxationBundle/spec/",
|
||||
"spec\\Sylius\\Bundle\\TaxonomyBundle\\": "src/Sylius/Bundle/TaxonomyBundle/spec/",
|
||||
"spec\\Sylius\\Bundle\\ThemeBundle\\": "src/Sylius/Bundle/ThemeBundle/spec/",
|
||||
"spec\\Sylius\\Bundle\\UiBundle\\": "src/Sylius/Bundle/UiBundle/spec/",
|
||||
"spec\\Sylius\\Bundle\\UserBundle\\": "src/Sylius/Bundle/UserBundle/spec/"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
@ -46,7 +45,6 @@ suites:
|
|||
ShopBundle: { namespace: Sylius\Bundle\ShopBundle, psr4_prefix: Sylius\Bundle\ShopBundle, spec_path: src/Sylius/Bundle/ShopBundle, src_path: src/Sylius/Bundle/ShopBundle }
|
||||
TaxationBundle: { namespace: Sylius\Bundle\TaxationBundle, psr4_prefix: Sylius\Bundle\TaxationBundle, spec_path: src/Sylius/Bundle/TaxationBundle, src_path: src/Sylius/Bundle/TaxationBundle }
|
||||
TaxonomyBundle: { namespace: Sylius\Bundle\TaxonomyBundle, psr4_prefix: Sylius\Bundle\TaxonomyBundle, spec_path: src/Sylius/Bundle/TaxonomyBundle, src_path: src/Sylius/Bundle/TaxonomyBundle }
|
||||
ThemeBundle: { namespace: Sylius\Bundle\ThemeBundle, psr4_prefix: Sylius\Bundle\ThemeBundle , spec_path: src/Sylius/Bundle/ThemeBundle, src_path: src/Sylius/Bundle/ThemeBundle }
|
||||
UiBundle: { namespace: Sylius\Bundle\UiBundle, psr4_prefix: Sylius\Bundle\UiBundle, spec_path: src/Sylius/Bundle/UiBundle, src_path: src/Sylius/Bundle/UiBundle }
|
||||
UserBundle: { namespace: Sylius\Bundle\UserBundle, psr4_prefix: Sylius\Bundle\UserBundle, spec_path: src/Sylius/Bundle/UserBundle, src_path: src/Sylius/Bundle/UserBundle }
|
||||
|
||||
|
|
|
|||
15
src/Sylius/Bundle/FixturesBundle/.gitignore
vendored
15
src/Sylius/Bundle/FixturesBundle/.gitignore
vendored
|
|
@ -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
|
||||
|
|
@ -1,75 +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);
|
||||
}
|
||||
|
||||
private function listSuites(OutputInterface $output): void
|
||||
{
|
||||
$suites = $this->getSuiteRegistry()->getSuites();
|
||||
|
||||
$output->writeln('Available suites:');
|
||||
|
||||
foreach ($suites as $suite) {
|
||||
$output->writeln(' - ' . $suite->getName());
|
||||
}
|
||||
}
|
||||
|
||||
private function listFixtures(OutputInterface $output): void
|
||||
{
|
||||
$fixtures = $this->getFixtureRegistry()->getFixtures();
|
||||
|
||||
$output->writeln('Available fixtures:');
|
||||
|
||||
foreach ($fixtures as $name => $fixture) {
|
||||
$output->writeln(' - ' . $name);
|
||||
}
|
||||
}
|
||||
|
||||
private function getSuiteRegistry(): SuiteRegistryInterface
|
||||
{
|
||||
return $this->getContainer()->get('sylius_fixtures.suite_registry');
|
||||
}
|
||||
|
||||
private function getFixtureRegistry(): FixtureRegistryInterface
|
||||
{
|
||||
return $this->getContainer()->get('sylius_fixtures.fixture_registry');
|
||||
}
|
||||
}
|
||||
|
|
@ -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\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);
|
||||
}
|
||||
|
||||
private function loadSuites(InputInterface $input): void
|
||||
{
|
||||
$suiteName = $input->getArgument('suite');
|
||||
$suite = $this->getSuiteRegistry()->getSuite($suiteName);
|
||||
|
||||
$this->getSuiteLoader()->load($suite);
|
||||
}
|
||||
|
||||
private function getSuiteRegistry(): SuiteRegistryInterface
|
||||
{
|
||||
return $this->getContainer()->get('sylius_fixtures.suite_registry');
|
||||
}
|
||||
|
||||
private function getSuiteLoader(): SuiteLoaderInterface
|
||||
{
|
||||
return $this->getContainer()->get('sylius_fixtures.suite_loader');
|
||||
}
|
||||
}
|
||||
|
|
@ -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)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,133 +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
|
||||
{
|
||||
if (method_exists(TreeBuilder::class, 'getRootNode')) {
|
||||
$treeBuilder = new TreeBuilder('sylius_fixtures');
|
||||
$rootNode = $treeBuilder->getRootNode();
|
||||
} else {
|
||||
// BC layer for symfony/config 4.1 and older
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$rootNode = $treeBuilder->root('sylius_fixtures');
|
||||
}
|
||||
|
||||
$this->buildSuitesNode($rootNode);
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private function buildListenersNode(ArrayNodeDefinition $suitesNode): void
|
||||
{
|
||||
/** @var ArrayNodeDefinition $listenersNode */
|
||||
$listenersNode = $suitesNode
|
||||
->children()
|
||||
->arrayNode('listeners')
|
||||
->useAttributeAsKey('name')
|
||||
->arrayPrototype()
|
||||
;
|
||||
|
||||
$this->buildAttributesNode($listenersNode);
|
||||
}
|
||||
|
||||
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([]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,66 +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);
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +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
|
||||
{
|
||||
if (method_exists(TreeBuilder::class, 'getRootNode')) {
|
||||
$treeBuilder = new TreeBuilder($this->getName());
|
||||
$optionsNode = $treeBuilder->getRootNode();
|
||||
} else {
|
||||
// BC layer for symfony/config 4.1 and older
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$optionsNode = $treeBuilder->root($this->getName());
|
||||
}
|
||||
|
||||
$this->configureOptionsNode($optionsNode);
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
|
||||
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
|
||||
{
|
||||
// empty
|
||||
}
|
||||
}
|
||||
|
|
@ -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\Fixture;
|
||||
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
interface FixtureInterface extends ConfigurationInterface
|
||||
{
|
||||
public function load(array $options): void;
|
||||
|
||||
public function getName(): string;
|
||||
}
|
||||
|
|
@ -1,22 +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
|
||||
{
|
||||
public function __construct(string $name, ?\Exception $previous = null)
|
||||
{
|
||||
parent::__construct(sprintf('Fixture with name "%s" could not be found!', $name), 0, $previous);
|
||||
}
|
||||
}
|
||||
|
|
@ -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\Fixture;
|
||||
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final class FixtureRegistry implements FixtureRegistryInterface
|
||||
{
|
||||
/** @var array */
|
||||
private $fixtures = [];
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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\Fixture;
|
||||
|
||||
interface FixtureRegistryInterface
|
||||
{
|
||||
/**
|
||||
* @throws FixtureNotFoundException
|
||||
*/
|
||||
public function getFixture(string $name): FixtureInterface;
|
||||
|
||||
/**
|
||||
* @return array|FixtureInterface[] Name indexed
|
||||
*/
|
||||
public function getFixtures(): array;
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
Copyright (c) 2011-2019 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.
|
||||
|
|
@ -1,44 +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
|
||||
{
|
||||
if (method_exists(TreeBuilder::class, 'getRootNode')) {
|
||||
$treeBuilder = new TreeBuilder($this->getName());
|
||||
$optionsNode = $treeBuilder->getRootNode();
|
||||
} else {
|
||||
// BC layer for symfony/config 4.1 and older
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$optionsNode = $treeBuilder->root($this->getName());
|
||||
}
|
||||
|
||||
$this->configureOptionsNode($optionsNode);
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
|
||||
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
|
||||
{
|
||||
// empty
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +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
|
||||
{
|
||||
public function afterFixture(FixtureEvent $fixtureEvent, array $options): void;
|
||||
}
|
||||
|
|
@ -1,19 +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
|
||||
{
|
||||
public function afterSuite(SuiteEvent $suiteEvent, array $options): void;
|
||||
}
|
||||
|
|
@ -1,19 +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
|
||||
{
|
||||
public function beforeFixture(FixtureEvent $fixtureEvent, array $options): void;
|
||||
}
|
||||
|
|
@ -1,19 +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
|
||||
{
|
||||
public function beforeSuite(SuiteEvent $suiteEvent, array $options): void;
|
||||
}
|
||||
|
|
@ -1,51 +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;
|
||||
|
||||
public function __construct(SuiteInterface $suite, FixtureInterface $fixture, array $fixtureOptions)
|
||||
{
|
||||
$this->suite = $suite;
|
||||
$this->fixture = $fixture;
|
||||
$this->fixtureOptions = $fixtureOptions;
|
||||
}
|
||||
|
||||
public function suite(): SuiteInterface
|
||||
{
|
||||
return $this->suite;
|
||||
}
|
||||
|
||||
public function fixture(): FixtureInterface
|
||||
{
|
||||
return $this->fixture;
|
||||
}
|
||||
|
||||
public function fixtureOptions(): array
|
||||
{
|
||||
return $this->fixtureOptions;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +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
|
||||
{
|
||||
public function getName(): string;
|
||||
}
|
||||
|
|
@ -1,22 +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
|
||||
{
|
||||
public function __construct(string $name, ?\Exception $previous = null)
|
||||
{
|
||||
parent::__construct(sprintf('Listener with name "%s" could not be found!', $name), 0, $previous);
|
||||
}
|
||||
}
|
||||
|
|
@ -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\Listener;
|
||||
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final class ListenerRegistry implements ListenerRegistryInterface
|
||||
{
|
||||
/** @var array */
|
||||
private $listeners = [];
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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\Listener;
|
||||
|
||||
interface ListenerRegistryInterface
|
||||
{
|
||||
/**
|
||||
* @throws ListenerNotFoundException
|
||||
*/
|
||||
public function getListener(string $name): ListenerInterface;
|
||||
|
||||
/**
|
||||
* @return array|ListenerInterface[] Name indexed
|
||||
*/
|
||||
public function getListeners(): array;
|
||||
}
|
||||
|
|
@ -1,51 +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;
|
||||
|
||||
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';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,65 +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;
|
||||
|
||||
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()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,85 +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,
|
||||
];
|
||||
|
||||
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()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,65 +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;
|
||||
|
||||
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()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +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;
|
||||
|
||||
public function __construct(SuiteInterface $suite)
|
||||
{
|
||||
$this->suite = $suite;
|
||||
}
|
||||
|
||||
public function suite(): SuiteInterface
|
||||
{
|
||||
return $this->suite;
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +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
|
||||
{
|
||||
public function load(SuiteInterface $suite, FixtureInterface $fixture, array $options): void;
|
||||
}
|
||||
|
|
@ -1,67 +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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private function executeBeforeFixtureListeners(SuiteInterface $suite, FixtureEvent $fixtureEvent): void
|
||||
{
|
||||
foreach ($suite->getListeners() as $listener => $listenerOptions) {
|
||||
if (!$listener instanceof BeforeFixtureListenerInterface) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$listener->beforeFixture($fixtureEvent, $listenerOptions);
|
||||
}
|
||||
}
|
||||
|
||||
private function executeAfterFixtureListeners(SuiteInterface $suite, FixtureEvent $fixtureEvent): void
|
||||
{
|
||||
foreach ($suite->getListeners() as $listener => $listenerOptions) {
|
||||
if (!$listener instanceof AfterFixtureListenerInterface) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$listener->afterFixture($fixtureEvent, $listenerOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,66 +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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private function executeBeforeSuiteListeners(SuiteInterface $suite, SuiteEvent $suiteEvent): void
|
||||
{
|
||||
foreach ($suite->getListeners() as $listener => $listenerOptions) {
|
||||
if (!$listener instanceof BeforeSuiteListenerInterface) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$listener->beforeSuite($suiteEvent, $listenerOptions);
|
||||
}
|
||||
}
|
||||
|
||||
private function executeAfterSuiteListeners(SuiteInterface $suite, SuiteEvent $suiteEvent): void
|
||||
{
|
||||
foreach ($suite->getListeners() as $listener => $listenerOptions) {
|
||||
if (!$listener instanceof AfterSuiteListenerInterface) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$listener->afterSuite($suiteEvent, $listenerOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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\Loader;
|
||||
|
||||
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
|
||||
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
|
||||
|
||||
final class SuiteLoader implements SuiteLoaderInterface
|
||||
{
|
||||
/** @var FixtureLoaderInterface */
|
||||
private $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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +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
|
||||
{
|
||||
public function load(SuiteInterface $suite): void;
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
SyliusFixturesBundle [](http://travis-ci.org/Sylius/SyliusFixturesBundle)
|
||||
====================
|
||||
|
||||
Configurable fixtures for Symfony2 applications.
|
||||
|
||||
Sylius
|
||||
------
|
||||
|
||||

|
||||
|
||||
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).
|
||||
|
|
@ -1,32 +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>
|
||||
|
||||
<services>
|
||||
<service id="Sylius\Bundle\FixturesBundle\Command\FixturesListCommand">
|
||||
<tag name="console.command" />
|
||||
</service>
|
||||
|
||||
<service id="Sylius\Bundle\FixturesBundle\Command\FixturesLoadCommand">
|
||||
<tag name="console.command" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
@ -1,20 +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>
|
||||
<defaults public="true" />
|
||||
|
||||
<service id="sylius_fixtures.fixture_registry" class="Sylius\Bundle\FixturesBundle\Fixture\FixtureRegistry" />
|
||||
</services>
|
||||
</container>
|
||||
|
|
@ -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>
|
||||
<defaults public="true" />
|
||||
|
||||
<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>
|
||||
|
|
@ -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>
|
||||
<defaults public="true" />
|
||||
|
||||
<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>
|
||||
|
|
@ -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>
|
||||
<defaults public="true" />
|
||||
|
||||
<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>
|
||||
|
|
@ -1,25 +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>
|
||||
<defaults public="true" />
|
||||
|
||||
<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>
|
||||
|
|
@ -1,32 +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>
|
||||
<defaults public="true" />
|
||||
|
||||
<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>
|
||||
|
|
@ -1,44 +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>
|
||||
<defaults public="true" />
|
||||
|
||||
<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 type="collection">
|
||||
<argument key="format">%%message%% %%context%% %%extra%% </argument>
|
||||
</argument>
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
@ -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>
|
||||
<defaults public="true" />
|
||||
|
||||
<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>
|
||||
|
|
@ -1,65 +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 = [];
|
||||
|
||||
public function __construct(SuiteFactoryInterface $suiteFactory)
|
||||
{
|
||||
$this->suiteFactory = $suiteFactory;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,77 +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;
|
||||
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->fixtures = new SplPriorityQueue();
|
||||
$this->listeners = new SplPriorityQueue();
|
||||
}
|
||||
|
||||
public function addFixture(FixtureInterface $fixture, array $options, int $priority = 0): void
|
||||
{
|
||||
$this->fixtures->insert(['fixture' => $fixture, 'options' => $options], $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'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,85 +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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +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
|
||||
{
|
||||
public function createSuite(string $name, array $configuration): SuiteInterface;
|
||||
}
|
||||
|
|
@ -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 Sylius\Bundle\FixturesBundle\Suite;
|
||||
|
||||
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
|
||||
use Sylius\Bundle\FixturesBundle\Listener\ListenerInterface;
|
||||
|
||||
interface SuiteInterface
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
|
@ -1,22 +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
|
||||
{
|
||||
public function __construct(string $name, ?\Exception $previous = null)
|
||||
{
|
||||
parent::__construct(sprintf('Suite with name "%s" could not be found!', $name), 0, $previous);
|
||||
}
|
||||
}
|
||||
|
|
@ -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\Suite;
|
||||
|
||||
interface SuiteRegistryInterface
|
||||
{
|
||||
/**
|
||||
* @throws SuiteNotFoundException
|
||||
*/
|
||||
public function getSuite(string $name): SuiteInterface;
|
||||
|
||||
/**
|
||||
* @return array|SuiteInterface[]
|
||||
*/
|
||||
public function getSuites(): array;
|
||||
}
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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()];
|
||||
}
|
||||
}
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
@ -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.2",
|
||||
|
||||
"doctrine/data-fixtures": "^1.2",
|
||||
"monolog/monolog": "^1.8",
|
||||
"symfony/framework-bundle": "^3.4|^4.1.1",
|
||||
"symfony/monolog-bridge": "^3.4|^4.1.1",
|
||||
"webmozart/assert": "^1.0",
|
||||
"zendframework/zend-stdlib": "^3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/orm": "^2.5",
|
||||
"doctrine/doctrine-bundle": "^1.3",
|
||||
"matthiasnoback/symfony-config-test": "^4.0",
|
||||
"matthiasnoback/symfony-dependency-injection-test": "^3.0",
|
||||
"phpspec/phpspec": "^5.0",
|
||||
"phpunit/phpunit": "^7.0",
|
||||
"twig/twig": "^2.0",
|
||||
"symfony/browser-kit": "^3.4|^4.1.1",
|
||||
"symfony/dependency-injection": "^3.4|^4.1.1",
|
||||
"symfony/templating": "^3.4|^4.1.1",
|
||||
"symfony/translation": "^3.4|^4.1.1",
|
||||
"symfony/twig-bundle": "^3.4|^4.1.1",
|
||||
"symfony/security-csrf": "^3.4|^4.1.1",
|
||||
"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/"
|
||||
},
|
||||
"classmap": ["test/app/AppKernel.php"]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"repositories": [
|
||||
{
|
||||
"type": "path",
|
||||
"url": "../../*/*"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.3-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
suites:
|
||||
main:
|
||||
namespace: Sylius\Bundle\FixturesBundle
|
||||
psr4_prefix: Sylius\Bundle\FixturesBundle
|
||||
src_path: .
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.0/phpunit.xsd"
|
||||
colors="true"
|
||||
>
|
||||
<php>
|
||||
<server name="KERNEL_CLASS" value="AppKernel" />
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="SyliusFixturesBundle Test Suite">
|
||||
<directory>./test/</directory>
|
||||
<directory>./Tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
|
|
@ -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!');
|
||||
}
|
||||
}
|
||||
|
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
|
@ -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!');
|
||||
}
|
||||
}
|
||||
|
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
|
@ -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(), []), []);
|
||||
}
|
||||
}
|
||||
|
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,221 +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
|
||||
*/
|
||||
private function createGenerator(Collaborator ...$collaborators): \Generator
|
||||
{
|
||||
foreach ($collaborators as $collaborator) {
|
||||
yield $collaborator->getWrappedObject() => [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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!');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,86 +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
|
||||
*/
|
||||
private function createGenerator(Collaborator ...$collaborators): \Generator
|
||||
{
|
||||
foreach ($collaborators as $collaborator) {
|
||||
yield $collaborator->getWrappedObject() => [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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 (0 === strpos($this->environment, 'test')) {
|
||||
return MockerContainer::class;
|
||||
}
|
||||
|
||||
return parent::getContainerBaseClass();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
imports:
|
||||
- { resource: "@SyliusFixturesBundle/test/app/config/parameters.yml" }
|
||||
|
||||
framework:
|
||||
assets: false
|
||||
translator: { fallbacks: ["%locale%"] }
|
||||
secret: "%secret%"
|
||||
router:
|
||||
resource: "%kernel.project_dir%/app/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
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
parameters:
|
||||
database_driver: pdo_sqlite
|
||||
database_path: "%kernel.project_dir%/app/db.sql"
|
||||
|
||||
locale: en_US
|
||||
secret: "Three can keep a secret, if two of them are dead."
|
||||
|
|
@ -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);
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"name": "example/test-application"
|
||||
}
|
||||
|
|
@ -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\Tests;
|
||||
|
||||
use PHPUnit\Framework\Assert;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
final class SyliusFixturesBundleTest extends WebTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function its_services_are_initializable(): void
|
||||
{
|
||||
/** @var ContainerBuilder $container */
|
||||
$container = self::createClient()->getContainer();
|
||||
|
||||
$services = $container->getServiceIds();
|
||||
|
||||
$services = array_filter($services, function (string $serviceId): bool {
|
||||
return 0 === strpos($serviceId, 'sylius.');
|
||||
});
|
||||
|
||||
foreach ($services as $id) {
|
||||
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/Sylius/Bundle/ThemeBundle/.gitignore
vendored
8
src/Sylius/Bundle/ThemeBundle/.gitignore
vendored
|
|
@ -1,8 +0,0 @@
|
|||
/vendor/
|
||||
/bin/
|
||||
|
||||
/composer.phar
|
||||
/composer.lock
|
||||
|
||||
/phpspec.yml
|
||||
/phpunit.xml
|
||||
|
|
@ -1,227 +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\ThemeBundle\Asset\Installer;
|
||||
|
||||
use Sylius\Bundle\ThemeBundle\Asset\PathResolverInterface;
|
||||
use Sylius\Bundle\ThemeBundle\HierarchyProvider\ThemeHierarchyProviderInterface;
|
||||
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
|
||||
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
|
||||
use Symfony\Component\Filesystem\Exception\IOException;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
final class AssetsInstaller implements AssetsInstallerInterface
|
||||
{
|
||||
/** @var Filesystem */
|
||||
private $filesystem;
|
||||
|
||||
/** @var KernelInterface */
|
||||
private $kernel;
|
||||
|
||||
/** @var ThemeRepositoryInterface */
|
||||
private $themeRepository;
|
||||
|
||||
/** @var ThemeHierarchyProviderInterface */
|
||||
private $themeHierarchyProvider;
|
||||
|
||||
/** @var PathResolverInterface */
|
||||
private $pathResolver;
|
||||
|
||||
public function __construct(
|
||||
Filesystem $filesystem,
|
||||
KernelInterface $kernel,
|
||||
ThemeRepositoryInterface $themeRepository,
|
||||
ThemeHierarchyProviderInterface $themeHierarchyProvider,
|
||||
PathResolverInterface $pathResolver
|
||||
) {
|
||||
$this->filesystem = $filesystem;
|
||||
$this->kernel = $kernel;
|
||||
$this->themeRepository = $themeRepository;
|
||||
$this->themeHierarchyProvider = $themeHierarchyProvider;
|
||||
$this->pathResolver = $pathResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function installAssets(string $targetDir, int $symlinkMask): int
|
||||
{
|
||||
// Create the bundles directory otherwise symlink will fail.
|
||||
$targetDir = rtrim($targetDir, '/') . '/bundles/';
|
||||
$this->filesystem->mkdir($targetDir);
|
||||
|
||||
$effectiveSymlinkMask = $symlinkMask;
|
||||
foreach ($this->kernel->getBundles() as $bundle) {
|
||||
$effectiveSymlinkMask = min($effectiveSymlinkMask, $this->installBundleAssets($bundle, $targetDir, $symlinkMask));
|
||||
}
|
||||
|
||||
return $effectiveSymlinkMask;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function installBundleAssets(BundleInterface $bundle, string $targetDir, int $symlinkMask): int
|
||||
{
|
||||
$targetDir .= preg_replace('/bundle$/', '', strtolower($bundle->getName()));
|
||||
|
||||
$this->filesystem->remove($targetDir);
|
||||
|
||||
$effectiveSymlinkMask = $symlinkMask;
|
||||
foreach ($this->findAssetsPaths($bundle) as $originDir) {
|
||||
$effectiveSymlinkMask = min(
|
||||
$effectiveSymlinkMask,
|
||||
$this->installVanillaBundleAssets($originDir, $targetDir, $symlinkMask)
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($this->themeRepository->findAll() as $theme) {
|
||||
$themes = $this->themeHierarchyProvider->getThemeHierarchy($theme);
|
||||
|
||||
foreach ($this->findAssetsPaths($bundle, $themes) as $originDir) {
|
||||
$effectiveSymlinkMask = min(
|
||||
$effectiveSymlinkMask,
|
||||
$this->installThemedBundleAssets($theme, $originDir, $targetDir, $symlinkMask)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $effectiveSymlinkMask;
|
||||
}
|
||||
|
||||
private function installThemedBundleAssets(ThemeInterface $theme, string $originDir, string $targetDir, int $symlinkMask): int
|
||||
{
|
||||
$effectiveSymlinkMask = $symlinkMask;
|
||||
|
||||
$finder = new Finder();
|
||||
$finder->sortByName()->ignoreDotFiles(false)->in($originDir);
|
||||
|
||||
/** @var SplFileInfo[] $finder */
|
||||
foreach ($finder as $originFile) {
|
||||
$targetFile = $targetDir . '/' . $originFile->getRelativePathname();
|
||||
$targetFile = $this->pathResolver->resolve($targetFile, $theme);
|
||||
|
||||
if (file_exists($targetFile) && AssetsInstallerInterface::HARD_COPY !== $symlinkMask) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->filesystem->mkdir(dirname($targetFile));
|
||||
|
||||
$effectiveSymlinkMask = min(
|
||||
$effectiveSymlinkMask,
|
||||
$this->installAsset($originFile->getPathname(), $targetFile, $symlinkMask)
|
||||
);
|
||||
}
|
||||
|
||||
return $effectiveSymlinkMask;
|
||||
}
|
||||
|
||||
private function installVanillaBundleAssets(string $originDir, string $targetDir, int $symlinkMask): int
|
||||
{
|
||||
return $this->installAsset($originDir, $targetDir, $symlinkMask);
|
||||
}
|
||||
|
||||
private function installAsset(string $origin, string $target, int $symlinkMask): int
|
||||
{
|
||||
if (AssetsInstallerInterface::RELATIVE_SYMLINK === $symlinkMask) {
|
||||
try {
|
||||
$targetDirname = realpath(is_dir($target) ? $target : dirname($target));
|
||||
$relativeOrigin = rtrim($this->filesystem->makePathRelative($origin, $targetDirname), '/');
|
||||
|
||||
$this->doInstallAsset($relativeOrigin, $target, true);
|
||||
|
||||
return AssetsInstallerInterface::RELATIVE_SYMLINK;
|
||||
} catch (IOException $exception) {
|
||||
// Do nothing, trying to create non-relative symlinks later.
|
||||
}
|
||||
}
|
||||
|
||||
if (AssetsInstallerInterface::HARD_COPY !== $symlinkMask) {
|
||||
try {
|
||||
$this->doInstallAsset($origin, $target, true);
|
||||
|
||||
return AssetsInstallerInterface::SYMLINK;
|
||||
} catch (IOException $exception) {
|
||||
// Do nothing, hard copy later.
|
||||
}
|
||||
}
|
||||
|
||||
$this->doInstallAsset($origin, $target, false);
|
||||
|
||||
return AssetsInstallerInterface::HARD_COPY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IOException When failed to make symbolic link, if requested.
|
||||
*/
|
||||
private function doInstallAsset(string $origin, string $target, bool $symlink): void
|
||||
{
|
||||
if ($symlink) {
|
||||
$this->doSymlinkAsset($origin, $target);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->doCopyAsset($origin, $target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|ThemeInterface[] $themes
|
||||
*/
|
||||
private function findAssetsPaths(BundleInterface $bundle, array $themes = []): array
|
||||
{
|
||||
$sources = [];
|
||||
|
||||
foreach ($themes as $theme) {
|
||||
$sourceDir = $theme->getPath() . '/' . $bundle->getName() . '/public';
|
||||
if (is_dir($sourceDir)) {
|
||||
$sources[] = $sourceDir;
|
||||
}
|
||||
}
|
||||
|
||||
$sourceDir = $bundle->getPath() . '/Resources/public';
|
||||
if (is_dir($sourceDir)) {
|
||||
$sources[] = $sourceDir;
|
||||
}
|
||||
|
||||
return $sources;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IOException If symbolic link is broken
|
||||
*/
|
||||
private function doSymlinkAsset(string $origin, string $target): void
|
||||
{
|
||||
$this->filesystem->symlink($origin, $target);
|
||||
|
||||
if (!file_exists($target)) {
|
||||
throw new IOException('Symbolic link is broken');
|
||||
}
|
||||
}
|
||||
|
||||
private function doCopyAsset(string $origin, string $target): void
|
||||
{
|
||||
if (is_dir($origin)) {
|
||||
$this->filesystem->mkdir($target, 0777);
|
||||
$this->filesystem->mirror($origin, $target, Finder::create()->ignoreDotFiles(false)->in($origin));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->filesystem->copy($origin, $target);
|
||||
}
|
||||
}
|
||||
|
|
@ -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\ThemeBundle\Asset\Installer;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
|
||||
|
||||
interface AssetsInstallerInterface
|
||||
{
|
||||
/**
|
||||
* Constant used as parameter and returned in installAssets() methods.
|
||||
*
|
||||
* @see AssetsInstallerInterface::installAssets()
|
||||
* @see AssetsInstallerInterface::installBundleAssets()
|
||||
* @see AssetsInstallerInterface::installDirAssets()
|
||||
*/
|
||||
public const HARD_COPY = 0;
|
||||
|
||||
/**
|
||||
* Constant used as parameter and returned in installAssets() methods.
|
||||
*
|
||||
* @see AssetsInstallerInterface::installAssets()
|
||||
* @see AssetsInstallerInterface::installBundleAssets()
|
||||
* @see AssetsInstallerInterface::installDirAssets()
|
||||
*/
|
||||
public const SYMLINK = 1;
|
||||
|
||||
/**
|
||||
* Constant used as parameter and returned in installAssets() methods.
|
||||
*
|
||||
* @see AssetsInstallerInterface::installAssets()
|
||||
* @see AssetsInstallerInterface::installBundleAssets()
|
||||
* @see AssetsInstallerInterface::installDirAssets()
|
||||
*/
|
||||
public const RELATIVE_SYMLINK = 2;
|
||||
|
||||
/**
|
||||
* @return int Effective symlink mask (lowest value received from installBundleAssets() method)
|
||||
*/
|
||||
public function installAssets(string $targetDir, int $symlinkMask);
|
||||
|
||||
/**
|
||||
* @return int Effective symlink mask (lowest value received from installDirAssets() method)
|
||||
*/
|
||||
public function installBundleAssets(BundleInterface $bundle, string $targetDir, int $symlinkMask);
|
||||
}
|
||||
|
|
@ -1,102 +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\ThemeBundle\Asset\Installer;
|
||||
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
|
||||
|
||||
final class OutputAwareAssetsInstaller implements AssetsInstallerInterface, OutputAwareInterface
|
||||
{
|
||||
/** @var AssetsInstallerInterface */
|
||||
private $assetsInstaller;
|
||||
|
||||
/** @var OutputInterface */
|
||||
private $output;
|
||||
|
||||
public function __construct(AssetsInstallerInterface $assetsInstaller)
|
||||
{
|
||||
$this->assetsInstaller = $assetsInstaller;
|
||||
$this->output = new NullOutput();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setOutput(OutputInterface $output): void
|
||||
{
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function installAssets(string $targetDir, int $symlinkMask): int
|
||||
{
|
||||
$this->output->writeln($this->provideExpectationComment($symlinkMask));
|
||||
|
||||
return $this->assetsInstaller->installAssets($targetDir, $symlinkMask);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function installBundleAssets(BundleInterface $bundle, string $targetDir, int $symlinkMask): int
|
||||
{
|
||||
$this->output->writeln(sprintf(
|
||||
'Installing assets for <comment>%s</comment> into <comment>%s</comment>',
|
||||
$bundle->getNamespace(),
|
||||
$targetDir
|
||||
));
|
||||
|
||||
$effectiveSymlinkMask = $this->assetsInstaller->installBundleAssets($bundle, $targetDir, $symlinkMask);
|
||||
|
||||
$this->output->writeln($this->provideResultComment($symlinkMask, $effectiveSymlinkMask));
|
||||
|
||||
return $effectiveSymlinkMask;
|
||||
}
|
||||
|
||||
private function provideResultComment(int $symlinkMask, int $effectiveSymlinkMask): string
|
||||
{
|
||||
if ($effectiveSymlinkMask === $symlinkMask) {
|
||||
switch ($symlinkMask) {
|
||||
case AssetsInstallerInterface::HARD_COPY:
|
||||
return 'The assets were copied.';
|
||||
case AssetsInstallerInterface::SYMLINK:
|
||||
return 'The assets were installed using symbolic links.';
|
||||
case AssetsInstallerInterface::RELATIVE_SYMLINK:
|
||||
return 'The assets were installed using relative symbolic links.';
|
||||
}
|
||||
}
|
||||
|
||||
switch ($symlinkMask + $effectiveSymlinkMask) {
|
||||
case AssetsInstallerInterface::SYMLINK:
|
||||
case AssetsInstallerInterface::RELATIVE_SYMLINK:
|
||||
return 'It looks like your system doesn\'t support symbolic links, so the assets were copied.';
|
||||
case AssetsInstallerInterface::RELATIVE_SYMLINK + AssetsInstallerInterface::SYMLINK:
|
||||
return 'It looks like your system doesn\'t support relative symbolic links, so the assets were installed by using absolute symbolic links.';
|
||||
}
|
||||
|
||||
return 'Something gone bad, can\'t provide the result of assets installing!';
|
||||
}
|
||||
|
||||
private function provideExpectationComment(int $symlinkMask): string
|
||||
{
|
||||
if (AssetsInstallerInterface::HARD_COPY === $symlinkMask) {
|
||||
return 'Installing assets as <comment>hard copies</comment>.';
|
||||
}
|
||||
|
||||
return 'Trying to install assets as <comment>symbolic links</comment>.';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +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\ThemeBundle\Asset\Installer;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
interface OutputAwareInterface
|
||||
{
|
||||
public function setOutput(OutputInterface $output): void;
|
||||
}
|
||||
|
|
@ -1,69 +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\ThemeBundle\Asset\Package;
|
||||
|
||||
use Sylius\Bundle\ThemeBundle\Asset\PathResolverInterface;
|
||||
use Sylius\Bundle\ThemeBundle\Context\ThemeContextInterface;
|
||||
use Symfony\Component\Asset\Context\ContextInterface;
|
||||
use Symfony\Component\Asset\PathPackage as BasePathPackage;
|
||||
use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;
|
||||
|
||||
/**
|
||||
* @see BasePathPackage
|
||||
*/
|
||||
class PathPackage extends BasePathPackage
|
||||
{
|
||||
/** @var ThemeContextInterface */
|
||||
protected $themeContext;
|
||||
|
||||
/** @var PathResolverInterface */
|
||||
protected $pathResolver;
|
||||
|
||||
public function __construct(
|
||||
string $basePath,
|
||||
VersionStrategyInterface $versionStrategy,
|
||||
ThemeContextInterface $themeContext,
|
||||
PathResolverInterface $pathResolver,
|
||||
?ContextInterface $context = null
|
||||
) {
|
||||
parent::__construct($basePath, $versionStrategy, $context);
|
||||
|
||||
$this->themeContext = $themeContext;
|
||||
$this->pathResolver = $pathResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getUrl($path): string
|
||||
{
|
||||
if ($this->isAbsoluteUrl($path)) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
$theme = $this->themeContext->getTheme();
|
||||
if (null !== $theme) {
|
||||
$path = $this->pathResolver->resolve($path, $theme);
|
||||
}
|
||||
|
||||
$versionedPath = $this->getVersionStrategy()->applyVersion($path);
|
||||
|
||||
// if absolute or begins with /, we're done
|
||||
if ($this->isAbsoluteUrl($versionedPath) || ($versionedPath && '/' === $versionedPath[0])) {
|
||||
return $versionedPath;
|
||||
}
|
||||
|
||||
return $this->getBasePath() . ltrim($versionedPath, '/');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,117 +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\ThemeBundle\Asset\Package;
|
||||
|
||||
use Sylius\Bundle\ThemeBundle\Asset\PathResolverInterface;
|
||||
use Sylius\Bundle\ThemeBundle\Context\ThemeContextInterface;
|
||||
use Symfony\Component\Asset\Context\ContextInterface;
|
||||
use Symfony\Component\Asset\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Asset\UrlPackage as BaseUrlPackage;
|
||||
use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;
|
||||
|
||||
/**
|
||||
* @see BaseUrlPackage
|
||||
*/
|
||||
class UrlPackage extends BaseUrlPackage
|
||||
{
|
||||
/** @var array */
|
||||
private $baseUrls = [];
|
||||
|
||||
/** @var UrlPackage */
|
||||
private $sslPackage;
|
||||
|
||||
/** @var ThemeContextInterface */
|
||||
protected $themeContext;
|
||||
|
||||
/** @var PathResolverInterface */
|
||||
protected $pathResolver;
|
||||
|
||||
/**
|
||||
* @param string|array $baseUrls Base asset URLs
|
||||
* @param VersionStrategyInterface $versionStrategy The version strategy
|
||||
* @param ContextInterface|null $context Context
|
||||
*/
|
||||
public function __construct(
|
||||
$baseUrls,
|
||||
VersionStrategyInterface $versionStrategy,
|
||||
ThemeContextInterface $themeContext,
|
||||
PathResolverInterface $pathResolver,
|
||||
?ContextInterface $context = null
|
||||
) {
|
||||
parent::__construct($baseUrls, $versionStrategy, $context);
|
||||
|
||||
if (!is_array($baseUrls)) {
|
||||
$baseUrls = (array) $baseUrls;
|
||||
}
|
||||
|
||||
foreach ($baseUrls as $baseUrl) {
|
||||
$this->baseUrls[] = rtrim($baseUrl, '/');
|
||||
}
|
||||
|
||||
$sslUrls = $this->getSslUrls($baseUrls);
|
||||
|
||||
if ($sslUrls && $baseUrls !== $sslUrls) {
|
||||
$this->sslPackage = new self($sslUrls, $versionStrategy, $themeContext, $pathResolver);
|
||||
}
|
||||
|
||||
$this->themeContext = $themeContext;
|
||||
$this->pathResolver = $pathResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getUrl($path): string
|
||||
{
|
||||
if ($this->isAbsoluteUrl($path)) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
if (null !== $this->sslPackage && $this->getContext()->isSecure()) {
|
||||
return $this->sslPackage->getUrl($path);
|
||||
}
|
||||
|
||||
$theme = $this->themeContext->getTheme();
|
||||
if (null !== $theme) {
|
||||
$path = $this->pathResolver->resolve($path, $theme);
|
||||
}
|
||||
|
||||
$url = $this->getVersionStrategy()->applyVersion($path);
|
||||
|
||||
if ($this->isAbsoluteUrl($url)) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
if ($url && '/' != $url[0]) {
|
||||
$url = '/' . $url;
|
||||
}
|
||||
|
||||
return $this->getBaseUrl($path) . $url;
|
||||
}
|
||||
|
||||
private function getSslUrls(array $urls): array
|
||||
{
|
||||
$sslUrls = [];
|
||||
|
||||
foreach ($urls as $url) {
|
||||
if ('https://' === substr($url, 0, 8) || '//' === substr($url, 0, 2)) {
|
||||
$sslUrls[] = $url;
|
||||
} elseif ('http://' !== substr($url, 0, 7)) {
|
||||
throw new InvalidArgumentException(sprintf('"%s" is not a valid URL', $url));
|
||||
}
|
||||
}
|
||||
|
||||
return $sslUrls;
|
||||
}
|
||||
}
|
||||
|
|
@ -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\ThemeBundle\Asset;
|
||||
|
||||
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
|
||||
|
||||
final class PathResolver implements PathResolverInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function resolve(string $path, ThemeInterface $theme): string
|
||||
{
|
||||
return str_replace('bundles/', 'bundles/_themes/' . $theme->getName() . '/', $path);
|
||||
}
|
||||
}
|
||||
|
|
@ -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\ThemeBundle\Asset;
|
||||
|
||||
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
|
||||
|
||||
interface PathResolverInterface
|
||||
{
|
||||
/**
|
||||
* Applies theme hashcode to given asset file in order to distinguish it from
|
||||
* another same named assets files with another theme or without it.
|
||||
*/
|
||||
public function resolve(string $path, ThemeInterface $theme): string;
|
||||
}
|
||||
|
|
@ -1,101 +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\ThemeBundle\Collector;
|
||||
|
||||
use Sylius\Bundle\ThemeBundle\Context\ThemeContextInterface;
|
||||
use Sylius\Bundle\ThemeBundle\HierarchyProvider\ThemeHierarchyProviderInterface;
|
||||
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
|
||||
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
|
||||
|
||||
final class ThemeCollector extends DataCollector
|
||||
{
|
||||
/** @var ThemeRepositoryInterface */
|
||||
private $themeRepository;
|
||||
|
||||
/** @var ThemeContextInterface */
|
||||
private $themeContext;
|
||||
|
||||
/** @var ThemeHierarchyProviderInterface */
|
||||
private $themeHierarchyProvider;
|
||||
|
||||
public function __construct(
|
||||
ThemeRepositoryInterface $themeRepository,
|
||||
ThemeContextInterface $themeContext,
|
||||
ThemeHierarchyProviderInterface $themeHierarchyProvider
|
||||
) {
|
||||
$this->themeRepository = $themeRepository;
|
||||
$this->themeContext = $themeContext;
|
||||
$this->themeHierarchyProvider = $themeHierarchyProvider;
|
||||
|
||||
$this->data = [
|
||||
'used_theme' => null,
|
||||
'used_themes' => [],
|
||||
'themes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function getUsedTheme(): ?ThemeInterface
|
||||
{
|
||||
return $this->data['used_theme'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|ThemeInterface[]
|
||||
*/
|
||||
public function getUsedThemes(): array
|
||||
{
|
||||
return $this->data['used_themes'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ThemeInterface[]
|
||||
*/
|
||||
public function getThemes(): array
|
||||
{
|
||||
return $this->data['themes'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function collect(Request $request, Response $response, ?\Exception $exception = null): void
|
||||
{
|
||||
$usedTheme = $this->themeContext->getTheme();
|
||||
|
||||
$this->data['used_theme'] = $usedTheme;
|
||||
$this->data['used_themes'] = null !== $usedTheme ? $this->themeHierarchyProvider->getThemeHierarchy($usedTheme) : [];
|
||||
$this->data['themes'] = $this->themeRepository->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function reset(): void
|
||||
{
|
||||
$this->data['used_theme'] = null;
|
||||
$this->data['used_themes'] = [];
|
||||
$this->data['themes'] = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'sylius_theme';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,101 +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\ThemeBundle\Command;
|
||||
|
||||
use Sylius\Bundle\ThemeBundle\Asset\Installer\AssetsInstallerInterface;
|
||||
use Sylius\Bundle\ThemeBundle\Asset\Installer\OutputAwareInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Command that places themes web assets into a given directory.
|
||||
*/
|
||||
final class AssetsInstallCommand extends ContainerAwareCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->setName('sylius:theme:assets:install')
|
||||
->setDefinition([
|
||||
new InputArgument('target', InputArgument::OPTIONAL, 'The target directory'),
|
||||
])
|
||||
->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it')
|
||||
->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks')
|
||||
->setDescription('Installs themes web assets under a public web directory')
|
||||
->setHelp($this->getHelpMessage())
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws \InvalidArgumentException When the target directory does not exist or symlink cannot be used
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): void
|
||||
{
|
||||
$assetsInstaller = $this->getContainer()->get('sylius.theme.asset.assets_installer');
|
||||
if ($assetsInstaller instanceof OutputAwareInterface) {
|
||||
$assetsInstaller->setOutput($output);
|
||||
}
|
||||
|
||||
$symlinkMask = AssetsInstallerInterface::HARD_COPY;
|
||||
|
||||
if ($input->getOption('symlink')) {
|
||||
$symlinkMask = max($symlinkMask, AssetsInstallerInterface::SYMLINK);
|
||||
}
|
||||
|
||||
if ($input->getOption('relative')) {
|
||||
$symlinkMask = max($symlinkMask, AssetsInstallerInterface::RELATIVE_SYMLINK);
|
||||
}
|
||||
|
||||
$assetsInstaller->installAssets($this->getTargetDir($input), $symlinkMask);
|
||||
}
|
||||
|
||||
private function getTargetDir(InputInterface $input): string
|
||||
{
|
||||
if ($input->getArgument('target') === null) {
|
||||
return $this->getContainer()->getParameter('sylius_core.public_dir');
|
||||
}
|
||||
|
||||
return $input->getArgument('target');
|
||||
}
|
||||
|
||||
private function getHelpMessage(): string
|
||||
{
|
||||
return <<<EOT
|
||||
The <info>%command.name%</info> command installs theme assets into a given
|
||||
directory (e.g. the <comment>public</comment> directory).
|
||||
|
||||
<info>php %command.full_name% public</info>
|
||||
|
||||
A "themes" directory will be created inside the target directory.
|
||||
|
||||
To create a symlink to each theme instead of copying its assets, use the
|
||||
<info>--symlink</info> option (will fall back to hard copies when symbolic links aren't possible):
|
||||
|
||||
<info>php %command.full_name% public --symlink</info>
|
||||
|
||||
To make symlink relative, add the <info>--relative</info> option:
|
||||
|
||||
<info>php %command.full_name% public --symlink --relative</info>
|
||||
|
||||
EOT;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +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\ThemeBundle\Command;
|
||||
|
||||
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
final class ListCommand extends ContainerAwareCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->setName('sylius:theme:list')
|
||||
->setDescription('Shows list of detected themes.')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): void
|
||||
{
|
||||
/** @var ThemeInterface[] $themes */
|
||||
$themes = $this->getContainer()->get('sylius.repository.theme')->findAll();
|
||||
|
||||
if (0 === count($themes)) {
|
||||
$output->writeln('<error>There are no themes.</error>');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$output->writeln('<question>Successfully loaded themes:</question>');
|
||||
|
||||
$table = new Table($output);
|
||||
$table->setHeaders(['Title', 'Name', 'Path']);
|
||||
|
||||
foreach ($themes as $theme) {
|
||||
$table->addRow([$theme->getTitle(), $theme->getName(), $theme->getPath()]);
|
||||
}
|
||||
|
||||
$table->setStyle('borderless');
|
||||
$table->render();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +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\ThemeBundle\Configuration;
|
||||
|
||||
final class CompositeConfigurationProvider implements ConfigurationProviderInterface
|
||||
{
|
||||
/** @var ConfigurationProviderInterface[] */
|
||||
private $configurationProviders;
|
||||
|
||||
/**
|
||||
* @param ConfigurationProviderInterface[] $configurationProviders
|
||||
*/
|
||||
public function __construct(array $configurationProviders)
|
||||
{
|
||||
$this->configurationProviders = $configurationProviders;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfigurations(): array
|
||||
{
|
||||
$configurations = [];
|
||||
foreach ($this->configurationProviders as $configurationProvider) {
|
||||
$configurations = array_merge(
|
||||
$configurations,
|
||||
$configurationProvider->getConfigurations()
|
||||
);
|
||||
}
|
||||
|
||||
return $configurations;
|
||||
}
|
||||
}
|
||||
|
|
@ -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\ThemeBundle\Configuration;
|
||||
|
||||
interface ConfigurationProcessorInterface
|
||||
{
|
||||
/**
|
||||
* @param array $configs An array of configuration arrays
|
||||
*
|
||||
* @return array The processed configuration array
|
||||
*/
|
||||
public function process(array $configs): array;
|
||||
}
|
||||
|
|
@ -1,19 +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\ThemeBundle\Configuration;
|
||||
|
||||
interface ConfigurationProviderInterface
|
||||
{
|
||||
public function getConfigurations(): array;
|
||||
}
|
||||
|
|
@ -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\ThemeBundle\Configuration;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
interface ConfigurationSourceFactoryInterface
|
||||
{
|
||||
public function buildConfiguration(ArrayNodeDefinition $node): void;
|
||||
|
||||
/**
|
||||
* @see ConfigurationProviderInterface
|
||||
*
|
||||
* @return Reference|Definition Configuration provider service
|
||||
*/
|
||||
public function initializeSource(ContainerBuilder $container, array $config);
|
||||
|
||||
public function getName(): string;
|
||||
}
|
||||
|
|
@ -1,22 +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\ThemeBundle\Configuration\Filesystem;
|
||||
|
||||
interface ConfigurationLoaderInterface
|
||||
{
|
||||
/**
|
||||
* Loads configuration for given identifier (can be theme name or path to configuration file)
|
||||
*/
|
||||
public function load(string $identifier): array;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue