diff --git a/.travis.yml b/.travis.yml index 0481b6f..f146284 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,9 @@ matrix: env: DEPENDENCIES='low' - php: 5.6 env: DEPENDENCIES='dev' + - php: 5.6 + env: SYMFONY_VERSION=3.0.* allow_failures: - - php: 7.0 - env: DEPENDENCIES='dev' fast_finish: true @@ -21,7 +22,11 @@ sudo: false cache: directories: - - $HOME/.composer/cache + - $HOME/.composer/cache/files + +before_install: + - composer selfupdate + - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi; install: - export SYMFONY_DEPRECATIONS_HELPER=weak diff --git a/UPGRADE.md b/UPGRADE.md new file mode 100644 index 0000000..bd064cc --- /dev/null +++ b/UPGRADE.md @@ -0,0 +1,23 @@ +UPGRADE +======= + +## Upgrade FROM 0.4 to 0.5 + +This version is compatible with Rollerworks Datagrid 0.8, which contains +some major BC breaks! Please see the [component upgrade](https://github.com/rollerworks/datagrid/blob/v0.8.1/UPGRADE.md) +instructions for more information. + + * Support for Symfony 2.3 is dropped, you need at least Symfony 2.7 LTS or Symfony 3 + + * The extension tags are renamed to follow the changes in the component. + + * `rollerworks_datagrid.column_type` is renamed to `rollerworks_datagrid.type` + * `rollerworks_datagrid.column_extension` is renamed to `rollerworks_datagrid.type_extension`. + + * The `alias` argument of `rollerworks_datagrid.column_extension` is renamed to `extended_type`. + + * The `alias` argument of `rollerworks_datagrid.type` is no longer required, and should be removed. + The FQCN is used as the type name now. + + * The `rollerworks_datagrid.extension` is no longer supported, you need to register your types + and types extensions directly as services with the correct tags. diff --git a/composer.json b/composer.json index 10bc955..ffa43e5 100644 --- a/composer.json +++ b/composer.json @@ -16,13 +16,16 @@ ], "require": { "php": ">=5.5.0", - "rollerworks/datagrid": "~0.7", - "rollerworks/datagrid-twig": "~0.4", - "symfony/framework-bundle": "~2.3", - "symfony/twig-bundle": "~2.3" + "rollerworks/datagrid": "~0.8", + "rollerworks/datagrid-twig": "^0.5.1", + "symfony/framework-bundle": "^2.7.9|^3.0.1", + "symfony/dependency-injection": "^2.7.9|^3.0.1", + "symfony/twig-bundle": "~2.7|~3.0" }, "require-dev": { - "matthiasnoback/symfony-dependency-injection-test": "^0.7.3", + "symfony/browser-kit": "^2.7.9|~3.0", + "symfony/css-selector": "^2.7.9|~3.0", + "matthiasnoback/symfony-dependency-injection-test": "^0.7.4", "matthiasnoback/symfony-service-definition-validator": "^1.2.2" }, "autoload": { @@ -35,12 +38,9 @@ "Rollerworks\\Bundle\\DatagridBundle\\Tests\\": "tests/" } }, - "config": { - "bin-dir": "bin" - }, "extra": { "branch-alias": { - "dev-master": "0.4-dev" + "dev-master": "0.5-dev" } }, "minimum-stability": "dev", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 959e85a..f7900b0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -15,6 +15,13 @@ + + + + diff --git a/src/DependencyInjection/Compiler/ExtensionPass.php b/src/DependencyInjection/Compiler/ExtensionPass.php index ee1acb2..fb9e6b8 100644 --- a/src/DependencyInjection/Compiler/ExtensionPass.php +++ b/src/DependencyInjection/Compiler/ExtensionPass.php @@ -11,14 +11,11 @@ namespace Rollerworks\Bundle\DatagridBundle\DependencyInjection\Compiler; -use Rollerworks\Component\Datagrid\Twig\Extension\DatagridExtension as TwigDatagridExtension; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\Reference; /** - * Adds all services with the tags "rollerworks_datagrid.column_type" and "rollerworks_datagrid.column_extension" as + * Adds all services with the tags "rollerworks_datagrid.type" and "rollerworks_datagrid.type_extension" as * arguments of the "rollerworks_datagrid.extension" service. * * @author Sebastiaan Stok @@ -36,59 +33,46 @@ public function process(ContainerBuilder $container) $definition = $container->getDefinition('rollerworks_datagrid.extension'); - $this->processTwig($container); - $this->processExtensions($container); - $this->processTypes($definition, $container); - $this->processTypeExtensions($definition, $container); - } - - private function processTwig(ContainerBuilder $container) - { - $reflection = new \ReflectionClass(TwigDatagridExtension::class); - $extensionFolder = dirname(dirname(dirname($reflection->getFileName()))); - - $container->getDefinition('twig.loader.filesystem')->addMethodCall( - 'addPath', - [$extensionFolder.'/Resources/theme'] - ); - } - - private function processExtensions(ContainerBuilder $container) - { - if (!$container->hasDefinition('rollerworks_datagrid.registry')) { - return; - } - - $definition = $container->getDefinition('rollerworks_datagrid.registry'); - $extensions = $definition->getArgument(0); - - foreach (array_keys($container->findTaggedServiceIds('rollerworks_datagrid.extension')) as $serviceId) { - $extensions[] = new Reference($serviceId); - } - - $definition->replaceArgument(0, $extensions); - } - - private function processTypes(Definition $definition, ContainerBuilder $container) - { + // Builds an array with fully-qualified type class names as keys and service IDs as values $types = []; - foreach ($container->findTaggedServiceIds('rollerworks_datagrid.column_type') as $serviceId => $tag) { - $alias = isset($tag[0]['alias']) ? $tag[0]['alias'] : $serviceId; - // Flip, because we want tag aliases (= type identifiers) as keys - $types[$alias] = $serviceId; + foreach ($container->findTaggedServiceIds('rollerworks_datagrid.type') as $serviceId => $tag) { + $serviceDefinition = $container->getDefinition($serviceId); + if (!$serviceDefinition->isPublic()) { + throw new \InvalidArgumentException( + sprintf('The service "%s" must be public as datagrid types are lazy-loaded.', $serviceId) + ); + } + + // Support type access by FQCN + $types[$serviceDefinition->getClass()] = $serviceId; } $definition->replaceArgument(1, $types); - } - private function processTypeExtensions(Definition $definition, ContainerBuilder $container) - { $typeExtensions = []; - foreach ($container->findTaggedServiceIds('rollerworks_datagrid.column_extension') as $serviceId => $tag) { - $alias = isset($tag[0]['alias']) ? $tag[0]['alias'] : $serviceId; - $typeExtensions[$alias][] = $serviceId; + foreach ($container->findTaggedServiceIds('rollerworks_datagrid.type_extension') as $serviceId => $tag) { + $serviceDefinition = $container->getDefinition($serviceId); + if (!$serviceDefinition->isPublic()) { + throw new \InvalidArgumentException( + sprintf('The service "%s" must be public as datagrid type extensions are lazy-loaded.', $serviceId) + ); + } + + if (isset($tag[0]['extended_type'])) { + $extendedType = $tag[0]['extended_type']; + } else { + throw new \InvalidArgumentException( + sprintf( + 'Tagged datagrid type extension must have the extended type configured using the '. + 'extended_type/extended-type attribute, none was configured for the "%s" service.', + $serviceId + ) + ); + } + + $typeExtensions[$extendedType][] = $serviceId; } $definition->replaceArgument(2, $typeExtensions); diff --git a/src/DependencyInjection/Compiler/RequestUriProviderPass.php b/src/DependencyInjection/Compiler/RequestUriProviderPass.php deleted file mode 100644 index 7a6862c..0000000 --- a/src/DependencyInjection/Compiler/RequestUriProviderPass.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Bundle\DatagridBundle\DependencyInjection\Compiler; - -use Symfony\Component\DependencyInjection\Alias; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Reference; - -/** - * @author Sebastiaan Stok - */ -class RequestUriProviderPass implements CompilerPassInterface -{ - /** - * {@inheritdoc} - */ - public function process(ContainerBuilder $container) - { - if (!$container->hasDefinition('rollerworks_datagrid.column_extension.action')) { - return; - } - - $definition = $container->getDefinition('rollerworks_datagrid.column_extension.action'); - - // Symfony >=2.4 - if ($container->hasDefinition('request_stack') || $container->hasAlias('request_stack')) { - $container->setAlias('rollerworks_datagrid.request_uri_provider', new Alias('rollerworks_datagrid.request_uri_provider.request_stack', false)); - } else { - // Symfony 2.3 - $container->setAlias('rollerworks_datagrid.request_uri_provider', new Alias('rollerworks_datagrid.request_uri_provider.request_service', false)); - } - } -} diff --git a/src/DependencyInjection/Compiler/TwigRenderEnginePass.php b/src/DependencyInjection/Compiler/TwigRenderEnginePass.php new file mode 100644 index 0000000..6f6c255 --- /dev/null +++ b/src/DependencyInjection/Compiler/TwigRenderEnginePass.php @@ -0,0 +1,38 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Rollerworks\Bundle\DatagridBundle\DependencyInjection\Compiler; + +use Rollerworks\Component\Datagrid\Twig\Extension\DatagridExtension as TwigDatagridExtension; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; + +/** + * Registers the Datagrid base themes for loading. + * + * @author Sebastiaan Stok + */ +class TwigRenderEnginePass implements CompilerPassInterface +{ + /** + * {@inheritdoc} + */ + public function process(ContainerBuilder $container) + { + $reflection = new \ReflectionClass(TwigDatagridExtension::class); + $extensionFolder = dirname(dirname(dirname($reflection->getFileName()))); + + $container->getDefinition('twig.loader.filesystem')->addMethodCall( + 'addPath', + [$extensionFolder.'/Resources/theme'] + ); + } +} diff --git a/src/Extension/Symfony/DependencyInjectionExtension.php b/src/Extension/Symfony/DependencyInjectionExtension.php index dd4e93e..a09992a 100644 --- a/src/Extension/Symfony/DependencyInjectionExtension.php +++ b/src/Extension/Symfony/DependencyInjectionExtension.php @@ -12,7 +12,7 @@ namespace Rollerworks\Bundle\DatagridBundle\Extension\Symfony; use Rollerworks\Component\Datagrid\DatagridExtensionInterface; -use Rollerworks\Component\Datagrid\DatagridInterface; +use Rollerworks\Component\Datagrid\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\ContainerInterface; final class DependencyInjectionExtension implements DatagridExtensionInterface @@ -25,98 +25,72 @@ final class DependencyInjectionExtension implements DatagridExtensionInterface /** * @var string[] */ - private $columnTypes = []; + private $typeServiceIds = []; /** * @var array[] */ - private $columnExtensions = []; - - /** - * @var string[] - */ - private $gridSubscriberServiceIds = []; + private $typeExtensionServiceIds = []; /** * Constructor. * - * @param ContainerInterface $container Symfony services container object - * @param string[] $columnTypes column-type service-ids (type => service-id ) - * @param array[] $columnExtensions column-type extension service-ids (type => [[service-ids]) - * @param array $gridSubscriberServiceIds Datagrid subscriber service-ids ([service-id, service-id2]) - */ - public function __construct( - ContainerInterface $container, - array $columnTypes, - array $columnExtensions, - array $gridSubscriberServiceIds = [] - ) { - $this->container = $container; - $this->columnTypes = $columnTypes; - $this->columnExtensions = $columnExtensions; - $this->gridSubscriberServiceIds = $gridSubscriberServiceIds; - } - - /** - * {@inheritdoc} + * @param ContainerInterface $container Symfony services container object + * @param string[] $typeServiceIds column-type service-ids (type => service-id ) + * @param array[] $typeExtensionServiceIds column-type extension service-ids (type => [[service-ids]) */ - public function registerListeners(DatagridInterface $datagrid) + public function __construct(ContainerInterface $container, array $typeServiceIds, array $typeExtensionServiceIds) { - $subscribers = []; - - foreach ($this->gridSubscriberServiceIds as $alias => $subscriberName) { - $subscribers[] = $this->container->get($this->gridSubscriberServiceIds[$alias]); - } - - return $subscribers; + $this->container = $container; + $this->typeServiceIds = $typeServiceIds; + $this->typeExtensionServiceIds = $typeExtensionServiceIds; } /** * {@inheritdoc} */ - public function getColumnType($name) + public function getType($name) { - if (!isset($this->columnTypes[$name])) { - throw new \InvalidArgumentException( - sprintf('The field type "%s" is not registered with the service container.', $name) - ); - } - - $type = $this->container->get($this->columnTypes[$name]); - - if ($type->getName() !== $name) { - throw new \InvalidArgumentException( - sprintf( - 'The type name specified for the service "%s" does not match the actual name.'. - 'Expected "%s", given "%s"', - $this->columnTypes[$name], - $name, - $type->getName() - ) + if (!isset($this->typeServiceIds[$name])) { + throw new InvalidArgumentException( + sprintf('The column type "%s" is not registered with the service container.', $name) ); } - return $type; + return $this->container->get($this->typeServiceIds[$name]); } /** * {@inheritdoc} */ - public function hasColumnType($name) + public function hasType($name) { - return isset($this->columnTypes[$name]); + return isset($this->typeServiceIds[$name]); } /** * {@inheritdoc} */ - public function getColumnTypeExtensions($name) + public function getTypeExtensions($name) { $extensions = []; - if (isset($this->columnExtensions[$name])) { - foreach ($this->columnExtensions[$name] as $serviceId) { - $extensions[] = $this->container->get($serviceId); + if (isset($this->typeExtensionServiceIds[$name])) { + foreach ($this->typeExtensionServiceIds[$name] as $serviceId) { + $extensions[] = $extension = $this->container->get($serviceId); + + // validate result of getExtendedType() to ensure it is consistent with the service definition + if ($extension->getExtendedType() !== $name) { + throw new InvalidArgumentException( + sprintf( + 'The extended type specified for the service "%s" does not match the actual extended type. '. + 'Expected "%s", given "%s".', + $serviceId, + $name, + $extension->getExtendedType() + ) + ); + } } } @@ -126,8 +100,8 @@ public function getColumnTypeExtensions($name) /** * {@inheritdoc} */ - public function hasColumnTypeExtensions($name) + public function hasTypeExtensions($name) { - return isset($this->columnExtensions[$name]); + return isset($this->typeExtensionServiceIds[$name]); } } diff --git a/src/Extension/Symfony/RequestUriProviderByRequestService.php b/src/Extension/Symfony/RequestUriProviderByRequestService.php deleted file mode 100644 index 0c59fdf..0000000 --- a/src/Extension/Symfony/RequestUriProviderByRequestService.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Bundle\DatagridBundle\Extension\Symfony; - -use Symfony\Component\DependencyInjection\ContainerInterface; - -class RequestUriProviderByRequestService implements RequestUriProviderInterface -{ - private $container; - - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } - - /** - * @return string - */ - public function getRequestUri() - { - return $this->container->get('request')->getRequestUri(); - } -} diff --git a/src/Extension/Symfony/RequestUriProviderByRequestStack.php b/src/Extension/Symfony/RequestUriProviderByRequestStack.php deleted file mode 100644 index 14df7e4..0000000 --- a/src/Extension/Symfony/RequestUriProviderByRequestStack.php +++ /dev/null @@ -1,35 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Bundle\DatagridBundle\Extension\Symfony; - -use Symfony\Component\HttpFoundation\RequestStack; - -class RequestUriProviderByRequestStack implements RequestUriProviderInterface -{ - /** - * @var RequestStack - */ - private $requestStack; - - public function __construct(RequestStack $requestStack) - { - $this->requestStack = $requestStack; - } - - /** - * @return string - */ - public function getRequestUri() - { - return $this->requestStack->getMasterRequest()->getRequestUri(); - } -} diff --git a/src/Extension/Symfony/RequestUriProviderInterface.php b/src/Extension/Symfony/RequestUriProviderInterface.php deleted file mode 100644 index c725619..0000000 --- a/src/Extension/Symfony/RequestUriProviderInterface.php +++ /dev/null @@ -1,26 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Bundle\DatagridBundle\Extension\Symfony; - -/** - * The RequestUriProvide provides access to the current URI of the master-request. - * - * This interface only exists to be compatible with Symfony <2.4, - * where the RequestStack did not exist yet. - */ -interface RequestUriProviderInterface -{ - /** - * @return string - */ - public function getRequestUri(); -} diff --git a/src/Extension/Symfony/ColumnTypeExtension/ActionTypeExtension.php b/src/Extension/Symfony/TypeExtension/ActionTypeExtension.php similarity index 66% rename from src/Extension/Symfony/ColumnTypeExtension/ActionTypeExtension.php rename to src/Extension/Symfony/TypeExtension/ActionTypeExtension.php index 01dd5b4..fb17369 100644 --- a/src/Extension/Symfony/ColumnTypeExtension/ActionTypeExtension.php +++ b/src/Extension/Symfony/TypeExtension/ActionTypeExtension.php @@ -9,19 +9,19 @@ * with this source code in the file LICENSE. */ -namespace Rollerworks\Bundle\DatagridBundle\Extension\Symfony\ColumnTypeExtension; +namespace Rollerworks\Bundle\DatagridBundle\Extension\Symfony\TypeExtension; -use Rollerworks\Bundle\DatagridBundle\Extension\Symfony\RequestUriProviderInterface; -use Rollerworks\Component\Datagrid\Column\AbstractColumnTypeExtension; +use Rollerworks\Component\Datagrid\Column\AbstractTypeExtension; +use Rollerworks\Component\Datagrid\Extension\Core\Type\ActionType; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; /** * @author Sebastiaan Stok */ -class ActionTypeExtension extends AbstractColumnTypeExtension +class ActionTypeExtension extends AbstractTypeExtension { /** * Router to generate urls. @@ -31,24 +31,24 @@ class ActionTypeExtension extends AbstractColumnTypeExtension private $router; /** - * RequestUriProvider. + * RequestStack. * * This is used for getting the current URI for redirects. * - * @var RequestUriProviderInterface + * @var RequestStack */ - private $requestUriProvider; + private $requestStack; /** * Constructor. * - * @param UrlGeneratorInterface $router - * @param RequestUriProviderInterface $requestUriProvider + * @param UrlGeneratorInterface $router + * @param RequestStack $requestStack */ - public function __construct(UrlGeneratorInterface $router, RequestUriProviderInterface $requestUriProvider) + public function __construct(UrlGeneratorInterface $router, RequestStack $requestStack) { $this->router = $router; - $this->requestUriProvider = $requestUriProvider; + $this->requestStack = $requestStack; } /** @@ -98,32 +98,18 @@ public function configureOptions(OptionsResolver $resolver) ); } - return $this->requestUriProvider->getRequestUri(); + return $this->requestStack->getMasterRequest()->getRequestUri(); }, ] ); - if ($resolver instanceof OptionsResolverInterface) { - $resolver->setAllowedTypes( - [ - 'route_name' => ['string', 'null'], - 'parameters_field_mapping' => ['array'], - 'additional_parameters' => ['array'], - - 'redirect_route' => ['string', 'null'], - 'redirect_parameters_field_mapping' => ['array'], - 'redirect_additional_parameters' => ['array'], - ] - ); - } else { - $resolver->setAllowedTypes('route_name', ['string', 'null']); - $resolver->setAllowedTypes('parameters_field_mapping', ['array']); - $resolver->setAllowedTypes('additional_parameters', ['array']); - - $resolver->setAllowedTypes('redirect_route', ['string', 'null']); - $resolver->setAllowedTypes('redirect_parameters_field_mapping', ['array']); - $resolver->setAllowedTypes('redirect_additional_parameters', ['array']); - } + $resolver->setAllowedTypes('route_name', ['string', 'null']); + $resolver->setAllowedTypes('parameters_field_mapping', ['array']); + $resolver->setAllowedTypes('additional_parameters', ['array']); + + $resolver->setAllowedTypes('redirect_route', ['string', 'null']); + $resolver->setAllowedTypes('redirect_parameters_field_mapping', ['array']); + $resolver->setAllowedTypes('redirect_additional_parameters', ['array']); } /** @@ -131,7 +117,7 @@ public function configureOptions(OptionsResolver $resolver) */ public function getExtendedType() { - return 'action'; + return ActionType::class; } private function createRouteGenerator($routeName, $referenceType, array $fieldMapping, array $additionalParameters) diff --git a/src/Resources/config/services/core.xml b/src/Resources/config/services/core.xml index 3586e7c..82a5f57 100644 --- a/src/Resources/config/services/core.xml +++ b/src/Resources/config/services/core.xml @@ -9,13 +9,12 @@ - + @@ -24,21 +23,16 @@ - + - - - - - - + - + diff --git a/src/Resources/config/services/type.xml b/src/Resources/config/services/type.xml index 992b6c5..c3598b7 100644 --- a/src/Resources/config/services/type.xml +++ b/src/Resources/config/services/type.xml @@ -6,65 +6,40 @@ - - + + + - - + + - - - + + - - - + + - - - + + - - - + + - - - + + - - - + + - - - + + - - - - - - - - - + + - - - - - - - - - - - - diff --git a/src/RollerworksDatagridBundle.php b/src/RollerworksDatagridBundle.php index dc6bcf2..a5f5aa7 100644 --- a/src/RollerworksDatagridBundle.php +++ b/src/RollerworksDatagridBundle.php @@ -20,8 +20,8 @@ final class RollerworksDatagridBundle extends Bundle { public function build(ContainerBuilder $container) { + $container->addCompilerPass(new CompilerPass\TwigRenderEnginePass()); $container->addCompilerPass(new CompilerPass\ExtensionPass()); - $container->addCompilerPass(new CompilerPass\RequestUriProviderPass()); } public function getContainerExtension() diff --git a/tests/DependencyInjection/Compiler/ExtensionPassTest.php b/tests/DependencyInjection/Compiler/ExtensionPassTest.php index 205d813..ba1b19b 100644 --- a/tests/DependencyInjection/Compiler/ExtensionPassTest.php +++ b/tests/DependencyInjection/Compiler/ExtensionPassTest.php @@ -13,90 +13,59 @@ use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; use Rollerworks\Bundle\DatagridBundle\DependencyInjection\Compiler\ExtensionPass; +use Rollerworks\Component\Datagrid\Extension\Core\Type\ColumnType; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\Reference; +use Rollerworks\Bundle\DatagridBundle\Tests\Fixtures\Type; +use Rollerworks\Bundle\DatagridBundle\Tests\Fixtures\TypeExtension; class ExtensionPassTest extends AbstractCompilerPassTestCase { public function testRegisteringOfColumnTypes() { - $collectingService = new Definition(); - $collectingService->setArguments([null, [], []]); - - $this->setDefinition('rollerworks_datagrid.extension', $collectingService); - - $collectedService = new Definition(); - $collectedService->addTag('rollerworks_datagrid.column_type', ['alias' => 'user_id']); - $this->setDefinition('acme_user.datagrid.column_type.user_id', $collectedService); - + $this->registerService('rollerworks_datagrid.extension', \stdClass::class)->setArguments([null, [], []]); + $this->registerService('acme_user.datagrid.type.foo', Type\FooType::class)->addTag('rollerworks_datagrid.type'); + $this->registerService('acme_user.datagrid.type.bar', Type\BarType::class)->addTag('rollerworks_datagrid.type'); $this->compile(); $collectingService = $this->container->findDefinition('rollerworks_datagrid.extension'); $this->assertNull($collectingService->getArgument(0)); - $this->assertEquals(['user_id' => 'acme_user.datagrid.column_type.user_id'], $collectingService->getArgument(1)); - $this->assertCount(0, $collectingService->getArgument(2)); + $this->assertEquals( + [ + Type\FooType::class => 'acme_user.datagrid.type.foo', + Type\BarType::class => 'acme_user.datagrid.type.bar', + ], + $collectingService->getArgument(1) + ); + $this->assertEquals([], $collectingService->getArgument(2)); } public function testRegisteringOfColumnTypesExtensions() { - $collectingService = new Definition(); - $collectingService->setArguments([null, [], []]); - - $this->setDefinition('rollerworks_datagrid.extension', $collectingService); - - $collectedService = new Definition(); - $collectedService->addTag('rollerworks_datagrid.column_extension', ['alias' => 'field']); - $this->setDefinition('acme_user.datagrid.column_extension.field', $collectedService); - + $this->registerService('rollerworks_datagrid.extension', \stdClass::class)->setArguments([null, [], []]); + $this->registerService('acme_user.datagrid.column_extension.bla', TypeExtension\BlaExtension::class)->addTag( + 'rollerworks_datagrid.type_extension', + ['extended_type' => ColumnType::class] + ); + $this->registerService('acme_user.datagrid.column_extension.beep', TypeExtension\BlaExtension::class)->addTag( + 'rollerworks_datagrid.type_extension', + ['extended_type' => ColumnType::class] + ); $this->compile(); $collectingService = $this->container->findDefinition('rollerworks_datagrid.extension'); $this->assertNull($collectingService->getArgument(0)); - $this->assertCount(0, $collectingService->getArgument(1)); + $this->assertEquals([], $collectingService->getArgument(1)); $this->assertEquals( - ['field' => ['acme_user.datagrid.column_extension.field']], + [ColumnType::class => ['acme_user.datagrid.column_extension.bla', 'acme_user.datagrid.column_extension.beep']], $collectingService->getArgument(2) ); } - public function testRegisteringOfDatagridExtensions() - { - $extensionDefinition = new Definition(); - $extensionDefinition->setArguments([null, [], []]); - $this->setDefinition('rollerworks_datagrid.extension', $extensionDefinition); - - $collectingService = new Definition(); - $collectingService->setArguments( - [ - [new Reference('rollerworks_datagrid.extension')], - ] - ); - - $this->setDefinition('rollerworks_datagrid.registry', $collectingService); - - $collectedService = new Definition('DoctrineOrmExtension'); - $collectedService->addTag('rollerworks_datagrid.extension'); - $this->setDefinition('rollerworks_datagrid.extension.doctrine_orm', $collectedService); - - $this->compile(); - - $collectingService = $this->container->findDefinition('rollerworks_datagrid.registry'); - - $this->assertEquals( - $collectingService->getArgument(0), - [ - new Reference('rollerworks_datagrid.extension'), - new Reference('rollerworks_datagrid.extension.doctrine_orm'), - ] - ); - } - protected function registerCompilerPass(ContainerBuilder $container) { $container->addCompilerPass(new ExtensionPass()); - $container->setDefinition('twig.loader.filesystem', new Definition('stdClass')); } } diff --git a/tests/DependencyInjection/Compiler/RequestUriProviderPassTest.php b/tests/DependencyInjection/Compiler/RequestUriProviderPassTest.php deleted file mode 100644 index 1da3641..0000000 --- a/tests/DependencyInjection/Compiler/RequestUriProviderPassTest.php +++ /dev/null @@ -1,55 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Bundle\DatagridBundle\Tests\DependencyInjection\Compiler; - -use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; -use Rollerworks\Bundle\DatagridBundle\DependencyInjection\Compiler\RequestUriProviderPass; -use Rollerworks\Bundle\DatagridBundle\DependencyInjection\DatagridExtension; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Reference; - -class RequestUriProviderPassTest extends AbstractCompilerPassTestCase -{ - protected function setUp() - { - parent::setUp(); - - $this->container->registerExtension(new DatagridExtension()); - $this->container->loadFromExtension('rollerworks_datagrid'); - } - - public function testSymfony23RequestListener() - { - $this->compile(); - - $this->assertContainerBuilderHasAlias( - 'rollerworks_datagrid.request_uri_provider', - 'rollerworks_datagrid.request_uri_provider.request_service' - ); - } - - public function testSymfony24AndHigherRequestStack() - { - $this->registerService('request_stack', 'stdClass'); - $this->compile(); - - $this->assertContainerBuilderHasAlias( - 'rollerworks_datagrid.request_uri_provider', - 'rollerworks_datagrid.request_uri_provider.request_stack' - ); - } - - protected function registerCompilerPass(ContainerBuilder $container) - { - $container->addCompilerPass(new RequestUriProviderPass()); - } -} diff --git a/tests/Extension/Symfony/ColumnTypeExtension/ActionTypeExtensionTest.php b/tests/Extension/Symfony/ColumnTypeExtension/ActionTypeExtensionTest.php index 7a5314d..5a9779e 100644 --- a/tests/Extension/Symfony/ColumnTypeExtension/ActionTypeExtensionTest.php +++ b/tests/Extension/Symfony/ColumnTypeExtension/ActionTypeExtensionTest.php @@ -12,10 +12,12 @@ namespace Rollerworks\Bundle\DatagridBundle\Tests\Extension\Symfony\ColumnTypeExtension; use Prophecy\Argument; -use Rollerworks\Bundle\DatagridBundle\Extension\Symfony\ColumnTypeExtension\ActionTypeExtension; -use Rollerworks\Bundle\DatagridBundle\Extension\Symfony\RequestUriProviderInterface; +use Rollerworks\Bundle\DatagridBundle\Extension\Symfony\TypeExtension\ActionTypeExtension; +use Rollerworks\Component\Datagrid\Extension\Core\Type\ActionType; use Rollerworks\Component\Datagrid\PreloadedExtension; use Rollerworks\Component\Datagrid\Test\ColumnTypeTestCase; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; class ActionTypeExtensionTest extends ColumnTypeTestCase @@ -59,15 +61,15 @@ function () { } ); - $requestUriProvider = $this->prophesize(RequestUriProviderInterface::class); - $requestUriProvider->getRequestUri()->willReturn('/datagrid'); + $requestStack = new RequestStack(); + $requestStack->push(Request::create('/datagrid')); return [ new PreloadedExtension( [], [ - 'action' => [ - new ActionTypeExtension($urlGenerator->reveal(), $requestUriProvider->reveal()), + ActionType::class => [ + new ActionTypeExtension($urlGenerator->reveal(), $requestStack), ], ] ), @@ -76,30 +78,34 @@ function () { protected function getTestedType() { - return 'action'; + return ActionType::class; } - public function testPassLabelToView() + public function testPassLabelToHeaderView() { $column = $this->factory->createColumn( 'edit', $this->getTestedType(), - $this->datagrid, [ - 'content' => 'My label', - 'field_mapping' => ['key'], + 'label' => 'My label', + 'data_provider' => function ($data) { + return ['key' => $data->key]; + }, 'uri_scheme' => '/entity/{key}/edit', ] ); + $datagrid = $this->factory->createDatagrid('grid', [$column]); + $object = new \stdClass(); $object->key = ' foo '; - $this->datagrid->setData([1 => $object]); - $datagridView = $this->datagrid->createView(); - $view = $column->createHeaderView($datagridView); + $datagrid->setData([1 => $object]); + + $view = $datagrid->createView(); + $view = $column->createHeaderView($view); - $this->assertEquals('My label', $view->label); + $this->assertSame('My label', $view->label); } public function testActionWithAttr() @@ -110,6 +116,9 @@ public function testActionWithAttr() 'content' => 'edit', 'attr' => ['class' => 'i-edit'], 'url_attr' => ['data-new-window' => true], + 'data_provider' => function ($data) { + return ['key' => $data->key]; + }, ]; $expectedAttributesAttributes = [ @@ -130,6 +139,9 @@ public function testActionWithUriAsClosure() 'uri_scheme' => function ($values) { return '/entity/'.$values['key'].'/delete'; }, + 'data_provider' => function ($data) { + return ['key' => $data->key]; + }, ]; $expectedAttributes = [ @@ -150,6 +162,9 @@ public function testActionWithContentAsClosure() 'content' => function ($values) { return 'Delete #'.$values['key']; }, + 'data_provider' => function ($data) { + return ['key' => $data->key]; + }, ]; $expectedAttributes = [ @@ -168,6 +183,9 @@ public function testActionWithRedirectUri() 'uri_scheme' => '/entity/{key}/edit', 'content' => 'edit', 'redirect_uri' => '/entity/list', + 'data_provider' => function ($data) { + return ['key' => $data->key]; + }, ]; $expectedAttributes = [ @@ -186,6 +204,9 @@ public function testActionWithRedirectUriWithExistingQueryStringInUrl() 'uri_scheme' => '/entity/{key}/edit?foo=bar', 'content' => 'delete', 'redirect_uri' => '/entity/list?filter=something', + 'data_provider' => function ($data) { + return ['key' => $data->key]; + }, ]; $expectedAttributes = [ @@ -206,6 +227,9 @@ public function testActionWithRedirectUriAsClosure() 'redirect_uri' => function ($values) { return '/entity/list/?last-entity='.$values['key']; }, + 'data_provider' => function ($data) { + return ['key' => $data->key]; + }, ]; $expectedAttributes = [ @@ -224,7 +248,9 @@ public function testActionWithMultipleFields() 'uri_scheme' => '/entity/{id}/edit?name={username}', 'redirect_uri' => null, 'content' => 'edit', - 'field_mapping' => ['id' => 'id', 'username' => 'name'], + 'data_provider' => function ($data) { + return ['id' => $data->id, 'username' => $data->name]; + }, ]; $expectedAttributes = [ @@ -251,7 +277,9 @@ public function testActionWithRouteName() 'route_name' => 'entity_edit', 'parameters_field_mapping' => ['id' => 'id'], 'content' => 'edit', - 'field_mapping' => ['id' => 'id', 'username' => 'name'], + 'data_provider' => function ($data) { + return ['id' => $data->id, 'username' => $data->name]; + }, ]; $expectedAttributes = [ @@ -277,7 +305,9 @@ public function testActionWithAdditionalParams() 'parameters_field_mapping' => ['id' => 'id'], 'additional_parameters' => ['foo' => 'bar'], 'content' => 'edit', - 'field_mapping' => ['id' => 'id', 'username' => 'name'], + 'data_provider' => function ($data) { + return ['id' => $data->id, 'username' => $data->name]; + }, ]; $expectedAttributes = [ @@ -303,7 +333,9 @@ public function testActionWithRedirectRouteName() 'redirect_route' => 'entity_list', 'parameters_field_mapping' => ['id' => 'id'], 'content' => 'edit', - 'field_mapping' => ['id' => 'id', 'username' => 'name'], + 'data_provider' => function ($data) { + return ['id' => $data->id, 'username' => $data->name]; + }, ]; $expectedAttributes = [ @@ -334,7 +366,9 @@ public function testActionWithRedirectAdditionalParams() 'redirect_additional_parameters' => ['filter' => 'something'], 'content' => 'edit', - 'field_mapping' => ['id' => 'id', 'username' => 'name'], + 'data_provider' => function ($data) { + return ['id' => $data->id, 'username' => $data->name]; + }, ]; $expectedAttributes = [ diff --git a/tests/Fixtures/Type/BarType.php b/tests/Fixtures/Type/BarType.php new file mode 100644 index 0000000..6a3674b --- /dev/null +++ b/tests/Fixtures/Type/BarType.php @@ -0,0 +1,18 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Rollerworks\Bundle\DatagridBundle\Tests\Fixtures\Type; + +use Rollerworks\Component\Datagrid\Column\AbstractType; + +final class BarType extends AbstractType +{ +} diff --git a/tests/Fixtures/Type/FooType.php b/tests/Fixtures/Type/FooType.php new file mode 100644 index 0000000..b6d706f --- /dev/null +++ b/tests/Fixtures/Type/FooType.php @@ -0,0 +1,18 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Rollerworks\Bundle\DatagridBundle\Tests\Fixtures\Type; + +use Rollerworks\Component\Datagrid\Column\AbstractType; + +final class FooType extends AbstractType +{ +} diff --git a/tests/Fixtures/TypeExtension/BeepExtension.php b/tests/Fixtures/TypeExtension/BeepExtension.php new file mode 100644 index 0000000..ffaf68a --- /dev/null +++ b/tests/Fixtures/TypeExtension/BeepExtension.php @@ -0,0 +1,23 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Rollerworks\Bundle\DatagridBundle\Tests\Fixtures\TypeExtension; + +use Rollerworks\Component\Datagrid\Column\AbstractTypeExtension; +use Rollerworks\Component\Datagrid\Extension\Core\Type\ColumnType; + +final class BeepExtension extends AbstractTypeExtension +{ + public function getExtendedType() + { + return ColumnType::class; + } +} diff --git a/tests/Fixtures/TypeExtension/BlaExtension.php b/tests/Fixtures/TypeExtension/BlaExtension.php new file mode 100644 index 0000000..2324d26 --- /dev/null +++ b/tests/Fixtures/TypeExtension/BlaExtension.php @@ -0,0 +1,23 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Rollerworks\Bundle\DatagridBundle\Tests\Fixtures\TypeExtension; + +use Rollerworks\Component\Datagrid\Column\AbstractTypeExtension; +use Rollerworks\Component\Datagrid\Extension\Core\Type\ColumnType; + +final class BlaExtension extends AbstractTypeExtension +{ + public function getExtendedType() + { + return ColumnType::class; + } +} diff --git a/tests/Functional/Application/AppBundle/AppBundle.php b/tests/Functional/Application/AppBundle/AppBundle.php new file mode 100644 index 0000000..c3f5438 --- /dev/null +++ b/tests/Functional/Application/AppBundle/AppBundle.php @@ -0,0 +1,18 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Rollerworks\Bundle\DatagridBundle\Tests\Functional\Application\AppBundle; + +use Symfony\Component\HttpKernel\Bundle\Bundle; + +final class AppBundle extends Bundle +{ +} diff --git a/tests/Functional/Application/AppBundle/Controller/DatagridController.php b/tests/Functional/Application/AppBundle/Controller/DatagridController.php new file mode 100644 index 0000000..1ce6b66 --- /dev/null +++ b/tests/Functional/Application/AppBundle/Controller/DatagridController.php @@ -0,0 +1,38 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Rollerworks\Bundle\DatagridBundle\Tests\Functional\Application\AppBundle\Controller; + +use Rollerworks\Component\Datagrid\Extension\Core\Type; +use Symfony\Bundle\FrameworkBundle\Controller\Controller; + +final class DatagridController extends Controller +{ + public function datagridAction() + { + $factory = $this->get('rollerworks_datagrid.factory'); + + $datagrid = $factory->createDatagridBuilder('users') + ->add('id', Type\NumberType::class) + ->add('firstName', Type\TextType::class) + ->add('lastName', Type\TextType::class) + ->add('regDate', Type\DateTimeType::class, ['format' => 'yyyy-MM-dd HH:mm:ss', 'label' => 'Registered on']) + ->getDatagrid(); + + $datagrid->setData([ + ['id' => 0, 'firstName' => 'Doctor', 'lastName' => 'Who', 'regDate' => new \DateTime('1980-12-05 12:00:00 EST')], + ['id' => 1, 'firstName' => 'Homer', 'lastName' => 'Simpson', 'regDate' => new \DateTime('1999-12-05 12:00:00 EST')], + ['id' => 50, 'firstName' => 'Spider', 'lastName' => 'Big', 'regDate' => new \DateTime('2012-08-05 09:12:00 EST')], + ]); + + return $this->render('AppBundle::users.html.twig', ['datagrid' => $datagrid->createView() ]); + } +} diff --git a/tests/Functional/Application/AppBundle/Resources/views/users.html.twig b/tests/Functional/Application/AppBundle/Resources/views/users.html.twig new file mode 100644 index 0000000..ba1add3 --- /dev/null +++ b/tests/Functional/Application/AppBundle/Resources/views/users.html.twig @@ -0,0 +1,10 @@ +{# + # This file is part of the RollerworksDatagrid package. + # + # (c) Sebastiaan Stok + # + # This source file is subject to the MIT license that is bundled + # with this source code in the file LICENSE. + #} + +{{ rollerworks_datagrid(datagrid) }} diff --git a/tests/Functional/Application/AppKernel.php b/tests/Functional/Application/AppKernel.php new file mode 100644 index 0000000..9229d95 --- /dev/null +++ b/tests/Functional/Application/AppKernel.php @@ -0,0 +1,126 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Rollerworks\Bundle\DatagridBundle\Tests\Functional\Application; + +use Matthias\SymfonyServiceDefinitionValidator\Compiler\ValidateServiceDefinitionsPass; +use Matthias\SymfonyServiceDefinitionValidator\Configuration; +use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\DependencyInjection\Compiler\PassConfig; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass; +use Symfony\Component\HttpKernel\Kernel; + +class AppKernel extends Kernel +{ + private $config; + + public function __construct($config, $debug = true) + { + parent::__construct('test', $debug); + + if (!(new Filesystem())->isAbsolutePath($config)) { + $config = __DIR__.'/config/'.$config; + } + + if (!file_exists($config)) { + throw new \RuntimeException(sprintf('The config file "%s" does not exist.', $config)); + } + + $this->config = $config; + } + + public function getName() + { + return 'RDatagrid'; + } + + public function registerBundles() + { + $bundles = [ + new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), + new \Symfony\Bundle\TwigBundle\TwigBundle(), + + new \Rollerworks\Bundle\DatagridBundle\RollerworksDatagridBundle(), + new AppBundle\AppBundle(), + ]; + + return $bundles; + } + + public function getRootDir() + { + if (null === $this->rootDir) { + $this->rootDir = str_replace('\\', '/', __DIR__); + } + + return $this->rootDir; + } + + public function registerContainerConfiguration(LoaderInterface $loader) + { + $loader->load($this->config); + } + + public function getCacheDir() + { + return sys_get_temp_dir().'/RDatagrid/'.substr(sha1($this->config), 0, 6); + } + + public function serialize() + { + return serialize([$this->config, $this->isDebug()]); + } + + public function unserialize($str) + { + call_user_func_array([$this, '__construct'], unserialize($str)); + } + + protected function prepareContainer(ContainerBuilder $container) + { + $extensions = []; + + foreach ($this->bundles as $bundle) { + if ($extension = $bundle->getContainerExtension()) { + $container->registerExtension($extension); + $extensions[] = $extension->getAlias(); + } + + if ($this->debug) { + $container->addObjectResource($bundle); + } + } + + foreach ($this->bundles as $bundle) { + $bundle->build($container); + } + + $this->buildBundleless($container); + + // ensure these extensions are implicitly loaded + $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions)); + } + + private function buildBundleless(ContainerBuilder $container) + { + if ($container->getParameter('kernel.debug')) { + $configuration = new Configuration(); + $configuration->setEvaluateExpressions(true); + + $container->addCompilerPass( + new ValidateServiceDefinitionsPass($configuration), + PassConfig::TYPE_AFTER_REMOVING + ); + } + } +} diff --git a/tests/Functional/Application/config/default.yml b/tests/Functional/Application/config/default.yml new file mode 100644 index 0000000..8ddd7ed --- /dev/null +++ b/tests/Functional/Application/config/default.yml @@ -0,0 +1,2 @@ +imports: + - { resource: framework.yml } diff --git a/tests/Functional/Application/config/framework.yml b/tests/Functional/Application/config/framework.yml new file mode 100644 index 0000000..29c1f46 --- /dev/null +++ b/tests/Functional/Application/config/framework.yml @@ -0,0 +1,16 @@ +framework: + translator: { fallback: en } + secret: test + router: + resource: %kernel.root_dir%/config/routing.yml + strict_requirements: %kernel.debug% + templating: { engines: [twig] } + default_locale: en + trusted_proxies: [] + session: + storage_id: session.storage.filesystem + test: ~ + +twig: + debug: true + strict_variables: true diff --git a/tests/Functional/Application/config/routing.yml b/tests/Functional/Application/config/routing.yml new file mode 100644 index 0000000..c7363f7 --- /dev/null +++ b/tests/Functional/Application/config/routing.yml @@ -0,0 +1,3 @@ +search: + path: /datagrid + defaults: { _controller: "AppBundle:Datagrid:datagrid" } diff --git a/tests/Functional/DatagridFactoryTest.php b/tests/Functional/DatagridFactoryTest.php new file mode 100644 index 0000000..f2b5ba0 --- /dev/null +++ b/tests/Functional/DatagridFactoryTest.php @@ -0,0 +1,99 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Rollerworks\Bundle\DatagridBundle\Tests\Functional; + +use Rollerworks\Component\Datagrid\Extension\Core\Type; + +final class DatagridFactoryTest extends FunctionalTestCase +{ + public function testDatagridWorks() + { + $client = self::newClient(); + $client->request('GET', '/datagrid'); + + $this->assertHtmlEquals( + <<<'HTML' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IdFirst nameLast nameRegistered on
+
0
+
+
Doctor
+
+
Who
+
+
1980-12-05 17:00:00
+
+
1
+
+
Homer
+
+
Simpson
+
+
1999-12-05 17:00:00
+
+
50
+
+
Spider
+
+
Big
+
+
2012-08-05 14:12:00
+
+HTML +, $client->getResponse()->getContent()); + } + + private function assertHtmlEquals($expected, $outputHtml) + { + $this->assertSame( + $this->normalizeWhitespace($expected), + $this->normalizeWhitespace($outputHtml) + ); + } + + private function normalizeWhitespace($value) + { + $value = str_replace(["\r\n", "\r"], "\n", $value); + $value = preg_replace(['/\s+/', '/>\s*<'], $value); + $value = trim($value); + + return $value; + } +} diff --git a/tests/Functional/FunctionalTestCase.php b/tests/Functional/FunctionalTestCase.php new file mode 100644 index 0000000..15caaa1 --- /dev/null +++ b/tests/Functional/FunctionalTestCase.php @@ -0,0 +1,47 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Rollerworks\Bundle\DatagridBundle\Tests\Functional; + +use Rollerworks\Bundle\DatagridBundle\Tests\Functional\Application\AppKernel; +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; + +abstract class FunctionalTestCase extends WebTestCase +{ + protected static function createKernel(array $options = []) + { + return new Application\AppKernel( + isset($options['config']) ? $options['config'] : 'default.yml' + ); + } + + protected static function getKernelClass() + { + return AppKernel::class; + } + + /** + * @param array $options + * @param array $server + * + * @return \Symfony\Bundle\FrameworkBundle\Client + */ + protected static function newClient(array $options = [], array $server = []) + { + $client = static::createClient(array_merge(['config' => 'default.yml'], $options), $server); + + $warmer = $client->getContainer()->get('cache_warmer'); + $warmer->warmUp($client->getContainer()->getParameter('kernel.cache_dir')); + $warmer->enableOptionalWarmers(); + + return $client; + } +}