From e172b747ee34cc70aa971099de827ba48023d347 Mon Sep 17 00:00:00 2001 From: Rob Frawley 2nd Date: Wed, 20 Sep 2017 05:01:08 -0400 Subject: [PATCH] updated cs rules (php-cs-fixer run) --- .php_cs.dist | 47 +++++-- Async/CacheResolved.php | 9 ++ Async/ResolveCache.php | 13 +- Async/ResolveCacheProcessor.php | 11 +- Async/Topics.php | 9 ++ Binary/Loader/AbstractDoctrineLoader.php | 36 ++--- Binary/Loader/FileSystemLoader.php | 2 +- Binary/Loader/FlysystemLoader.php | 2 +- Binary/Locator/FileSystemLocator.php | 22 +-- .../Compiler/MetadataReaderCompilerPass.php | 12 +- DependencyInjection/Configuration.php | 10 +- .../Loader/FileSystemLoaderFactory.php | 2 +- .../PostProcessor/InvalidOptionException.php | 2 +- Imagine/Cache/CacheManager.php | 68 ++++----- .../Resolver/AbstractFilesystemResolver.php | 12 +- Imagine/Cache/Resolver/CacheResolver.php | 44 +++--- Imagine/Cache/Resolver/FlysystemResolver.php | 38 ++--- Imagine/Cache/Resolver/WebPathResolver.php | 6 +- Imagine/Data/DataManager.php | 2 +- Imagine/Filter/FilterManager.php | 3 +- .../Filter/Loader/AutoRotateFilterLoader.php | 6 +- Imagine/Filter/Loader/FlipFilterLoader.php | 8 +- .../Filter/Loader/ResampleFilterLoader.php | 4 +- Imagine/Filter/Loader/ScaleFilterLoader.php | 2 +- .../Filter/Loader/WatermarkFilterLoader.php | 2 +- .../PostProcessor/AbstractPostProcessor.php | 4 +- .../PostProcessor/JpegOptimPostProcessor.php | 2 +- .../PostProcessor/OptiPngPostProcessor.php | 4 +- .../PostProcessor/PngquantPostProcessor.php | 8 +- Imagine/Filter/RelativeResize.php | 2 +- Tests/AbstractTest.php | 22 +-- Tests/Async/CacheResolvedTest.php | 11 +- Tests/Async/ResolveCacheProcessorTest.php | 11 +- Tests/Async/ResolveCacheTest.php | 11 +- Tests/Binary/Loader/ChainLoaderTest.php | 2 + Tests/Binary/Loader/FileSystemLoaderTest.php | 2 + .../Locator/AbstractFileSystemLocatorTest.php | 16 ++- Tests/Binary/SimpleMimeTypeGuesserTest.php | 16 +-- .../Compiler/AbstractCompilerPassTest.php | 130 +++++++++--------- .../MetadataReaderCompilerPassTest.php | 56 ++++---- .../DependencyInjection/ConfigurationTest.php | 6 - .../LiipImagineExtensionTest.php | 16 ++- Tests/Form/Type/ImageTypeTest.php | 2 +- .../Binary/Loader/ChainLoaderTest.php | 20 +-- .../Binary/Loader/FileSystemLoaderTest.php | 20 +-- .../Binary/Locator/FileSystemLocatorTest.php | 20 +-- Tests/Imagine/Cache/CacheManagerTest.php | 22 +-- Tests/Imagine/Filter/FilterManagerTest.php | 2 + .../Loader/AutoRotateFilterLoaderTest.php | 122 ++++++++-------- .../Loader/DownscaleFilterLoaderTest.php | 4 + .../Loader/ResampleFilterLoaderTest.php | 4 +- .../Filter/Loader/ScaleFilterLoaderTest.php | 67 +++++---- .../AbstractPostProcessorTest.php | 45 +++--- .../AbstractPostProcessorTestCase.php | 14 +- .../JpegOptimPostProcessorTest.php | 3 +- .../MozJpegPostProcessorTest.php | 1 + .../OptiPngPostProcessorTest.php | 1 + .../PngquantPostProcessorTest.php | 1 + .../OptionsResolver/OptionsResolverTest.php | 2 +- 59 files changed, 577 insertions(+), 464 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index b2551b4d9..89ff276f3 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -9,11 +9,7 @@ * file that was distributed with this source code. */ -use SLLH\StyleCIBridge\ConfigBridge; - -require_once __DIR__.'/vendor/sllh/php-cs-fixer-styleci-bridge/autoload.php'; - -$header = <<setRules(array_merge($config->getRules(), array( - 'header_comment' => array('header' => $header) - ))) - ->setUsingCache(false); - -return $config; +return PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setRules(array( + '@Symfony' => true, + '@Symfony:risky' => true, + 'array_syntax' => array('syntax' => 'long'), + 'combine_consecutive_unsets' => true, + 'header_comment' => array('header' => $header), + 'heredoc_to_nowdoc' => true, + 'linebreak_after_opening_tag' => true, + 'list_syntax' => array('syntax' => 'long'), + 'no_short_echo_tag' => true, + 'no_unreachable_default_argument_value' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'php_unit_construct' => true, + 'php_unit_dedicate_assert' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'phpdoc_order' => true, + 'psr4' => true, + 'strict_comparison' => true, + 'strict_param' => true, + )) + ->setFinder( + PhpCsFixer\Finder::create() + ->name("*.php") + ->name("*.twig") + ->exclude('vendor/var') + ->in(__DIR__) + ) +; diff --git a/Async/CacheResolved.php b/Async/CacheResolved.php index cc9ce63d1..09ac04b50 100644 --- a/Async/CacheResolved.php +++ b/Async/CacheResolved.php @@ -1,5 +1,14 @@ null, 'filters' => null, 'force' => false), JSON::decode($json)); - if (false == $data['path']) { + if (!$data['path']) { throw new \LogicException('The message does not contain "path" but it is required.'); } - if (false == (is_null($data['filters']) || is_array($data['filters']))) { + if (false === (null === $data['filters'] || is_array($data['filters']))) { throw new \LogicException('The message filters could be either null or array.'); } diff --git a/Async/ResolveCacheProcessor.php b/Async/ResolveCacheProcessor.php index 46bc1b881..51e8200b7 100644 --- a/Async/ResolveCacheProcessor.php +++ b/Async/ResolveCacheProcessor.php @@ -1,5 +1,14 @@ cacheManager->remove($path, $filter); } - if (false == $this->cacheManager->isStored($path, $filter)) { + if (false === $this->cacheManager->isStored($path, $filter)) { $binary = $this->dataManager->find($filter, $path); $this->cacheManager->store( $this->filterManager->applyFilter($binary, $filter), diff --git a/Async/Topics.php b/Async/Topics.php index 4529a4c4c..cab71e751 100644 --- a/Async/Topics.php +++ b/Async/Topics.php @@ -1,5 +1,14 @@ class = $class; } - /** - * Map the requested path (ie. subpath in the URL) to an id that can be used to lookup the image in the Doctrine store. - * - * @param string $path - * - * @return string - */ - abstract protected function mapPathToId($path); - - /** - * Return a stream resource from the Doctrine entity/document with the image content. - * - * @param object $image - * - * @return resource - */ - abstract protected function getStreamFromImage($image); - /** * {@inheritdoc} */ @@ -75,4 +57,22 @@ public function find($path) return stream_get_contents($this->getStreamFromImage($image)); } + + /** + * Map the requested path (ie. subpath in the URL) to an id that can be used to lookup the image in the Doctrine store. + * + * @param string $path + * + * @return string + */ + abstract protected function mapPathToId($path); + + /** + * Return a stream resource from the Doctrine entity/document with the image content. + * + * @param object $image + * + * @return resource + */ + abstract protected function getStreamFromImage($image); } diff --git a/Binary/Loader/FileSystemLoader.php b/Binary/Loader/FileSystemLoader.php index 529c26f47..a091cd29b 100644 --- a/Binary/Loader/FileSystemLoader.php +++ b/Binary/Loader/FileSystemLoader.php @@ -52,7 +52,7 @@ public function __construct(MimeTypeGuesserInterface $mimeGuesser, ExtensionGues if ($locator instanceof LocatorInterface) { // post-1.9.0 behavior $this->locator = $locator; } elseif (is_array($locator) || is_string($locator)) { // pre-1.9.0 behaviour - if (count((array) $locator) === 0) { + if (0 === count((array) $locator)) { throw new InvalidArgumentException('One or more data root paths must be specified.'); } diff --git a/Binary/Loader/FlysystemLoader.php b/Binary/Loader/FlysystemLoader.php index cbfca7eb1..d0b01a7f5 100644 --- a/Binary/Loader/FlysystemLoader.php +++ b/Binary/Loader/FlysystemLoader.php @@ -41,7 +41,7 @@ public function __construct( */ public function find($path) { - if ($this->filesystem->has($path) === false) { + if (false === $this->filesystem->has($path)) { throw new NotLoadableException(sprintf('Source image "%s" not found.', $path)); } diff --git a/Binary/Locator/FileSystemLocator.php b/Binary/Locator/FileSystemLocator.php index 7ba6c295b..ca6fe0f62 100644 --- a/Binary/Locator/FileSystemLocator.php +++ b/Binary/Locator/FileSystemLocator.php @@ -76,6 +76,17 @@ public function locate($path) $path, implode(':', $this->roots))); } + /** + * @param string $root + * @param string $path + * + * @return string|false + */ + protected function generateAbsolutePath($root, $path) + { + return realpath($root.DIRECTORY_SEPARATOR.$path); + } + /** * @param string $path * @@ -111,17 +122,6 @@ private function locateUsingRootPlaceholder($path) $matches['name'], $matches['path'])); } - /** - * @param string $root - * @param string $path - * - * @return string|false - */ - protected function generateAbsolutePath($root, $path) - { - return realpath($root.DIRECTORY_SEPARATOR.$path); - } - /** * @param string $root * diff --git a/DependencyInjection/Compiler/MetadataReaderCompilerPass.php b/DependencyInjection/Compiler/MetadataReaderCompilerPass.php index 7f3334772..fab554605 100644 --- a/DependencyInjection/Compiler/MetadataReaderCompilerPass.php +++ b/DependencyInjection/Compiler/MetadataReaderCompilerPass.php @@ -53,20 +53,20 @@ public function process(ContainerBuilder $container) } /** - * @param ContainerBuilder $container - * * @return bool */ - private function isExifMetadataReaderSet(ContainerBuilder $container) + protected function isExifExtensionLoaded() { - return $container->getParameter(self::$metadataReaderParameter) === self::$metadataReaderExifClass; + return extension_loaded('exif'); } /** + * @param ContainerBuilder $container + * * @return bool */ - protected function isExifExtensionLoaded() + private function isExifMetadataReaderSet(ContainerBuilder $container) { - return extension_loaded('exif'); + return $container->getParameter(self::$metadataReaderParameter) === self::$metadataReaderExifClass; } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index e9e27f9b3..8550e86d6 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -79,11 +79,11 @@ public function getConfigTreeBuilder() $v['loaders'] = array(); } - if (false == is_array($v['loaders'])) { + if (false === is_array($v['loaders'])) { throw new \LogicException('Loaders has to be array'); } - if (false == array_key_exists('default', $v['loaders'])) { + if (false === array_key_exists('default', $v['loaders'])) { $v['loaders']['default'] = array('filesystem' => null); } @@ -91,11 +91,11 @@ public function getConfigTreeBuilder() $v['resolvers'] = array(); } - if (false == is_array($v['resolvers'])) { + if (false === is_array($v['resolvers'])) { throw new \LogicException('Resolvers has to be array'); } - if (false == array_key_exists('default', $v['resolvers'])) { + if (false === array_key_exists('default', $v['resolvers'])) { $v['resolvers']['default'] = array('web_path' => null); } @@ -110,7 +110,7 @@ public function getConfigTreeBuilder() ->scalarNode('driver')->defaultValue('gd') ->validate() ->ifTrue(function ($v) { - return !in_array($v, array('gd', 'imagick', 'gmagick')); + return !in_array($v, array('gd', 'imagick', 'gmagick'), true); }) ->thenInvalid('Invalid imagine driver specified: %s') ->end() diff --git a/DependencyInjection/Factory/Loader/FileSystemLoaderFactory.php b/DependencyInjection/Factory/Loader/FileSystemLoaderFactory.php index 03fd37a52..06113f156 100644 --- a/DependencyInjection/Factory/Loader/FileSystemLoaderFactory.php +++ b/DependencyInjection/Factory/Loader/FileSystemLoaderFactory.php @@ -104,7 +104,7 @@ private function resolveDataRoots(array $staticPaths, array $config, ContainerBu $resourcePaths = array(); foreach ($this->getBundleResourcePaths($container) as $name => $path) { - if (('whitelist' === $config['access_control_type']) === in_array($name, $config['access_control_list']) && is_dir($path)) { + if (('whitelist' === $config['access_control_type']) === in_array($name, $config['access_control_list'], true) && is_dir($path)) { $resourcePaths[$name] = $path; } } diff --git a/Exception/Imagine/Filter/PostProcessor/InvalidOptionException.php b/Exception/Imagine/Filter/PostProcessor/InvalidOptionException.php index 7201ab1d2..b996a19e2 100644 --- a/Exception/Imagine/Filter/PostProcessor/InvalidOptionException.php +++ b/Exception/Imagine/Filter/PostProcessor/InvalidOptionException.php @@ -32,7 +32,7 @@ public function __construct($message, array $options = array()) */ private function stringifyOptions(array $options = array()) { - if (count($options) === 0) { + if (0 === count($options)) { return '[]'; } diff --git a/Imagine/Cache/CacheManager.php b/Imagine/Cache/CacheManager.php index 9c93f1c04..a3fb34d99 100644 --- a/Imagine/Cache/CacheManager.php +++ b/Imagine/Cache/CacheManager.php @@ -91,40 +91,6 @@ public function addResolver($filter, ResolverInterface $resolver) } } - /** - * Gets a resolver for the given filter. - * - * In case there is no specific resolver, but a default resolver has been configured, the default will be returned. - * - * @param string $filter - * @param string $resolver - * - * @throws \OutOfBoundsException If neither a specific nor a default resolver is available - * - * @return ResolverInterface - */ - protected function getResolver($filter, $resolver) - { - // BC - if (false == $resolver) { - $config = $this->filterConfig->get($filter); - - $resolverName = empty($config['cache']) ? $this->defaultResolver : $config['cache']; - } else { - $resolverName = $resolver; - } - - if (!isset($this->resolvers[$resolverName])) { - throw new \OutOfBoundsException(sprintf( - 'Could not find resolver "%s" for "%s" filter type', - $resolverName, - $filter - )); - } - - return $this->resolvers[$resolverName]; - } - /** * Gets filtered path for rendering in the browser. * It could be the cached one or an url of filter action. @@ -288,4 +254,38 @@ public function remove($paths = null, $filters = null) $resolver->remove($paths, $mapping[$resolver]); } } + + /** + * Gets a resolver for the given filter. + * + * In case there is no specific resolver, but a default resolver has been configured, the default will be returned. + * + * @param string $filter + * @param string $resolver + * + * @throws \OutOfBoundsException If neither a specific nor a default resolver is available + * + * @return ResolverInterface + */ + protected function getResolver($filter, $resolver) + { + // BC + if (!$resolver) { + $config = $this->filterConfig->get($filter); + + $resolverName = empty($config['cache']) ? $this->defaultResolver : $config['cache']; + } else { + $resolverName = $resolver; + } + + if (!isset($this->resolvers[$resolverName])) { + throw new \OutOfBoundsException(sprintf( + 'Could not find resolver "%s" for "%s" filter type', + $resolverName, + $filter + )); + } + + return $this->resolvers[$resolverName]; + } } diff --git a/Imagine/Cache/Resolver/AbstractFilesystemResolver.php b/Imagine/Cache/Resolver/AbstractFilesystemResolver.php index 86d6de90e..da82a7ce6 100644 --- a/Imagine/Cache/Resolver/AbstractFilesystemResolver.php +++ b/Imagine/Cache/Resolver/AbstractFilesystemResolver.php @@ -11,6 +11,7 @@ namespace Liip\ImagineBundle\Imagine\Cache\Resolver; +use Guzzle\Http\Message\RequestInterface; use Liip\ImagineBundle\Binary\BinaryInterface; use Liip\ImagineBundle\Imagine\Cache\CacheManager; use Liip\ImagineBundle\Imagine\Cache\CacheManagerAwareInterface; @@ -20,11 +21,6 @@ abstract class AbstractFilesystemResolver implements ResolverInterface, CacheManagerAwareInterface { - /** - * @var Request - */ - private $request; - /** * @var Filesystem */ @@ -44,6 +40,10 @@ abstract class AbstractFilesystemResolver implements ResolverInterface, CacheMan * @var int */ protected $folderPermissions = 0777; + /** + * @var Request + */ + private $request; /** * Constructs a filesystem based cache resolver. @@ -151,7 +151,7 @@ public function remove(array $paths, array $filters) */ protected function getRequest() { - if (false == $this->request) { + if (!$this->request instanceof RequestInterface) { throw new \LogicException('The request was not injected, inject it before using resolver.'); } diff --git a/Imagine/Cache/Resolver/CacheResolver.php b/Imagine/Cache/Resolver/CacheResolver.php index 60fd47044..46cecf65d 100644 --- a/Imagine/Cache/Resolver/CacheResolver.php +++ b/Imagine/Cache/Resolver/CacheResolver.php @@ -116,6 +116,26 @@ public function remove(array $paths, array $filters) } } + /** + * Generate a unique cache key based on the given parameters. + * + * When overriding this method, ensure generateIndexKey is adjusted accordingly. + * + * @param string $path The image path in use + * @param string $filter The filter in use + * + * @return string + */ + public function generateCacheKey($path, $filter) + { + return implode('.', array( + $this->sanitizeCacheKeyPart($this->options['global_prefix']), + $this->sanitizeCacheKeyPart($this->options['prefix']), + $this->sanitizeCacheKeyPart($filter), + $this->sanitizeCacheKeyPart($path), + )); + } + protected function removePathAndFilter($path, $filter) { $indexKey = $this->generateIndexKey($this->generateCacheKey($path, $filter)); @@ -133,7 +153,7 @@ protected function removePathAndFilter($path, $filter) $index = array(); } else { $cacheKey = $this->generateCacheKey($path, $filter); - if (false !== $indexIndex = array_search($cacheKey, $index)) { + if (false !== $indexIndex = array_search($cacheKey, $index, true)) { unset($index[$indexIndex]); $this->cache->delete($cacheKey); } @@ -146,26 +166,6 @@ protected function removePathAndFilter($path, $filter) } } - /** - * Generate a unique cache key based on the given parameters. - * - * When overriding this method, ensure generateIndexKey is adjusted accordingly. - * - * @param string $path The image path in use - * @param string $filter The filter in use - * - * @return string - */ - public function generateCacheKey($path, $filter) - { - return implode('.', array( - $this->sanitizeCacheKeyPart($this->options['global_prefix']), - $this->sanitizeCacheKeyPart($this->options['prefix']), - $this->sanitizeCacheKeyPart($filter), - $this->sanitizeCacheKeyPart($path), - )); - } - /** * Generate the index key for the given cacheKey. * @@ -212,7 +212,7 @@ protected function saveToCache($cacheKey, $content) if ($this->cache->contains($indexKey)) { $index = (array) $this->cache->fetch($indexKey); - if (!in_array($cacheKey, $index)) { + if (!in_array($cacheKey, $index, true)) { $index[] = $cacheKey; } } else { diff --git a/Imagine/Cache/Resolver/FlysystemResolver.php b/Imagine/Cache/Resolver/FlysystemResolver.php index ae6b24e18..4ec71f4cd 100644 --- a/Imagine/Cache/Resolver/FlysystemResolver.php +++ b/Imagine/Cache/Resolver/FlysystemResolver.php @@ -91,25 +91,6 @@ public function isStored($path, $filter) return $this->flysystem->has($this->getFilePath($path, $filter)); } - /** - * {@inheritdoc} - */ - protected function getFilePath($path, $filter) - { - return $this->getFileUrl($path, $filter); - } - - /** - * {@inheritdoc} - */ - protected function getFileUrl($path, $filter) - { - // crude way of sanitizing URL scheme ("protocol") part - $path = str_replace('://', '---', $path); - - return $this->cachePrefix.'/'.$filter.'/'.ltrim($path, '/'); - } - /** * Resolves filtered path for rendering in the browser. * @@ -172,4 +153,23 @@ public function remove(array $paths, array $filters) } } } + + /** + * {@inheritdoc} + */ + protected function getFilePath($path, $filter) + { + return $this->getFileUrl($path, $filter); + } + + /** + * {@inheritdoc} + */ + protected function getFileUrl($path, $filter) + { + // crude way of sanitizing URL scheme ("protocol") part + $path = str_replace('://', '---', $path); + + return $this->cachePrefix.'/'.$filter.'/'.ltrim($path, '/'); + } } diff --git a/Imagine/Cache/Resolver/WebPathResolver.php b/Imagine/Cache/Resolver/WebPathResolver.php index 5ad6a1ab9..4e2a28e8f 100644 --- a/Imagine/Cache/Resolver/WebPathResolver.php +++ b/Imagine/Cache/Resolver/WebPathResolver.php @@ -144,16 +144,16 @@ protected function getFileUrl($path, $filter) protected function getBaseUrl() { $port = ''; - if ('https' == $this->requestContext->getScheme() && $this->requestContext->getHttpsPort() != 443) { + if ('https' === $this->requestContext->getScheme() && 443 !== $this->requestContext->getHttpsPort()) { $port = ":{$this->requestContext->getHttpsPort()}"; } - if ('http' == $this->requestContext->getScheme() && $this->requestContext->getHttpPort() != 80) { + if ('http' === $this->requestContext->getScheme() && 80 !== $this->requestContext->getHttpPort()) { $port = ":{$this->requestContext->getHttpPort()}"; } $baseUrl = $this->requestContext->getBaseUrl(); - if ('.php' == substr($this->requestContext->getBaseUrl(), -4)) { + if ('php' === pathinfo($this->requestContext->getBaseUrl(), PATHINFO_EXTENSION)) { $baseUrl = pathinfo($this->requestContext->getBaseurl(), PATHINFO_DIRNAME); } $baseUrl = rtrim($baseUrl, '/\\'); diff --git a/Imagine/Data/DataManager.php b/Imagine/Data/DataManager.php index de5cddf1d..4d37bca92 100644 --- a/Imagine/Data/DataManager.php +++ b/Imagine/Data/DataManager.php @@ -156,7 +156,7 @@ public function getDefaultImageUrl($filter) $config = $this->filterConfig->get($filter); $defaultImage = null; - if (false == empty($config['default_image'])) { + if (!empty($config['default_image'])) { $defaultImage = $config['default_image']; } elseif (!empty($this->globalDefaultImage)) { $defaultImage = $this->globalDefaultImage; diff --git a/Imagine/Filter/FilterManager.php b/Imagine/Filter/FilterManager.php index 2d4482739..bc45eecf6 100644 --- a/Imagine/Filter/FilterManager.php +++ b/Imagine/Filter/FilterManager.php @@ -16,7 +16,6 @@ use Liip\ImagineBundle\Binary\FileBinaryInterface; use Liip\ImagineBundle\Binary\MimeTypeGuesserInterface; use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface; -use Liip\ImagineBundle\Imagine\Filter\PostProcessor\ConfigurablePostProcessorInterface; use Liip\ImagineBundle\Imagine\Filter\PostProcessor\PostProcessorInterface; use Liip\ImagineBundle\Model\Binary; @@ -148,7 +147,7 @@ public function apply(BinaryInterface $binary, array $config) $options['png_compression_filter'] = $config['png_compression_filter']; } - if ($binary->getFormat() === 'gif' && $config['animated']) { + if ('gif' === $binary->getFormat() && $config['animated']) { $options['animated'] = $config['animated']; } diff --git a/Imagine/Filter/Loader/AutoRotateFilterLoader.php b/Imagine/Filter/Loader/AutoRotateFilterLoader.php index e0b17cb24..7807629df 100644 --- a/Imagine/Filter/Loader/AutoRotateFilterLoader.php +++ b/Imagine/Filter/Loader/AutoRotateFilterLoader.php @@ -37,7 +37,7 @@ public function load(ImageInterface $image, array $options = array()) // Rotates if necessary. $degree = $this->calculateRotation($orientation); - if ($degree !== 0) { + if (0 !== $degree) { $image->rotate($degree); } @@ -90,7 +90,7 @@ private function getOrientation(ImageInterface $image) if ($orientation) { $image->metadata()->offsetSet($orientationKey, '1'); - return intval($orientation); + return (int) $orientation; } } } else { @@ -98,8 +98,6 @@ private function getOrientation(ImageInterface $image) return isset($data['Orientation']) ? $data['Orientation'] : null; } - - return; } /** diff --git a/Imagine/Filter/Loader/FlipFilterLoader.php b/Imagine/Filter/Loader/FlipFilterLoader.php index 25cd8a6b6..a5232b3d7 100644 --- a/Imagine/Filter/Loader/FlipFilterLoader.php +++ b/Imagine/Filter/Loader/FlipFilterLoader.php @@ -12,10 +12,10 @@ namespace Liip\ImagineBundle\Imagine\Filter\Loader; use Imagine\Image\ImageInterface; -use Liip\ImagineBundle\Utility\OptionsResolver\OptionsResolver; use Liip\ImagineBundle\Exception\InvalidArgumentException; -use Symfony\Component\OptionsResolver\Options; +use Liip\ImagineBundle\Utility\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\Exception\ExceptionInterface; +use Symfony\Component\OptionsResolver\Options; class FlipFilterLoader implements LoaderInterface { @@ -29,7 +29,7 @@ public function load(ImageInterface $image, array $options = array()) { $options = $this->sanitizeOptions($options); - return $options['axis'] === 'x' ? $image->flipHorizontally() : $image->flipVertically(); + return 'x' === $options['axis'] ? $image->flipHorizontally() : $image->flipVertically(); } /** @@ -43,7 +43,7 @@ private function sanitizeOptions(array $options) $resolver->setDefault('axis', 'x'); $resolver->setAllowedValues('axis', array('x', 'horizontal', 'y', 'vertical')); $resolver->setNormalizer('axis', function (Options $options, $value) { - return $value === 'horizontal' ? 'x' : ($value === 'vertical' ? 'y' : $value); + return 'horizontal' === $value ? 'x' : ('vertical' === $value ? 'y' : $value); }); try { diff --git a/Imagine/Filter/Loader/ResampleFilterLoader.php b/Imagine/Filter/Loader/ResampleFilterLoader.php index b19fc5f03..370685103 100644 --- a/Imagine/Filter/Loader/ResampleFilterLoader.php +++ b/Imagine/Filter/Loader/ResampleFilterLoader.php @@ -14,10 +14,10 @@ use Imagine\Image\ImageInterface; use Imagine\Image\ImagineInterface; use Liip\ImagineBundle\Exception\Imagine\Filter\LoadFilterException; -use Liip\ImagineBundle\Utility\OptionsResolver\OptionsResolver; use Liip\ImagineBundle\Exception\InvalidArgumentException; -use Symfony\Component\OptionsResolver\Options; +use Liip\ImagineBundle\Utility\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\Exception\ExceptionInterface; +use Symfony\Component\OptionsResolver\Options; class ResampleFilterLoader implements LoaderInterface { diff --git a/Imagine/Filter/Loader/ScaleFilterLoader.php b/Imagine/Filter/Loader/ScaleFilterLoader.php index 3ae828964..109eacf26 100644 --- a/Imagine/Filter/Loader/ScaleFilterLoader.php +++ b/Imagine/Filter/Loader/ScaleFilterLoader.php @@ -67,7 +67,7 @@ public function load(ImageInterface $image, array $options = array()) $widthRatio = $width / $origWidth; $heightRatio = $height / $origHeight; - if (null == $width || null == $height) { + if (null === $width || null === $height) { $ratio = max($widthRatio, $heightRatio); } else { $ratio = ('min' === $this->dimensionKey) ? max($widthRatio, $heightRatio) : min($widthRatio, $heightRatio); diff --git a/Imagine/Filter/Loader/WatermarkFilterLoader.php b/Imagine/Filter/Loader/WatermarkFilterLoader.php index 69afe00e1..8fcaf6db8 100644 --- a/Imagine/Filter/Loader/WatermarkFilterLoader.php +++ b/Imagine/Filter/Loader/WatermarkFilterLoader.php @@ -44,7 +44,7 @@ public function load(ImageInterface $image, array $options = array()) 'position' => 'center', ); - if (substr($options['size'], -1) == '%') { + if ('%' === substr($options['size'], -1)) { $options['size'] = substr($options['size'], 0, -1) / 100; } diff --git a/Imagine/Filter/PostProcessor/AbstractPostProcessor.php b/Imagine/Filter/PostProcessor/AbstractPostProcessor.php index 1fb90ef1d..83e34f761 100644 --- a/Imagine/Filter/PostProcessor/AbstractPostProcessor.php +++ b/Imagine/Filter/PostProcessor/AbstractPostProcessor.php @@ -138,7 +138,7 @@ protected function isBinaryPngMimeType(BinaryInterface $binary) */ protected function isBinaryMatchingMimeType(BinaryInterface $binary, array $types) { - return in_array($binary->getMimeType(), $types); + return in_array($binary->getMimeType(), $types, true); } /** @@ -195,7 +195,7 @@ protected function acquireTemporaryFilePath(array $options, $prefix = null) */ protected function isProcessSuccessful(Process $process, array $validReturns = array(0), array $errorStrings = array('ERROR')) { - if (count($validReturns) > 0 && !in_array($process->getExitCode(), $validReturns)) { + if (count($validReturns) > 0 && !in_array($process->getExitCode(), $validReturns, true)) { return false; } diff --git a/Imagine/Filter/PostProcessor/JpegOptimPostProcessor.php b/Imagine/Filter/PostProcessor/JpegOptimPostProcessor.php index 6abc85a72..018b2d467 100644 --- a/Imagine/Filter/PostProcessor/JpegOptimPostProcessor.php +++ b/Imagine/Filter/PostProcessor/JpegOptimPostProcessor.php @@ -160,7 +160,7 @@ private function setupProcessBuilder(array $options = array()) } if ($quality = isset($options['quality']) ? $options['quality'] : $this->quality) { - if (!in_array($options['quality'], range(0, 100))) { + if (!in_array($options['quality'], range(0, 100), true)) { throw new InvalidOptionException('the "quality" option must be an int between 0 and 100', $options); } diff --git a/Imagine/Filter/PostProcessor/OptiPngPostProcessor.php b/Imagine/Filter/PostProcessor/OptiPngPostProcessor.php index 590d87ee1..bf5cfc154 100644 --- a/Imagine/Filter/PostProcessor/OptiPngPostProcessor.php +++ b/Imagine/Filter/PostProcessor/OptiPngPostProcessor.php @@ -88,7 +88,7 @@ private function setupProcessBuilder(array $options = array()) $builder = $this->createProcessBuilder($options); if (null !== $level = isset($options['level']) ? $options['level'] : $this->level) { - if (!in_array($level, range(0, 7))) { + if (!in_array($level, range(0, 7), true)) { throw new InvalidOptionException('the "level" option must be an int between 0 and 7', $options); } @@ -119,7 +119,7 @@ private function setupProcessBuilder(array $options = array()) } if (isset($options['interlace_type'])) { - if (!in_array($options['interlace_type'], range(0, 1))) { + if (!in_array($options['interlace_type'], range(0, 1), true)) { throw new InvalidOptionException('the "interlace_type" option must be either 0 or 1', $options); } diff --git a/Imagine/Filter/PostProcessor/PngquantPostProcessor.php b/Imagine/Filter/PostProcessor/PngquantPostProcessor.php index e45bcbaed..cabcff280 100644 --- a/Imagine/Filter/PostProcessor/PngquantPostProcessor.php +++ b/Imagine/Filter/PostProcessor/PngquantPostProcessor.php @@ -95,8 +95,8 @@ private function setupProcessBuilder(array $options = array()) if ($quality = isset($options['quality']) ? $options['quality'] : $this->quality) { if (is_string($quality) && false !== strpos($quality, '-')) { - @trigger_error(sprintf('Passing the "quality" option as a string was deprecated in 1.10.0 and ' . - 'will be removed in 2.0. Instead, pass wither an integer representing the max value or an array ' . + @trigger_error(sprintf('Passing the "quality" option as a string was deprecated in 1.10.0 and '. + 'will be removed in 2.0. Instead, pass wither an integer representing the max value or an array '. 'representing the minimum and maximum values.'), E_USER_DEPRECATED); $quality = array_map(function ($q) { @@ -114,7 +114,7 @@ private function setupProcessBuilder(array $options = array()) if ($quality[0] > $quality[1]) { throw new InvalidOptionException('the "quality" option cannot have a greater minimum value value than maximum quality value', $options); - } elseif (!in_array($quality[0], range(0, 100)) || !in_array($quality[1], range(0, 100))) { + } elseif (!in_array($quality[0], range(0, 100), true) || !in_array($quality[1], range(0, 100), true)) { throw new InvalidOptionException('the "quality" option value(s) must be an int between 0 and 100', $options); } @@ -122,7 +122,7 @@ private function setupProcessBuilder(array $options = array()) } if (isset($options['speed'])) { - if (!in_array($options['speed'], range(1, 11))) { + if (!in_array($options['speed'], range(1, 11), true)) { throw new InvalidOptionException('the "speed" option must be an int between 1 and 11', $options); } diff --git a/Imagine/Filter/RelativeResize.php b/Imagine/Filter/RelativeResize.php index 88afbac1a..5a66a9ac2 100644 --- a/Imagine/Filter/RelativeResize.php +++ b/Imagine/Filter/RelativeResize.php @@ -35,7 +35,7 @@ class RelativeResize implements FilterInterface */ public function __construct($method, $parameter) { - if (!in_array($method, array('heighten', 'increase', 'scale', 'widen'))) { + if (!in_array($method, array('heighten', 'increase', 'scale', 'widen'), true)) { throw new InvalidArgumentException(sprintf('Unsupported method: ', $method)); } diff --git a/Tests/AbstractTest.php b/Tests/AbstractTest.php index 2e3d8191a..59523fa0b 100644 --- a/Tests/AbstractTest.php +++ b/Tests/AbstractTest.php @@ -59,6 +59,17 @@ protected function setUp() $this->filesystem->mkdir($this->temporaryPath); } + protected function tearDown() + { + if (!$this->filesystem) { + return; + } + + if ($this->filesystem->exists($this->temporaryPath)) { + $this->filesystem->remove($this->temporaryPath); + } + } + /** * @return string[] */ @@ -265,15 +276,4 @@ protected function getVisibilityRestrictedMethod($object, $name) return $m; } - - protected function tearDown() - { - if (!$this->filesystem) { - return; - } - - if ($this->filesystem->exists($this->temporaryPath)) { - $this->filesystem->remove($this->temporaryPath); - } - } } diff --git a/Tests/Async/CacheResolvedTest.php b/Tests/Async/CacheResolvedTest.php index e6439a3d9..2b5b51ad5 100644 --- a/Tests/Async/CacheResolvedTest.php +++ b/Tests/Async/CacheResolvedTest.php @@ -1,5 +1,14 @@ assertInstanceOf('\Liip\ImagineBundle\Binary\Locator\LocatorInterface', new FileSystemLocator()); @@ -127,9 +120,18 @@ public function provideOutsideRootPathsData() * * @expectedException \Liip\ImagineBundle\Exception\InvalidArgumentException * @expectedExceptionMessage Root image path not resolvable + * + * @param mixed $path */ public function testThrowsIfRealPathOutsideRootPath($path) { $this->getFileSystemLocator($path)->locate($path); } + + /** + * @param string[]|string $roots + * + * @return LocatorInterface + */ + abstract protected function getFileSystemLocator($roots); } diff --git a/Tests/Binary/SimpleMimeTypeGuesserTest.php b/Tests/Binary/SimpleMimeTypeGuesserTest.php index 0cad03ebf..3986dd1d6 100644 --- a/Tests/Binary/SimpleMimeTypeGuesserTest.php +++ b/Tests/Binary/SimpleMimeTypeGuesserTest.php @@ -19,14 +19,6 @@ */ class SimpleMimeTypeGuesserTest extends \PHPUnit_Framework_TestCase { - /** - * @return SimpleMimeTypeGuesser - */ - private function getSimpleMimeTypeGuesser() - { - return new SimpleMimeTypeGuesser(MimeTypeGuesser::getInstance()); - } - public function testCouldBeConstructedWithSymfonyMimeTypeGuesserAsFirstArgument() { $this->getSimpleMimeTypeGuesser(); @@ -61,4 +53,12 @@ public function testGuessMimeType($fileName, $mimeType) { $this->assertEquals($mimeType, $this->getSimpleMimeTypeGuesser()->guess(file_get_contents($fileName))); } + + /** + * @return SimpleMimeTypeGuesser + */ + private function getSimpleMimeTypeGuesser() + { + return new SimpleMimeTypeGuesser(MimeTypeGuesser::getInstance()); + } } diff --git a/Tests/DependencyInjection/Compiler/AbstractCompilerPassTest.php b/Tests/DependencyInjection/Compiler/AbstractCompilerPassTest.php index 73759abf6..cb8959e96 100644 --- a/Tests/DependencyInjection/Compiler/AbstractCompilerPassTest.php +++ b/Tests/DependencyInjection/Compiler/AbstractCompilerPassTest.php @@ -22,71 +22,6 @@ */ class AbstractCompilerPassTest extends AbstractCompilerPassTestCase { - /** - * @param string[] $methods - * - * @return \PHPUnit_Framework_MockObject_MockObject|AbstractCompilerPass - */ - private function createAbstractCompilerPassMock(array $methods = array()) - { - return $this - ->getMockBuilder('\Liip\ImagineBundle\DependencyInjection\Compiler\AbstractCompilerPass') - ->setMethods($methods) - ->getMock(); - } - - /** - * @param string[] $methods - * - * @return \PHPUnit_Framework_MockObject_MockObject|ContainerBuilder - */ - private function createContainerBuilderMock(array $methods = array()) - { - return $this - ->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerBuilder') - ->setMethods($methods) - ->getMock(); - } - - /** - * @param string[] $methods - * - * @return \PHPUnit_Framework_MockObject_MockObject|Compiler - */ - private function createCompilerMock(array $methods = array()) - { - return $this - ->getMockBuilder('\Symfony\Component\DependencyInjection\Compiler\Compiler') - ->setMethods($methods) - ->getMock(); - } - - /** - * @param string[] $methods - * - * @return \PHPUnit_Framework_MockObject_MockObject|Compiler - */ - private function createLoggingFormatterMock(array $methods = array()) - { - return $this - ->getMockBuilder('\Symfony\Component\DependencyInjection\Compiler\LoggingFormatter') - ->setMethods($methods) - ->getMock(); - } - - /** - * @param string[] $methods - * - * @return \PHPUnit_Framework_MockObject_MockObject|Definition - */ - private function createDefinitionMock(array $methods = array()) - { - return $this - ->getMockBuilder('\Symfony\Component\DependencyInjection\Definition') - ->setMethods($methods) - ->getMock(); - } - public function testCompilerLogging() { $pass = $this->createAbstractCompilerPassMock(); @@ -165,4 +100,69 @@ public function testSetDefinitionSharing() $m->invoke($p, $definition, true); } + + /** + * @param string[] $methods + * + * @return \PHPUnit_Framework_MockObject_MockObject|AbstractCompilerPass + */ + private function createAbstractCompilerPassMock(array $methods = array()) + { + return $this + ->getMockBuilder('\Liip\ImagineBundle\DependencyInjection\Compiler\AbstractCompilerPass') + ->setMethods($methods) + ->getMock(); + } + + /** + * @param string[] $methods + * + * @return \PHPUnit_Framework_MockObject_MockObject|ContainerBuilder + */ + private function createContainerBuilderMock(array $methods = array()) + { + return $this + ->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerBuilder') + ->setMethods($methods) + ->getMock(); + } + + /** + * @param string[] $methods + * + * @return \PHPUnit_Framework_MockObject_MockObject|Compiler + */ + private function createCompilerMock(array $methods = array()) + { + return $this + ->getMockBuilder('\Symfony\Component\DependencyInjection\Compiler\Compiler') + ->setMethods($methods) + ->getMock(); + } + + /** + * @param string[] $methods + * + * @return \PHPUnit_Framework_MockObject_MockObject|Compiler + */ + private function createLoggingFormatterMock(array $methods = array()) + { + return $this + ->getMockBuilder('\Symfony\Component\DependencyInjection\Compiler\LoggingFormatter') + ->setMethods($methods) + ->getMock(); + } + + /** + * @param string[] $methods + * + * @return \PHPUnit_Framework_MockObject_MockObject|Definition + */ + private function createDefinitionMock(array $methods = array()) + { + return $this + ->getMockBuilder('\Symfony\Component\DependencyInjection\Definition') + ->setMethods($methods) + ->getMock(); + } } diff --git a/Tests/DependencyInjection/Compiler/MetadataReaderCompilerPassTest.php b/Tests/DependencyInjection/Compiler/MetadataReaderCompilerPassTest.php index 44a4c6028..0eb66c112 100644 --- a/Tests/DependencyInjection/Compiler/MetadataReaderCompilerPassTest.php +++ b/Tests/DependencyInjection/Compiler/MetadataReaderCompilerPassTest.php @@ -19,6 +19,34 @@ */ class MetadataReaderCompilerPassTest extends \PHPUnit_Framework_TestCase { + public function testProcessWithoutExtExifAddsDefaultReader() + { + list($metadataParameter, $metadataExifClass, $metadataDefaultClass) = static::getReaderParamAndDefaultAndExifValues(); + + $container = new ContainerBuilder(); + $container->setParameter($metadataParameter, $metadataExifClass); + + $pass = $this->getMetadataReaderCompilerPass(false); + $this->assertEquals($metadataExifClass, $container->getParameter($metadataParameter)); + + $pass->process($container); + $this->assertEquals($metadataDefaultClass, $container->getParameter($metadataParameter)); + } + + public function testProcessWithExtExifKeepsExifReader() + { + list($metadataParameter, $metadataExifClass) = static::getReaderParamAndDefaultAndExifValues(); + + $container = new ContainerBuilder(); + $container->setParameter($metadataParameter, $metadataExifClass); + + $pass = static::getMetadataReaderCompilerPass(true); + $this->assertEquals($metadataExifClass, $container->getParameter($metadataParameter)); + + $pass->process($container); + $this->assertEquals($metadataExifClass, $container->getParameter($metadataParameter)); + } + /** * @param \ReflectionClass $r * @param string $p @@ -65,32 +93,4 @@ private function getMetadataReaderCompilerPass($return) return $mock; } - - public function testProcessWithoutExtExifAddsDefaultReader() - { - list($metadataParameter, $metadataExifClass, $metadataDefaultClass) = static::getReaderParamAndDefaultAndExifValues(); - - $container = new ContainerBuilder(); - $container->setParameter($metadataParameter, $metadataExifClass); - - $pass = $this->getMetadataReaderCompilerPass(false); - $this->assertEquals($metadataExifClass, $container->getParameter($metadataParameter)); - - $pass->process($container); - $this->assertEquals($metadataDefaultClass, $container->getParameter($metadataParameter)); - } - - public function testProcessWithExtExifKeepsExifReader() - { - list($metadataParameter, $metadataExifClass) = static::getReaderParamAndDefaultAndExifValues(); - - $container = new ContainerBuilder(); - $container->setParameter($metadataParameter, $metadataExifClass); - - $pass = static::getMetadataReaderCompilerPass(true); - $this->assertEquals($metadataExifClass, $container->getParameter($metadataParameter)); - - $pass->process($container); - $this->assertEquals($metadataExifClass, $container->getParameter($metadataParameter)); - } } diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index 497a7d1e0..6c1b15f35 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -58,7 +58,6 @@ public function testInjectLoaderFactoryConfig() ), ), ), - )) ); @@ -94,7 +93,6 @@ public function testAllowToUseLoaderFactorySeveralTimes() ), ), ), - )) ); @@ -225,7 +223,6 @@ public function testShouldNotOverwriteDefaultLoaderIfDefined() ), ), ), - )) ); @@ -253,7 +250,6 @@ public function testInjectResolverFactoryConfig() ), ), ), - )) ); @@ -289,7 +285,6 @@ public function testAllowToUseResolverFactorySeveralTimes() ), ), ), - )) ); @@ -383,7 +378,6 @@ public function testShouldNotOverwriteDefaultResolverIfDefined() ), ), ), - )) ); diff --git a/Tests/DependencyInjection/LiipImagineExtensionTest.php b/Tests/DependencyInjection/LiipImagineExtensionTest.php index f12b8cc2c..f67479073 100644 --- a/Tests/DependencyInjection/LiipImagineExtensionTest.php +++ b/Tests/DependencyInjection/LiipImagineExtensionTest.php @@ -33,6 +33,11 @@ class LiipImagineExtensionTest extends AbstractTest */ protected $containerBuilder; + protected function tearDown() + { + unset($this->containerBuilder); + } + /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException */ @@ -89,6 +94,9 @@ public static function provideFactoryData() /** * @dataProvider provideFactoryData + * + * @param mixed $service + * @param mixed $factory */ public function testFactoriesConfiguration($service, $factory) { @@ -106,6 +114,9 @@ public function testFactoriesConfiguration($service, $factory) * @group legacy * * @dataProvider provideFactoryData + * + * @param mixed $service + * @param mixed $factory */ public function testFactoriesConfigurationLegacy($service, $factory) { @@ -216,9 +227,4 @@ private function assertDICConstructorArguments(Definition $definition, array $ar { $this->assertEquals($arguments, $definition->getArguments(), "Expected and actual DIC Service constructor arguments of definition '".$definition->getClass()."' don't match."); } - - protected function tearDown() - { - unset($this->containerBuilder); - } } diff --git a/Tests/Form/Type/ImageTypeTest.php b/Tests/Form/Type/ImageTypeTest.php index ceb16145a..7195d641d 100644 --- a/Tests/Form/Type/ImageTypeTest.php +++ b/Tests/Form/Type/ImageTypeTest.php @@ -12,8 +12,8 @@ namespace Liip\ImagineBundle\Tests\Form\Type; use Liip\ImagineBundle\Form\Type\ImageType; -use Liip\ImagineBundle\Utility\Framework\SymfonyFramework; use Liip\ImagineBundle\Tests\AbstractTest; +use Liip\ImagineBundle\Utility\Framework\SymfonyFramework; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; diff --git a/Tests/Functional/Binary/Loader/ChainLoaderTest.php b/Tests/Functional/Binary/Loader/ChainLoaderTest.php index 2e2813a6f..667c2217a 100644 --- a/Tests/Functional/Binary/Loader/ChainLoaderTest.php +++ b/Tests/Functional/Binary/Loader/ChainLoaderTest.php @@ -19,16 +19,6 @@ */ class ChainLoaderTest extends AbstractWebTestCase { - /** - * @param string $name - * - * @return ChainLoader|object - */ - private function getLoader($name) - { - return $this->getService(sprintf('liip_imagine.binary.loader.%s', $name)); - } - public function testFind() { static::createClient(); @@ -39,4 +29,14 @@ public function testFind() $this->assertNotNull($loader->find($file)); } } + + /** + * @param string $name + * + * @return ChainLoader|object + */ + private function getLoader($name) + { + return $this->getService(sprintf('liip_imagine.binary.loader.%s', $name)); + } } diff --git a/Tests/Functional/Binary/Loader/FileSystemLoaderTest.php b/Tests/Functional/Binary/Loader/FileSystemLoaderTest.php index cec47b9bc..d133ccd72 100644 --- a/Tests/Functional/Binary/Loader/FileSystemLoaderTest.php +++ b/Tests/Functional/Binary/Loader/FileSystemLoaderTest.php @@ -19,16 +19,6 @@ */ class FileSystemLoaderTest extends AbstractWebTestCase { - /** - * @param string $name - * - * @return FileSystemLoader|object - */ - private function getLoader($name) - { - return $this->getService(sprintf('liip_imagine.binary.loader.%s', $name)); - } - public function testMultipleLoadersHaveDifferentLocatorInstances() { static::createClient(); @@ -49,4 +39,14 @@ public function testMultipleLoadersHaveDifferentLocatorInstances() $this->assertStringEndsWith('root-01', $fooRoots[0]); $this->assertStringEndsWith('root-02', $barRoots[0]); } + + /** + * @param string $name + * + * @return FileSystemLoader|object + */ + private function getLoader($name) + { + return $this->getService(sprintf('liip_imagine.binary.loader.%s', $name)); + } } diff --git a/Tests/Functional/Binary/Locator/FileSystemLocatorTest.php b/Tests/Functional/Binary/Locator/FileSystemLocatorTest.php index 8ba038209..02d9c2653 100644 --- a/Tests/Functional/Binary/Locator/FileSystemLocatorTest.php +++ b/Tests/Functional/Binary/Locator/FileSystemLocatorTest.php @@ -20,16 +20,6 @@ */ class FileSystemLocatorTest extends AbstractWebTestCase { - /** - * @param string $name - * - * @return FileSystemLocator - */ - private function getFileSystemLoaderLocator($name) - { - return $this->getPrivateProperty($this->getService(sprintf('liip_imagine.binary.loader.%s', $name)), 'locator'); - } - public function testBundleResourcesOnAllLoader() { static::createClient(); @@ -71,6 +61,16 @@ public function testBundleResourcesOnBarLoader() $this->assertBarBundleResourcesExist($locator, true); } + /** + * @param string $name + * + * @return FileSystemLocator + */ + private function getFileSystemLoaderLocator($name) + { + return $this->getPrivateProperty($this->getService(sprintf('liip_imagine.binary.loader.%s', $name)), 'locator'); + } + /** * @param LocatorInterface $locator */ diff --git a/Tests/Imagine/Cache/CacheManagerTest.php b/Tests/Imagine/Cache/CacheManagerTest.php index 0e44aadd5..f18111a9f 100644 --- a/Tests/Imagine/Cache/CacheManagerTest.php +++ b/Tests/Imagine/Cache/CacheManagerTest.php @@ -25,16 +25,6 @@ */ class CacheManagerTest extends AbstractTest { - /** - * @return \PHPUnit_Framework_MockObject_MockObject|ResolverInterface - */ - private function createCacheManagerAwareResolverMock() - { - return $resolver = $this - ->getMockBuilder('\Liip\ImagineBundle\Tests\Fixtures\CacheManagerAwareResolver') - ->getMock(); - } - public function testAddCacheManagerAwareResolver() { $cacheManager = new CacheManager($this->createFilterConfigurationMock(), $this->createRouterInterfaceMock(), new Signer('secret'), $this->createEventDispatcherInterfaceMock()); @@ -204,6 +194,8 @@ public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBr /** * @dataProvider invalidPathProvider * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * + * @param mixed $path */ public function testResolveInvalidPath($path) { @@ -700,4 +692,14 @@ public function testShouldReturnUrlChangedInPostResolveEvent() $this->assertEquals('changed_url', $cacheManager->resolve('cats.jpg', 'thumbnail')); } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject|ResolverInterface + */ + private function createCacheManagerAwareResolverMock() + { + return $resolver = $this + ->getMockBuilder('\Liip\ImagineBundle\Tests\Fixtures\CacheManagerAwareResolver') + ->getMock(); + } } diff --git a/Tests/Imagine/Filter/FilterManagerTest.php b/Tests/Imagine/Filter/FilterManagerTest.php index ec1e31595..ced5e86dc 100644 --- a/Tests/Imagine/Filter/FilterManagerTest.php +++ b/Tests/Imagine/Filter/FilterManagerTest.php @@ -525,6 +525,7 @@ public function testMergeRuntimeConfigWithOneFromFilterConfigurationOnApplyFilte $filterManager->applyFilter($binary, 'thumbnail', $runtimeConfig) ); } + /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Could not find filter loader for "thumbnail" filter type @@ -982,6 +983,7 @@ public function testApplyPostProcessor() $this->assertInstanceOf('\Liip\ImagineBundle\Model\Binary', $filteredBinary); $this->assertEquals($expectedPostProcessedContent, $filteredBinary->getContent()); } + /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Post-processor "foo" could not be found diff --git a/Tests/Imagine/Filter/Loader/AutoRotateFilterLoaderTest.php b/Tests/Imagine/Filter/Loader/AutoRotateFilterLoaderTest.php index 8c0900c95..596f348c9 100644 --- a/Tests/Imagine/Filter/Loader/AutoRotateFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/AutoRotateFilterLoaderTest.php @@ -21,67 +21,6 @@ class AutoRotateFilterLoaderTest extends AbstractTest { private $orientationKey = 'exif.Orientation'; - /** - * Starts a test with expected results. - * - * @param $exifValue {String} The exif value to be returned by the metadata mock - * @param $expectCallRotateValue {null|number} The expected rotation value, null if no rotation is expected - * @param $expectCallFlip {Boolean} True if a horizontal flip is expected, false otherwise - */ - private function loadExif($exifValue, $expectCallRotateValue, $expectCallFlip) - { - $loader = new AutoRotateFilterLoader(); - - // Mocks the image and makes it use the fake meta data. - $image = $this->getImageInterfaceMock(); - - if (method_exists('\Imagine\Image\ImageInterface', 'metadata')) { - // Mocks the metadata and makes it return the expected exif value for the rotation. - // If $exifValue is null, it means the image doesn't contain any metadata. - $metaData = $this->getMetadataBagMock(); - - $metaData - ->expects($this->atLeastOnce()) - ->method('offsetGet') - ->willReturn($exifValue); - - if ($exifValue && $exifValue > '1' && $exifValue <= 8) { - $metaData - ->expects($this->once()) - ->method('offsetSet') - ->with($this->orientationKey, '1'); - } - - $image - ->expects($this->atLeastOnce()) - ->method('metadata') - ->willReturn($metaData); - } else { - $jpg = file_get_contents(__DIR__.'/../../../Fixtures/assets/pixel_1x1_orientation_at_0x30.jpg'); - // The byte with orientation is at offset 0x30 for this image - $jpg[0x30] = chr((int) $exifValue); - - $image - ->expects($this->once()) - ->method('get') - ->with('jpg') - ->will($this->returnValue($jpg)); - } - - // Checks that rotate is called with $expectCallRotateValue, or not called at all if $expectCallRotateValue is null. - $image - ->expects($expectCallRotateValue !== null ? $this->once() : $this->never()) - ->method('rotate') - ->with($expectCallRotateValue); - - // Checks that rotate is called if $expectCallFlip is true, not called if $expectCallFlip is false. - $image - ->expects($expectCallFlip ? $this->once() : $this->never()) - ->method('flipHorizontally'); - - $loader->load($image); - } - /* * Possible rotation values * 1: 0° @@ -181,4 +120,65 @@ public function testLoadExifNull() { $this->loadExif(null, null, false); } + + /** + * Starts a test with expected results. + * + * @param $exifValue {String} The exif value to be returned by the metadata mock + * @param $expectCallRotateValue {null|number} The expected rotation value, null if no rotation is expected + * @param $expectCallFlip {Boolean} True if a horizontal flip is expected, false otherwise + */ + private function loadExif($exifValue, $expectCallRotateValue, $expectCallFlip) + { + $loader = new AutoRotateFilterLoader(); + + // Mocks the image and makes it use the fake meta data. + $image = $this->getImageInterfaceMock(); + + if (method_exists('\Imagine\Image\ImageInterface', 'metadata')) { + // Mocks the metadata and makes it return the expected exif value for the rotation. + // If $exifValue is null, it means the image doesn't contain any metadata. + $metaData = $this->getMetadataBagMock(); + + $metaData + ->expects($this->atLeastOnce()) + ->method('offsetGet') + ->willReturn($exifValue); + + if ($exifValue && $exifValue > '1' && $exifValue <= 8) { + $metaData + ->expects($this->once()) + ->method('offsetSet') + ->with($this->orientationKey, '1'); + } + + $image + ->expects($this->atLeastOnce()) + ->method('metadata') + ->willReturn($metaData); + } else { + $jpg = file_get_contents(__DIR__.'/../../../Fixtures/assets/pixel_1x1_orientation_at_0x30.jpg'); + // The byte with orientation is at offset 0x30 for this image + $jpg[0x30] = chr((int) $exifValue); + + $image + ->expects($this->once()) + ->method('get') + ->with('jpg') + ->will($this->returnValue($jpg)); + } + + // Checks that rotate is called with $expectCallRotateValue, or not called at all if $expectCallRotateValue is null. + $image + ->expects(null !== $expectCallRotateValue ? $this->once() : $this->never()) + ->method('rotate') + ->with($expectCallRotateValue); + + // Checks that rotate is called if $expectCallFlip is true, not called if $expectCallFlip is false. + $image + ->expects($expectCallFlip ? $this->once() : $this->never()) + ->method('flipHorizontally'); + + $loader->load($image); + } } diff --git a/Tests/Imagine/Filter/Loader/DownscaleFilterLoaderTest.php b/Tests/Imagine/Filter/Loader/DownscaleFilterLoaderTest.php index 99158d03d..e571b295c 100644 --- a/Tests/Imagine/Filter/Loader/DownscaleFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/DownscaleFilterLoaderTest.php @@ -46,6 +46,8 @@ public function testItWorksSomeHow() /** * @depends testItWorksSomeHow + * + * @param mixed $sizes */ public function testDontScaleUp($sizes) { @@ -56,6 +58,8 @@ public function testDontScaleUp($sizes) /** * @depends testItWorksSomeHow + * + * @param mixed $sizes */ public function testFitBoundingBox($sizes) { diff --git a/Tests/Imagine/Filter/Loader/ResampleFilterLoaderTest.php b/Tests/Imagine/Filter/Loader/ResampleFilterLoaderTest.php index 82974b85a..a48e53efb 100644 --- a/Tests/Imagine/Filter/Loader/ResampleFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/ResampleFilterLoaderTest.php @@ -11,9 +11,9 @@ namespace Liip\ImagineBundle\Tests\Filter; -use Imagine\Imagick\Imagine as ImagickImagine; use Imagine\Gmagick\Imagine as GmagickImagine; use Imagine\Image\ImagineInterface; +use Imagine\Imagick\Imagine as ImagickImagine; use Liip\ImagineBundle\Imagine\Filter\Loader\ResampleFilterLoader; use Liip\ImagineBundle\Tests\AbstractTest; @@ -213,6 +213,8 @@ private static function getSupportedDriver() } /** + * @param mixed $driver + * * @return ImagickImagine|GmagickImagine */ private function getImagineInstance($driver) diff --git a/Tests/Imagine/Filter/Loader/ScaleFilterLoaderTest.php b/Tests/Imagine/Filter/Loader/ScaleFilterLoaderTest.php index 7164279e4..735c23e69 100644 --- a/Tests/Imagine/Filter/Loader/ScaleFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/ScaleFilterLoaderTest.php @@ -43,36 +43,6 @@ class ScaleFilterLoaderTest extends AbstractTest */ const UPSCALE_DUMMY_IMAGE_HEIGHT = 400; - protected function getUpscaleMockImage() - { - $mockImageSize = new Box( - self::UPSCALE_DUMMY_IMAGE_WIDTH, - self::UPSCALE_DUMMY_IMAGE_HEIGHT - ); - $mockImage = parent::getImageInterfaceMock(); - $mockImage->method('getSize')->willReturn(new Box( - self::UPSCALE_DUMMY_IMAGE_WIDTH, - self::UPSCALE_DUMMY_IMAGE_HEIGHT - )); - - return $mockImage; - } - - protected function getImageInterfaceMock() - { - $mockImageSize = new Box( - self::DUMMY_IMAGE_WIDTH, - self::DUMMY_IMAGE_HEIGHT - ); - $mockImage = parent::getImageInterfaceMock(); - $mockImage->method('getSize')->willReturn(new Box( - self::DUMMY_IMAGE_WIDTH, - self::DUMMY_IMAGE_HEIGHT - )); - - return $mockImage; - } - /** * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\ScaleFilterLoader::load */ @@ -96,6 +66,7 @@ public function testItShouldPreserveRatio() /** * @param int[] $dimension * @param Box $expected + * @param mixed $dimensions * * @covers \Liip\ImagineBundle\Imagine\Filter\Loader\ScaleFilterLoader::load * @@ -143,6 +114,9 @@ public function dimensionsDataProvider() /** * @dataProvider minScaleDataProvider + * + * @param mixed $dimensions + * @param mixed $expected */ public function testShouldScale($dimensions, $expected) { @@ -173,6 +147,9 @@ public function minScaleDataProvider() /** * @dataProvider minNotScaleDataProvider + * + * @param mixed $dimensions + * @param mixed $expected */ public function testShouldNotScale($dimensions, $expected) { @@ -200,4 +177,34 @@ public function minNotScaleDataProvider() array(array(600, 400), new Box(600, 400)), ); } + + protected function getUpscaleMockImage() + { + $mockImageSize = new Box( + self::UPSCALE_DUMMY_IMAGE_WIDTH, + self::UPSCALE_DUMMY_IMAGE_HEIGHT + ); + $mockImage = parent::getImageInterfaceMock(); + $mockImage->method('getSize')->willReturn(new Box( + self::UPSCALE_DUMMY_IMAGE_WIDTH, + self::UPSCALE_DUMMY_IMAGE_HEIGHT + )); + + return $mockImage; + } + + protected function getImageInterfaceMock() + { + $mockImageSize = new Box( + self::DUMMY_IMAGE_WIDTH, + self::DUMMY_IMAGE_HEIGHT + ); + $mockImage = parent::getImageInterfaceMock(); + $mockImage->method('getSize')->willReturn(new Box( + self::DUMMY_IMAGE_WIDTH, + self::DUMMY_IMAGE_HEIGHT + )); + + return $mockImage; + } } diff --git a/Tests/Imagine/Filter/PostProcessor/AbstractPostProcessorTest.php b/Tests/Imagine/Filter/PostProcessor/AbstractPostProcessorTest.php index 997c542f8..f3212ce51 100644 --- a/Tests/Imagine/Filter/PostProcessor/AbstractPostProcessorTest.php +++ b/Tests/Imagine/Filter/PostProcessor/AbstractPostProcessorTest.php @@ -78,18 +78,18 @@ public static function provideCreateProcessBuilderData() return $executable instanceof \SplFileInfo ? $executable->getRealPath() : null; }; - $getChars = function($onlyAlpha = true) { + $getChars = function ($onlyAlpha = true) { $chars = ''; - for ($i = 0; $i < mt_rand(1, 80); $i++) { + for ($i = 0; $i < mt_rand(1, 80); ++$i) { $chars .= chr($onlyAlpha ? mt_rand(97, 122) : mt_rand(35, 127)); } return strtolower($chars); }; - $getEnvVars = function() use ($getChars) { + $getEnvVars = function () use ($getChars) { $environment = array(); - for ($i = 0; $i < mt_rand(0, 20); $i++) { + for ($i = 0; $i < mt_rand(0, 20); ++$i) { $environment[strtoupper($getChars())] = $getChars(false); } @@ -104,11 +104,11 @@ public static function provideCreateProcessBuilderData() foreach (array_splice($directories, 0, 20) as $d) { $returns[] = array($d->getRealPath(), $getBin($d), (float) sprintf('%d.%d', mt_rand(0, 300), mt_rand(0, 99)), - $getChars(), $getEnvVars(), mt_rand(0, 1) === 0 ? array('bypass_shell' => true) : array()); + $getChars(), $getEnvVars(), 0 === mt_rand(0, 1) ? array('bypass_shell' => true) : array(), ); } return array_filter($returns, function (array $d) { - return $d[1] !== null; + return null !== $d[1]; }); } @@ -164,6 +164,8 @@ public static function provideCreateProcessBuilderThrowsOnInvalidEnvVarsData() * * @expectedException \Liip\ImagineBundle\Exception\Imagine\Filter\PostProcessor\InvalidOptionException * @expectedExceptionMessage the "process:environment_variables" option must be an array of name => value pairs + * + * @param mixed $environmentVariables */ public function testCreateProcessBuilderThrowsOnInvalidEnvVars($environmentVariables) { @@ -173,6 +175,7 @@ public function testCreateProcessBuilderThrowsOnInvalidEnvVars($environmentVaria ), ), '/bin/foobar'); } + /** * @return array */ @@ -186,6 +189,8 @@ public static function provideCreateProcessBuilderThrowsOnInvalidOptionsData() * * @expectedException \Liip\ImagineBundle\Exception\Imagine\Filter\PostProcessor\InvalidOptionException * @expectedExceptionMessage the "process:options" option must be an array of options intended for the proc_open function call + * + * @param mixed $options */ public function testCreateProcessBuilderThrowsOnInvalidOptions($options) { @@ -196,19 +201,6 @@ public function testCreateProcessBuilderThrowsOnInvalidOptions($options) ), '/bin/foobar'); } - /** - * @param array $options - * @param string $executablePath - * - * @return ProcessBuilder - */ - private function callCreateProcessBuilder(array $options, $executablePath) - { - $m = $this->getProtectedReflectionMethodVisible($processor = $this->getPostProcessorInstance(), 'createProcessBuilder'); - - return $m->invokeArgs($processor, array($options, array($executablePath))); - } - public function testCreateProcessBuilderWithDefaultExecutable() { $executablePath = '/bin/foobar'; @@ -331,7 +323,7 @@ public function testIsSuccessfulProcess(array $validReturns, array $errorString, */ protected function getPostProcessorInstance(array $parameters = array()) { - if (count($parameters) === 0) { + if (0 === count($parameters)) { $parameters = array(static::getPostProcessAsStdInExecutable()); } @@ -340,4 +332,17 @@ protected function getPostProcessorInstance(array $parameters = array()) ->setConstructorArgs($parameters) ->getMockForAbstractClass(); } + + /** + * @param array $options + * @param string $executablePath + * + * @return ProcessBuilder + */ + private function callCreateProcessBuilder(array $options, $executablePath) + { + $m = $this->getProtectedReflectionMethodVisible($processor = $this->getPostProcessorInstance(), 'createProcessBuilder'); + + return $m->invokeArgs($processor, array($options, array($executablePath))); + } } diff --git a/Tests/Imagine/Filter/PostProcessor/AbstractPostProcessorTestCase.php b/Tests/Imagine/Filter/PostProcessor/AbstractPostProcessorTestCase.php index 92a3f0777..4c30e9e4c 100644 --- a/Tests/Imagine/Filter/PostProcessor/AbstractPostProcessorTestCase.php +++ b/Tests/Imagine/Filter/PostProcessor/AbstractPostProcessorTestCase.php @@ -16,13 +16,6 @@ abstract class AbstractPostProcessorTestCase extends AbstractTest { - /** - * @param array $parameters - * - * @return PostProcessorInterface - */ - abstract protected function getPostProcessorInstance(array $parameters = array()); - /** * @return string */ @@ -55,6 +48,13 @@ public static function getPostProcessAsStdInErrorExecutable() return realpath(__DIR__.'/../../../Fixtures/bin/post-process-as-stdin-error.bash'); } + /** + * @param array $parameters + * + * @return PostProcessorInterface + */ + abstract protected function getPostProcessorInstance(array $parameters = array()); + /** * @return \Liip\ImagineBundle\Binary\BinaryInterface|\PHPUnit_Framework_MockObject_MockObject */ diff --git a/Tests/Imagine/Filter/PostProcessor/JpegOptimPostProcessorTest.php b/Tests/Imagine/Filter/PostProcessor/JpegOptimPostProcessorTest.php index ede39e210..863d86839 100644 --- a/Tests/Imagine/Filter/PostProcessor/JpegOptimPostProcessorTest.php +++ b/Tests/Imagine/Filter/PostProcessor/JpegOptimPostProcessorTest.php @@ -21,7 +21,7 @@ */ class JpegOptimPostProcessorTest extends AbstractPostProcessorTestCase { - /** + /** * @group legacy * * @expectedDeprecation The %s::setMax() method was deprecated in %s and will be removed in %s. You must setup the class state via its __construct() method. You can still pass filter-specific options to the process() method to overwrite behavior. @@ -173,6 +173,7 @@ public function testProcess($content, array $options, $expected) * * @param array $options * @param string $expected + * @param mixed $content */ public function testProcessError($content, array $options, $expected) { diff --git a/Tests/Imagine/Filter/PostProcessor/MozJpegPostProcessorTest.php b/Tests/Imagine/Filter/PostProcessor/MozJpegPostProcessorTest.php index 1090211d8..bb9b0631e 100644 --- a/Tests/Imagine/Filter/PostProcessor/MozJpegPostProcessorTest.php +++ b/Tests/Imagine/Filter/PostProcessor/MozJpegPostProcessorTest.php @@ -110,6 +110,7 @@ public function testProcess($content, array $options, $expected) * * @param array $options * @param string $expected + * @param mixed $content */ public function testProcessError($content, array $options, $expected) { diff --git a/Tests/Imagine/Filter/PostProcessor/OptiPngPostProcessorTest.php b/Tests/Imagine/Filter/PostProcessor/OptiPngPostProcessorTest.php index 681ea33cb..61ef1e13b 100644 --- a/Tests/Imagine/Filter/PostProcessor/OptiPngPostProcessorTest.php +++ b/Tests/Imagine/Filter/PostProcessor/OptiPngPostProcessorTest.php @@ -161,6 +161,7 @@ public function testProcess($content, array $options, $expected) * * @param array $options * @param string $expected + * @param mixed $content */ public function testProcessError($content, array $options, $expected) { diff --git a/Tests/Imagine/Filter/PostProcessor/PngquantPostProcessorTest.php b/Tests/Imagine/Filter/PostProcessor/PngquantPostProcessorTest.php index ab230923c..9398b14f0 100644 --- a/Tests/Imagine/Filter/PostProcessor/PngquantPostProcessorTest.php +++ b/Tests/Imagine/Filter/PostProcessor/PngquantPostProcessorTest.php @@ -174,6 +174,7 @@ public function testProcess($content, array $options, $expected) * * @param array $options * @param string $expected + * @param mixed $content */ public function testProcessError($content, array $options, $expected) { diff --git a/Tests/Utility/OptionsResolver/OptionsResolverTest.php b/Tests/Utility/OptionsResolver/OptionsResolverTest.php index 87acb21bf..e497ddd32 100644 --- a/Tests/Utility/OptionsResolver/OptionsResolverTest.php +++ b/Tests/Utility/OptionsResolver/OptionsResolverTest.php @@ -118,7 +118,7 @@ private static function setupOptionsResolver() $resolver->setAllowedTypes('bar', array('integer')); $resolver->setAllowedTypes('baz', array('string')); $resolver->setNormalizer('foo', function (Options $options, $value) { - return $value === 'c' ? 'z' : $value; + return 'c' === $value ? 'z' : $value; }); return $resolver;