From f3325053323400baefb82d63ad6eb3a61c65ab14 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Sat, 28 Feb 2015 19:50:36 +0100 Subject: [PATCH 01/19] use setFactory service definition method for symfony >= 2.6 setFactoryClass, setFactoryMethod is deprecated since 2.6 --- .../Factory/Resolver/AwsS3ResolverFactory.php | 10 +++++--- DependencyInjection/LiipImagineExtension.php | 23 +++++++++++++++++++ Resources/config/imagine.xml | 4 ---- .../Resolver/AwsS3ResolverFactoryTest.php | 8 +++++-- .../LiipImagineExtensionTest.php | 20 ++++++++++++++++ 5 files changed, 56 insertions(+), 9 deletions(-) diff --git a/DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php b/DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php index 38cf31d2b..5f88cefe3 100644 --- a/DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php +++ b/DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php @@ -15,11 +15,15 @@ class AwsS3ResolverFactory implements ResolverFactoryInterface */ public function create(ContainerBuilder $container, $resolverName, array $config) { + $awsS3ClientId = 'liip_imagine.cache.resolver.'.$resolverName.'.client'; $awsS3ClientDefinition = new Definition('Aws\S3\S3Client'); - $awsS3ClientDefinition->setFactoryClass('Aws\S3\S3Client'); - $awsS3ClientDefinition->setFactoryMethod('factory'); + if (method_exists($awsS3ClientDefinition, 'setFactory')) { + $awsS3ClientDefinition->setFactory(array('Aws\S3\S3Client', 'factory')); + } else { + $awsS3ClientDefinition->setFactoryService('Aws\S3\S3Client'); + $awsS3ClientDefinition->setFactoryMethod('factory'); + } $awsS3ClientDefinition->addArgument($config['client_config']); - $awsS3ClientId = 'liip_imagine.cache.resolver.'.$resolverName.'.client'; $container->setDefinition($awsS3ClientId, $awsS3ClientDefinition); $resolverDefinition = new DefinitionDecorator('liip_imagine.cache.resolver.prototype.aws_s3'); diff --git a/DependencyInjection/LiipImagineExtension.php b/DependencyInjection/LiipImagineExtension.php index d9990c08a..1e0174e9d 100644 --- a/DependencyInjection/LiipImagineExtension.php +++ b/DependencyInjection/LiipImagineExtension.php @@ -63,6 +63,8 @@ public function load(array $configs, ContainerBuilder $container) $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('imagine.xml'); + $this->setFactories($container); + if (interface_exists('Imagine\Image\Metadata\MetadataReaderInterface')) { $container->getDefinition('liip_imagine.'.$config['driver'])->addMethodCall('setMetadataReader', array(new Reference('liip_imagine.meta_data.reader'))); } else { @@ -113,4 +115,25 @@ protected function loadLoaders(array $config, ContainerBuilder $container) $factory->create($container, $loaderName, $loaderConfig[$factoryName]); } } + + /** + * @param ContainerBuilder $container + */ + private function setFactories($container) + { + $factories = array( + 'liip_imagine.mime_type_guesser' => array('Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser', 'getInstance'), + 'liip_imagine.extension_guesser' => array('Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser', 'getInstance'), + ); + + foreach ($factories as $service => $factory) { + $definition = $container->getDefinition($service); + if (method_exists($definition, 'setFactory')) { + $definition->setFactory($factory); + } else { + $definition->setFactoryClass($factory[0]); + $definition->setFactoryMethod($factory[1]); + } + } + } } diff --git a/Resources/config/imagine.xml b/Resources/config/imagine.xml index c432a3ef3..c4afaab4a 100644 --- a/Resources/config/imagine.xml +++ b/Resources/config/imagine.xml @@ -244,15 +244,11 @@ diff --git a/Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php b/Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php index 5283df2ed..af6e95dfb 100644 --- a/Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php +++ b/Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php @@ -107,8 +107,12 @@ public function testCreateS3ClientDefinitionOnCreate() $clientDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername.client'); $this->assertEquals('Aws\S3\S3Client', $clientDefinition->getClass()); - $this->assertEquals('Aws\S3\S3Client', $clientDefinition->getFactoryClass()); - $this->assertEquals('factory', $clientDefinition->getFactoryMethod()); + if (method_exists($clientDefinition, 'getFactory')) { + $this->assertEquals(array('Aws\S3\S3Client', 'factory'), $clientDefinition->getFactory()); + } else { + $this->assertEquals('Aws\S3\S3Client', $clientDefinition->getFactoryClass()); + $this->assertEquals('factory', $clientDefinition->getFactoryMethod()); + } $this->assertEquals(array('theClientConfigKey' => 'theClientConfigVal'), $clientDefinition->getArgument(0)); } diff --git a/Tests/DependencyInjection/LiipImagineExtensionTest.php b/Tests/DependencyInjection/LiipImagineExtensionTest.php index 6965da4cd..fd77d3d54 100644 --- a/Tests/DependencyInjection/LiipImagineExtensionTest.php +++ b/Tests/DependencyInjection/LiipImagineExtensionTest.php @@ -62,6 +62,26 @@ public function testCustomRouteRequirements() $this->assertEquals('value1', $variable1, sprintf('%s parameter is correct', $variable1)); } + public function testFactoriesConfiguration() + { + $this->createEmptyConfiguration(); + + $factories = array( + 'liip_imagine.mime_type_guesser' => array('Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser', 'getInstance'), + 'liip_imagine.extension_guesser' => array('Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser', 'getInstance'), + ); + + foreach ($factories as $service => $factory) { + $definition = $this->containerBuilder->getDefinition($service); + if (method_exists($definition, 'getFactory')) { + $this->assertEquals($factory, $definition->getFactory()); + } else { + $this->assertEquals($factory[0], $definition->getFactoryClass()); + $this->assertEquals($factory[1], $definition->getFactoryMethod()); + } + } + } + /** * @return ContainerBuilder */ From 23425b56562004d7e59fe4857fd3db7d9ac6158d Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Sat, 28 Feb 2015 20:38:30 +0100 Subject: [PATCH 02/19] fix setting factory class --- DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php b/DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php index 5f88cefe3..45ccf6ccc 100644 --- a/DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php +++ b/DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php @@ -20,7 +20,7 @@ public function create(ContainerBuilder $container, $resolverName, array $config if (method_exists($awsS3ClientDefinition, 'setFactory')) { $awsS3ClientDefinition->setFactory(array('Aws\S3\S3Client', 'factory')); } else { - $awsS3ClientDefinition->setFactoryService('Aws\S3\S3Client'); + $awsS3ClientDefinition->setFactoryClass('Aws\S3\S3Client'); $awsS3ClientDefinition->setFactoryMethod('factory'); } $awsS3ClientDefinition->addArgument($config['client_config']); From 6d4e0c854f75196897ae60bd8fe95c427ec90ea0 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Fri, 29 May 2015 16:14:37 +0200 Subject: [PATCH 03/19] expand symfony versions for testing --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index 245baa1be..9c6882b28 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,5 +31,13 @@ matrix: env: SYMFONY_VERSION=2.4.* - php: 5.5 env: SYMFONY_VERSION=2.5.* + - php: 5.5 + env: SYMFONY_VERSION=2.6.* + - php: 5.5 + env: SYMFONY_VERSION=2.7.* + - php: 5.5 + env: SYMFONY_VERSION=2.8.* + - php: 5.5 + env: SYMFONY_VERSION=3.0.* - php: 5.5 env: SYMFONY_VERSION=dev-master From 6c6ca23e2f6d8ef01866842cb5cc811bf3bd21f5 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Fri, 29 May 2015 16:26:47 +0200 Subject: [PATCH 04/19] add testing for symfony 3.0 --- .travis.yml | 2 +- composer.json | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9c6882b28..9b4e3befb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ php: - hhvm env: - - SYMFONY_VERSION=2.3.* + - SYMFONY_VERSION="~2.3||~3.0" before_script: - yes '' | pecl -q install -f mongo diff --git a/composer.json b/composer.json index a78556928..0a42ad5bb 100644 --- a/composer.json +++ b/composer.json @@ -18,18 +18,18 @@ "require": { "php": ">=5.3.2", "imagine/Imagine": "~0.5,<0.7", - "symfony/finder": "~2.3", - "symfony/filesystem": "~2.3", - "symfony/options-resolver": "~2.3", - "symfony/framework-bundle": "~2.3" + "symfony/finder": "~2.3 || ~3.0", + "symfony/filesystem": "~2.3 || ~3.0", + "symfony/options-resolver": "~2.3 || ~3.0", + "symfony/framework-bundle": "~2.3 || ~3.0" }, "require-dev": { "phpunit/phpunit": "~4.3", - "symfony/browser-kit": "~2.3", - "symfony/yaml": "~2.3", - "symfony/form": "~2.3", - "symfony/console": "~2.3", + "symfony/browser-kit": "~2.3 || ~3.0", + "symfony/yaml": "~2.3 || ~3.0", + "symfony/form": "~2.3 || ~3.0", + "symfony/console": "~2.3 || ~3.0", "doctrine/orm": "~2.3", "doctrine/mongodb-odm": "1.0.*", "doctrine/cache": "~1.1", From dc58bd92eac40b73c32593c3c5d17ee4880312cc Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Fri, 29 May 2015 16:26:53 +0200 Subject: [PATCH 05/19] cs fix --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9b4e3befb..53c687155 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ php: - 5.5 - 5.6 - hhvm - + env: - SYMFONY_VERSION="~2.3||~3.0" From 491a9ddc85867e88b81d8eb5860394ac6daa926d Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Sat, 30 May 2015 10:58:08 +0200 Subject: [PATCH 06/19] add SYMFONY_DEPRECATIONS_HELPER=weak for symfony >= 2.7 --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 53c687155..f59286566 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,10 +34,10 @@ matrix: - php: 5.5 env: SYMFONY_VERSION=2.6.* - php: 5.5 - env: SYMFONY_VERSION=2.7.* + env: SYMFONY_VERSION=2.7.* SYMFONY_DEPRECATIONS_HELPER=weak - php: 5.5 - env: SYMFONY_VERSION=2.8.* + env: SYMFONY_VERSION=2.8.* SYMFONY_DEPRECATIONS_HELPER=weak - php: 5.5 - env: SYMFONY_VERSION=3.0.* + env: SYMFONY_VERSION=3.0.* SYMFONY_DEPRECATIONS_HELPER=weak - php: 5.5 env: SYMFONY_VERSION=dev-master From 6764a83212cb7a8c4ddef8db723eb5dfc9b7b432 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Sat, 30 May 2015 11:13:04 +0200 Subject: [PATCH 07/19] add symfony 2.3 on php 5.5 for testing --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index f59286566..9588a0d58 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,8 @@ matrix: - env: SYMFONY_VERSION=dev-master - php: hhvm include: + - php: 5.5 + env: SYMFONY_VERSION=2.3.* - php: 5.5 env: SYMFONY_VERSION=2.4.* - php: 5.5 From cf9d22d8ea5c5f75dd57e24c816c5d1eb0fc0a80 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Mon, 1 Jun 2015 13:37:12 +0200 Subject: [PATCH 08/19] fix memory limit in travis tests --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 9588a0d58..8e616dda5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ env: before_script: - yes '' | pecl -q install -f mongo - composer self-update + - sh -c 'if [ "${TRAVIS_PHP_VERSION}" != "hhvm" ]; then echo "memory_limit = -1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi;' - composer require symfony/symfony:${SYMFONY_VERSION} --prefer-source - composer install --dev --prefer-source From 80b99eaac9341a87ae10b70567a2fc636f4c6778 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Mon, 1 Jun 2015 13:41:06 +0200 Subject: [PATCH 09/19] add symfony/phpunit-bridge --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 0a42ad5bb..50aa9249c 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,7 @@ "symfony/yaml": "~2.3 || ~3.0", "symfony/form": "~2.3 || ~3.0", "symfony/console": "~2.3 || ~3.0", + "symfony/phpunit-bridge": "~2.3 || ~3.0", "doctrine/orm": "~2.3", "doctrine/mongodb-odm": "1.0.*", "doctrine/cache": "~1.1", From 859939667953d56ddb2de8de63b2f7e91d4f849d Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Mon, 1 Jun 2015 14:52:54 +0200 Subject: [PATCH 10/19] add SYMFONY_DEPRECATIONS_HELPER as env var --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8e616dda5..b279f246f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ php: - hhvm env: - - SYMFONY_VERSION="~2.3||~3.0" + - SYMFONY_VERSION="~2.3||~3.0" SYMFONY_DEPRECATIONS_HELPER=weak before_script: - yes '' | pecl -q install -f mongo From 61e2c1e8112e6c2da958212c7e9a1627cfaf8377 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Wed, 3 Jun 2015 08:09:02 +0200 Subject: [PATCH 11/19] use configureOptions and isDefined for symfony >= 2.6 --- Form/Type/ImageType.php | 8 +++++++- Tests/Form/Type/ImageTypeTest.php | 12 ++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Form/Type/ImageType.php b/Form/Type/ImageType.php index 856aa4583..2e2f24aa6 100644 --- a/Form/Type/ImageType.php +++ b/Form/Type/ImageType.php @@ -5,6 +5,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolverInterface; /** @@ -24,7 +25,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) $view->vars['link_attr'] = $options['link_attr']; } - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setRequired(array( 'image_path', @@ -39,6 +40,11 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) )); } + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $this->configureOptions($resolver); + } + public function getParent() { return 'file'; diff --git a/Tests/Form/Type/ImageTypeTest.php b/Tests/Form/Type/ImageTypeTest.php index 56d78d779..7b55fdff0 100644 --- a/Tests/Form/Type/ImageTypeTest.php +++ b/Tests/Form/Type/ImageTypeTest.php @@ -5,6 +5,7 @@ use Liip\ImagineBundle\Form\Type\ImageType; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\HttpKernel\Kernel; /** * @covers Liip\ImagineBundle\Form\Type\ImageType @@ -30,12 +31,19 @@ public function testSetDefaultOptions() $resolver = new OptionsResolver(); $type = new ImageType(); - $type->setDefaultOptions($resolver); + if (version_compare(Kernel::VERSION_ID, '20600') >= 0) { + $setOptionsMethod = 'configureOptions'; + $isDefinedMethod = 'isDefined'; + } else { + $setOptionsMethod = 'setDefaultOptions'; + $isDefinedMethod = 'isKnown'; + } + + $type->$setOptionsMethod($resolver); $this->assertTrue($resolver->isRequired('image_path')); $this->assertTrue($resolver->isRequired('image_filter')); - $isDefinedMethod = method_exists($resolver, 'isDefined') ? 'isDefined' : 'isKnown'; $this->assertTrue($resolver->$isDefinedMethod('image_attr')); $this->assertTrue($resolver->$isDefinedMethod('link_url')); $this->assertTrue($resolver->$isDefinedMethod('link_filter')); From 8d14b437d1c1b994f61762204c0745973ac70db8 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Wed, 3 Jun 2015 08:25:51 +0200 Subject: [PATCH 12/19] change setDefaultOptions to configureOptions to be more consistent optionResolover --- Imagine/Cache/Resolver/CacheResolver.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Imagine/Cache/Resolver/CacheResolver.php b/Imagine/Cache/Resolver/CacheResolver.php index 589022f9e..ec9fe6f4e 100644 --- a/Imagine/Cache/Resolver/CacheResolver.php +++ b/Imagine/Cache/Resolver/CacheResolver.php @@ -46,7 +46,7 @@ public function __construct(Cache $cache, ResolverInterface $cacheResolver, arra $optionsResolver = new OptionsResolver(); } - $this->setDefaultOptions($optionsResolver); + $this->configureOptions($optionsResolver); $this->options = $optionsResolver->resolve($options); } @@ -222,7 +222,7 @@ protected function saveToCache($cacheKey, $content) return false; } - protected function setDefaultOptions(OptionsResolverInterface $resolver) + protected function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'global_prefix' => 'liip_imagine.resolver_cache', @@ -235,5 +235,9 @@ protected function setDefaultOptions(OptionsResolverInterface $resolver) 'prefix' => 'string', 'index_key' => 'string', )); + + protected function setDefaultOptions(OptionsResolverInterface $resolver) + { + $this->configureOptions($resolver); } } From 2c2e235b0e8ee84091074dd6c9c0b8ae6ba27072 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Wed, 3 Jun 2015 08:27:07 +0200 Subject: [PATCH 13/19] use new way of setting allowed types on OptionResolver for symfony >= 2.6 --- Imagine/Cache/Resolver/CacheResolver.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Imagine/Cache/Resolver/CacheResolver.php b/Imagine/Cache/Resolver/CacheResolver.php index ec9fe6f4e..d61a3e92c 100644 --- a/Imagine/Cache/Resolver/CacheResolver.php +++ b/Imagine/Cache/Resolver/CacheResolver.php @@ -6,6 +6,7 @@ use Liip\ImagineBundle\Binary\BinaryInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\HttpKernel\Kernel; class CacheResolver implements ResolverInterface { @@ -230,11 +231,21 @@ protected function configureOptions(OptionsResolver $resolver) 'index_key' => 'index', )); - $resolver->setAllowedTypes(array( - 'global_prefix' => 'string', - 'prefix' => 'string', - 'index_key' => 'string', - )); + $allowedTypesList = array( + 'global_prefix' => 'string', + 'prefix' => 'string', + 'index_key' => 'string', + ); + + if (version_compare(Kernel::VERSION_ID, '20600') >= 0) { + foreach ($allowedTypesList as $option => $allowedTypes) { + $resolver->setAllowedTypes($option, $allowedTypes); + } + } else { + $resolver->setAllowedTypes($allowedTypesList); + } + + } protected function setDefaultOptions(OptionsResolverInterface $resolver) { From 658148dbcc25cd0cd2b3b5b52ab6afc31ad9309e Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Wed, 3 Jun 2015 08:37:01 +0200 Subject: [PATCH 14/19] add comment about DI fallback --- DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php | 1 + DependencyInjection/LiipImagineExtension.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php b/DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php index 45ccf6ccc..3b2bc0bee 100644 --- a/DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php +++ b/DependencyInjection/Factory/Resolver/AwsS3ResolverFactory.php @@ -20,6 +20,7 @@ public function create(ContainerBuilder $container, $resolverName, array $config if (method_exists($awsS3ClientDefinition, 'setFactory')) { $awsS3ClientDefinition->setFactory(array('Aws\S3\S3Client', 'factory')); } else { + // to be removed when dependency on Symfony DependencyInjection is bumped to 2.6 $awsS3ClientDefinition->setFactoryClass('Aws\S3\S3Client'); $awsS3ClientDefinition->setFactoryMethod('factory'); } diff --git a/DependencyInjection/LiipImagineExtension.php b/DependencyInjection/LiipImagineExtension.php index 1e0174e9d..7b22246e5 100644 --- a/DependencyInjection/LiipImagineExtension.php +++ b/DependencyInjection/LiipImagineExtension.php @@ -129,8 +129,10 @@ private function setFactories($container) foreach ($factories as $service => $factory) { $definition = $container->getDefinition($service); if (method_exists($definition, 'setFactory')) { + // to be inlined in imagine.xml when dependency on Symfony DependencyInjection is bumped to 2.6 $definition->setFactory($factory); } else { + // to be removed when dependency on Symfony DependencyInjection is bumped to 2.6 $definition->setFactoryClass($factory[0]); $definition->setFactoryMethod($factory[1]); } From ce1ade3ab933168b5a3a1277a02accc442aaaff5 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Wed, 3 Jun 2015 09:50:39 +0200 Subject: [PATCH 15/19] add ContainerBuilder type hint --- DependencyInjection/LiipImagineExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DependencyInjection/LiipImagineExtension.php b/DependencyInjection/LiipImagineExtension.php index 7b22246e5..44b0df24c 100644 --- a/DependencyInjection/LiipImagineExtension.php +++ b/DependencyInjection/LiipImagineExtension.php @@ -119,7 +119,7 @@ protected function loadLoaders(array $config, ContainerBuilder $container) /** * @param ContainerBuilder $container */ - private function setFactories($container) + private function setFactories(ContainerBuilder $container) { $factories = array( 'liip_imagine.mime_type_guesser' => array('Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser', 'getInstance'), From d7d06d5f35b8404590acf316330c728782dedc84 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Wed, 3 Jun 2015 09:50:47 +0200 Subject: [PATCH 16/19] add doc blocks --- Form/Type/ImageType.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Form/Type/ImageType.php b/Form/Type/ImageType.php index 2e2f24aa6..baafa153b 100644 --- a/Form/Type/ImageType.php +++ b/Form/Type/ImageType.php @@ -15,6 +15,9 @@ */ class ImageType extends AbstractType { + /** + * {@inheritdoc} + */ public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars['image_path'] = $options['image_path']; @@ -25,6 +28,9 @@ public function buildView(FormView $view, FormInterface $form, array $options) $view->vars['link_attr'] = $options['link_attr']; } + /** + * {@inheritdoc} + */ public function configureOptions(OptionsResolver $resolver) { $resolver->setRequired(array( @@ -40,16 +46,25 @@ public function configureOptions(OptionsResolver $resolver) )); } + /** + * {@inheritdoc} + */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $this->configureOptions($resolver); } + /** + * {@inheritdoc} + */ public function getParent() { return 'file'; } + /** + * {@inheritdoc} + */ public function getName() { return 'liip_imagine_image'; From 4c577ac68a292d72a93a39670f34c889e6a8b2ab Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Wed, 3 Jun 2015 10:07:38 +0200 Subject: [PATCH 17/19] split testing factories in to separate tests based on symfony version --- .../LiipImagineExtensionTest.php | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/Tests/DependencyInjection/LiipImagineExtensionTest.php b/Tests/DependencyInjection/LiipImagineExtensionTest.php index fd77d3d54..f211fb906 100644 --- a/Tests/DependencyInjection/LiipImagineExtensionTest.php +++ b/Tests/DependencyInjection/LiipImagineExtensionTest.php @@ -10,6 +10,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\Yaml\Parser; +use Symfony\Component\HttpKernel\Kernel; /** * @covers Liip\ImagineBundle\DependencyInjection\Configuration @@ -62,24 +63,49 @@ public function testCustomRouteRequirements() $this->assertEquals('value1', $variable1, sprintf('%s parameter is correct', $variable1)); } - public function testFactoriesConfiguration() + /** + * @dataProvider factoriesProvider + */ + public function testFactoriesConfiguration($service, $factory) { + if (version_compare(Kernel::VERSION_ID, '20600') < 0) { + $this->markTestSkipped('No need to test on symfony < 2.6'); + } + $this->createEmptyConfiguration(); + $definition = $this->containerBuilder->getDefinition($service); - $factories = array( - 'liip_imagine.mime_type_guesser' => array('Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser', 'getInstance'), - 'liip_imagine.extension_guesser' => array('Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser', 'getInstance'), - ); + $this->assertEquals($factory, $definition->getFactory()); + } - foreach ($factories as $service => $factory) { - $definition = $this->containerBuilder->getDefinition($service); - if (method_exists($definition, 'getFactory')) { - $this->assertEquals($factory, $definition->getFactory()); - } else { - $this->assertEquals($factory[0], $definition->getFactoryClass()); - $this->assertEquals($factory[1], $definition->getFactoryMethod()); - } + /** + * @dataProvider factoriesProvider + */ + public function testLegacyFactoriesConfiguration($service, $factory) + { + if (version_compare(Kernel::VERSION_ID, '20600') >= 0) { + $this->markTestSkipped('No need to test on symfony >= 2.6'); } + + $this->createEmptyConfiguration(); + $definition = $this->containerBuilder->getDefinition($service); + + $this->assertEquals($factory[0], $definition->getFactoryClass()); + $this->assertEquals($factory[1], $definition->getFactoryMethod()); + } + + public function factoriesProvider() + { + return array( + array( + 'liip_imagine.mime_type_guesser', + array('Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser', 'getInstance'), + ), + array( + 'liip_imagine.extension_guesser', + array('Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser', 'getInstance'), + ), + ); } /** From c2179134b1e63884844e252523ca75f724f797aa Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Wed, 3 Jun 2015 10:20:06 +0200 Subject: [PATCH 18/19] extract testing service definition factories into separate tests --- .../Resolver/AwsS3ResolverFactoryTest.php | 59 +++++++++++++++++-- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php b/Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php index af6e95dfb..ca5732e73 100644 --- a/Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php +++ b/Tests/DependencyInjection/Factory/Resolver/AwsS3ResolverFactoryTest.php @@ -6,6 +6,7 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\Processor; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\HttpKernel\Kernel; /** * @covers Liip\ImagineBundle\DependencyInjection\Factory\Resolver\AwsS3ResolverFactory @@ -107,15 +108,61 @@ public function testCreateS3ClientDefinitionOnCreate() $clientDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername.client'); $this->assertEquals('Aws\S3\S3Client', $clientDefinition->getClass()); - if (method_exists($clientDefinition, 'getFactory')) { - $this->assertEquals(array('Aws\S3\S3Client', 'factory'), $clientDefinition->getFactory()); - } else { - $this->assertEquals('Aws\S3\S3Client', $clientDefinition->getFactoryClass()); - $this->assertEquals('factory', $clientDefinition->getFactoryMethod()); - } $this->assertEquals(array('theClientConfigKey' => 'theClientConfigVal'), $clientDefinition->getArgument(0)); } + public function testCreateS3ClientDefinitionWithFactoryOnCreate() + { + if (version_compare(Kernel::VERSION_ID, '20600') < 0) { + $this->markTestSkipped('No need to test on symfony < 2.6'); + } + + $container = new ContainerBuilder(); + + $resolver = new AwsS3ResolverFactory(); + + $resolver->create($container, 'theResolverName', array( + 'client_config' => array('theClientConfigKey' => 'theClientConfigVal'), + 'bucket' => 'aBucket', + 'acl' => 'aAcl', + 'url_options' => array(), + 'get_options' => array(), + 'put_options' => array(), + 'cache' => false, + 'proxies' => array(), + )); + + $clientDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername.client'); + $this->assertEquals(array('Aws\S3\S3Client', 'factory'), $clientDefinition->getFactory()); + + } + + public function testLegacyCreateS3ClientDefinitionWithFactoryOnCreate() + { + if (version_compare(Kernel::VERSION_ID, '20600') >= 0) { + $this->markTestSkipped('No need to test on symfony >= 2.6'); + } + + $container = new ContainerBuilder(); + + $resolver = new AwsS3ResolverFactory(); + + $resolver->create($container, 'theResolverName', array( + 'client_config' => array('theClientConfigKey' => 'theClientConfigVal'), + 'bucket' => 'aBucket', + 'acl' => 'aAcl', + 'url_options' => array(), + 'get_options' => array(), + 'put_options' => array(), + 'cache' => false, + 'proxies' => array(), + )); + + $clientDefinition = $container->getDefinition('liip_imagine.cache.resolver.theresolvername.client'); + $this->assertEquals('Aws\S3\S3Client', $clientDefinition->getFactoryClass()); + $this->assertEquals('factory', $clientDefinition->getFactoryMethod()); + } + public function testWrapResolverWithProxyOnCreateWithoutCache() { $container = new ContainerBuilder(); From 0177d6f8658cb53e2d20aaf9a9c6906f434c4828 Mon Sep 17 00:00:00 2001 From: Adam Misiorny Date: Thu, 4 Jun 2015 12:52:38 +0200 Subject: [PATCH 19/19] split testing setDefaultOptions and configureOptions --- Tests/Form/Type/ImageTypeTest.php | 38 ++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/Tests/Form/Type/ImageTypeTest.php b/Tests/Form/Type/ImageTypeTest.php index 7b55fdff0..f4fa4af64 100644 --- a/Tests/Form/Type/ImageTypeTest.php +++ b/Tests/Form/Type/ImageTypeTest.php @@ -26,28 +26,44 @@ public function testGetParent() $this->assertEquals('file', $type->getParent()); } - public function testSetDefaultOptions() + public function testConfigureOptions() { + if (version_compare(Kernel::VERSION_ID, '20600') < 0) { + $this->markTestSkipped('No need to test on symfony < 2.6'); + } + $resolver = new OptionsResolver(); $type = new ImageType(); + $type->configureOptions($resolver); + + $this->assertTrue($resolver->isRequired('image_path')); + $this->assertTrue($resolver->isRequired('image_filter')); + + $this->assertTrue($resolver->isDefined('image_attr')); + $this->assertTrue($resolver->isDefined('link_url')); + $this->assertTrue($resolver->isDefined('link_filter')); + $this->assertTrue($resolver->isDefined('link_attr')); + } + + public function testLegacySetDefaultOptions() + { if (version_compare(Kernel::VERSION_ID, '20600') >= 0) { - $setOptionsMethod = 'configureOptions'; - $isDefinedMethod = 'isDefined'; - } else { - $setOptionsMethod = 'setDefaultOptions'; - $isDefinedMethod = 'isKnown'; + $this->markTestSkipped('No need to test on symfony >= 2.6'); } - $type->$setOptionsMethod($resolver); + $resolver = new OptionsResolver(); + $type = new ImageType(); + + $type->setDefaultOptions($resolver); $this->assertTrue($resolver->isRequired('image_path')); $this->assertTrue($resolver->isRequired('image_filter')); - $this->assertTrue($resolver->$isDefinedMethod('image_attr')); - $this->assertTrue($resolver->$isDefinedMethod('link_url')); - $this->assertTrue($resolver->$isDefinedMethod('link_filter')); - $this->assertTrue($resolver->$isDefinedMethod('link_attr')); + $this->assertTrue($resolver->isKnown('image_attr')); + $this->assertTrue($resolver->isKnown('link_url')); + $this->assertTrue($resolver->isKnown('link_filter')); + $this->assertTrue($resolver->isKnown('link_attr')); } public function testBuildView()