diff --git a/.travis.yml b/.travis.yml index 677e4b5..d4c7116 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,41 +5,32 @@ sudo: false dist: trusty php: - - 5.5 - - 7.0 - 7.1 - 7.2 + - 7.3 + - 7.4 - nightly env: - - SYMFONY_VERSION="2.7.*" - - SYMFONY_VERSION="2.8.*" - - SYMFONY_VERSION="3.4.*" - - SYMFONY_VERSION="4.0.*" + - SYMFONY_VERSION="4.4.*" + - SYMFONY_VERSION="5.0.*" matrix: fast_finish: true exclude: - - php: 5.5 - env: SYMFONY_VERSION="4.0.*" - - php: 5.5 - env: SYMFONY_VERSION="dev-master" - - php: 7.0 - env: SYMFONY_VERSION="4.0.*" - - php: 7.0 - env: SYMFONY_VERSION="dev-master" + - php: 7.1 + env: SYMFONY_VERSION="5.0.*" allow_failures: - php: nightly before_script: - composer require symfony/symfony:${SYMFONY_VERSION} --prefer-dist --no-interaction --no-progress - mkdir -p build/logs - - if [ "${TRAVIS_PHP_VERSION}" == '7.1' ] && [ "${SYMFONY_VERSION}" == '3.4.*' ]; then composer require doctrine/orm doctrine/doctrine-bundle doctrine/mongodb-odm-bundle alcaeus/mongo-php-adapter --ignore-platform-reqs --no-interaction --no-progress; fi; script: - - if [ "${TRAVIS_PHP_VERSION}" != '7.1' ] || [ "${SYMFONY_VERSION}" != '3.4.*' ]; then vendor/bin/phpunit -v; fi; - - if [ "${TRAVIS_PHP_VERSION}" == '7.1' ] && [ "${SYMFONY_VERSION}" == '3.4.*' ]; then vendor/bin/phpunit -v --coverage-clover build/logs/clover.xml; fi; - - if [ "${TRAVIS_PHP_VERSION}" == '7.1' ] && [ "${SYMFONY_VERSION}" == '3.4.*' ]; then travis_retry wget -q https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar && travis_retry php coveralls.phar -v; fi; + - if [ "${TRAVIS_PHP_VERSION}" != '7.1' ] || [ "${SYMFONY_VERSION}" != '4.4.*' ]; then vendor/bin/phpunit -v; fi; + - if [ "${TRAVIS_PHP_VERSION}" == '7.1' ] && [ "${SYMFONY_VERSION}" == '4.4.*' ]; then vendor/bin/phpunit -v --coverage-clover build/logs/clover.xml; fi; + - if [ "${TRAVIS_PHP_VERSION}" == '7.1' ] && [ "${SYMFONY_VERSION}" == '4.4.*' ]; then travis_retry wget -q https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar && travis_retry php coveralls.phar -v; fi; notifications: email: diff --git a/composer.json b/composer.json index 9a825a3..361abce 100644 --- a/composer.json +++ b/composer.json @@ -18,16 +18,18 @@ } ], "require": { - "php": ">=5.5.9", - "symfony/symfony": "~2.7|~3.0|~4.0", + "php": ">=7.1.3", + "ext-gd": "*", + "ext-exif": "*", + "symfony/symfony": "4.4.*|5.0.*", "intervention/image": "^2.3", - "twig/twig": "^1.28|^2.0", + "twig/twig": "^2.0", "sybio/gif-frame-extractor": "^1.0", "sybio/gif-creator": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^4.0|^5.0", - "matthiasnoback/symfony-dependency-injection-test": "^1.0" + "phpunit/phpunit": "^7.0", + "matthiasnoback/symfony-dependency-injection-test": "^3.0|^4.0" }, "autoload": { "psr-4": { diff --git a/src/Controller/ImageController.php b/src/Controller/ImageController.php index 6609fcb..98e7fa1 100644 --- a/src/Controller/ImageController.php +++ b/src/Controller/ImageController.php @@ -11,38 +11,22 @@ use IngaLabs\Bundle\ImageBundle\Exception\ImageExceptionInterface; use IngaLabs\Bundle\ImageBundle\ImageManager; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** - * ImageController. - * * @author Antal Áron */ class ImageController { - /** - * @var ImageManager - */ private $imageManager; - /** - * Constructor. - * - * @param ImageManager $imageManager - */ public function __construct(ImageManager $imageManager) { $this->imageManager = $imageManager; } - /** - * ShowAction. - * - * The main controller. - * - * @return Response - */ - public function showAction($hash, $size, $aspect) + public function showAction(string $hash, int $size, int $aspect): Response { try { $image = $this->imageManager->getImageByHash($hash); diff --git a/src/DependencyInjection/Compiler/ConfigPass.php b/src/DependencyInjection/Compiler/ConfigPass.php index 3ee97c7..b41c6c2 100644 --- a/src/DependencyInjection/Compiler/ConfigPass.php +++ b/src/DependencyInjection/Compiler/ConfigPass.php @@ -29,16 +29,6 @@ public function process(ContainerBuilder $container) return; } - if ($container->hasParameter('ingalabs_image.backend_type_orm')) { - $doctrine = 'doctrine'; - } elseif ($container->hasParameter('ingalabs_image.backend_type_mongodb')) { - $doctrine = 'doctrine_mongodb'; - } else { - throw new \RuntimeException( - 'Either parameter "ingalabs_image.backend_type_orm" or '. - '"ingalabs_image.backend_type_mongodb" should be set.'); - } - $config = []; if ($container->hasParameter('ingalabs_image.config')) { $config = $container->getParameter('ingalabs_image.config'); @@ -46,7 +36,7 @@ public function process(ContainerBuilder $container) $container ->findDefinition('ingalabs_image.image_manager') - ->replaceArgument(0, new Reference($doctrine, ContainerInterface::NULL_ON_INVALID_REFERENCE)) + ->replaceArgument(0, new Reference('doctrine', ContainerInterface::NULL_ON_INVALID_REFERENCE)) ->replaceArgument(1, $config); $container diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 9ae1f0f..ff2e12a 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -13,15 +13,10 @@ use Symfony\Component\Config\Definition\ConfigurationInterface; /** - * Configuration. - * * @author Antal Áron */ class Configuration implements ConfigurationInterface { - /** - * {@inheritdoc} - */ public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); @@ -29,19 +24,12 @@ public function getConfigTreeBuilder() $rootNode ->children() - ->enumNode('doctrine_driver') - ->values(['orm', 'mongodb']) - ->defaultValue('orm') - ->end() ->scalarNode('image_dir') ->defaultValue('%kernel.root_dir%/../web') ->end() ->scalarNode('prefix') ->defaultValue('/assets/images') ->end() - ->scalarNode('driver') - ->defaultValue('gd') - ->end() ->booleanNode('mock_image') ->defaultValue('%kernel.debug%') ->end() diff --git a/src/DependencyInjection/IngaLabsImageExtension.php b/src/DependencyInjection/IngaLabsImageExtension.php index 68bae16..4209000 100644 --- a/src/DependencyInjection/IngaLabsImageExtension.php +++ b/src/DependencyInjection/IngaLabsImageExtension.php @@ -15,30 +15,21 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; /** - * IngaLabsImageExtension. - * * @author Antal Áron */ class IngaLabsImageExtension extends Extension { - /** - * {@inheritdoc} - */ public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); - $container->setParameter('ingalabs_image.backend_type_'.$config['doctrine_driver'], true); $container->setParameter('ingalabs_image.config', $config); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); } - /** - * {@inheritdoc} - */ public function getAlias() { return 'ingalabs_image'; diff --git a/src/Exception/IOException.php b/src/Exception/IOException.php index 9eddd8c..adaebc5 100644 --- a/src/Exception/IOException.php +++ b/src/Exception/IOException.php @@ -10,8 +10,6 @@ namespace IngaLabs\Bundle\ImageBundle\Exception; /** - * IOException. - * * @author Antal Áron */ class IOException extends \RuntimeException implements ImageExceptionInterface diff --git a/src/Exception/ImageExceptionInterface.php b/src/Exception/ImageExceptionInterface.php index 1069161..024af71 100644 --- a/src/Exception/ImageExceptionInterface.php +++ b/src/Exception/ImageExceptionInterface.php @@ -10,8 +10,6 @@ namespace IngaLabs\Bundle\ImageBundle\Exception; /** - * ImageExceptionInterface. - * * @author Antal Áron */ interface ImageExceptionInterface diff --git a/src/Exception/ImageNotFoundException.php b/src/Exception/ImageNotFoundException.php index bdec4bf..9a538b1 100644 --- a/src/Exception/ImageNotFoundException.php +++ b/src/Exception/ImageNotFoundException.php @@ -10,8 +10,6 @@ namespace IngaLabs\Bundle\ImageBundle\Exception; /** - * ImageNotFoundException. - * * @author Antal Áron */ class ImageNotFoundException extends \RuntimeException implements ImageExceptionInterface diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index b597eae..8d8cbe5 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -10,8 +10,6 @@ namespace IngaLabs\Bundle\ImageBundle\Exception; /** - * InvalidArgumentException. - * * @author Antal Áron */ class InvalidArgumentException extends \InvalidArgumentException implements ImageExceptionInterface diff --git a/src/Exception/LoaderException.php b/src/Exception/LoaderException.php index 70ab4f0..210c8c6 100644 --- a/src/Exception/LoaderException.php +++ b/src/Exception/LoaderException.php @@ -10,8 +10,6 @@ namespace IngaLabs\Bundle\ImageBundle\Exception; /** - * LoaderException. - * * @author Antal Áron */ class LoaderException extends \RuntimeException implements ImageExceptionInterface diff --git a/src/Helper/GifImage.php b/src/Helper/GifImage.php index 212e495..cea5c89 100644 --- a/src/Helper/GifImage.php +++ b/src/Helper/GifImage.php @@ -10,67 +10,37 @@ namespace IngaLabs\Bundle\ImageBundle\Helper; /** - * GifImage. - * * @author Antal Áron */ class GifImage { const MIME_TYPE = 'image/gif'; - /** - * @var string - */ private $content; - /** - * Constructor. - * - * @param string $content - */ - public function __construct($content = '') + public function __construct(string $content = '') { $this->content = $content; } - /** - * Set content. - * - * @param string $content - */ - public function setContent($content) + public function setContent(string $content): self { $this->content = $content; return $this; } - /** - * Get content. - * - * @return string - */ - public function getContent() + public function getContent(): string { return $this->content; } - /** - * Get mime. - * - * @return string - */ - public function mime() + public function mime(): string { return static::MIME_TYPE; } - /** - * String conversion. - * - * @return string - */ - public function __toString() + public function __toString(): string { return $this->getContent(); } diff --git a/src/ImageManager.php b/src/ImageManager.php index 7360d03..cb7f0f5 100644 --- a/src/ImageManager.php +++ b/src/ImageManager.php @@ -28,22 +28,13 @@ use Symfony\Component\HttpFoundation\Response; /** - * ImageManager. - * * @author Antal Áron */ class ImageManager { const DEFAULT_QUALITY = 90; - /** - * @var ManagerRegistry - */ private $managerRegistry; - - /** - * @var array - */ private $options = [ 'prefix' => '/assets/images', 'driver' => 'gd', @@ -51,33 +42,12 @@ class ImageManager 'mock_image' => false, 'file_levels' => '2:8', ]; - - /** - * @var null|Aspect[] - */ private $aspects; - - /** - * @var null|Size[] - */ private $sizes; - - /** - * @var Filesystem - */ private $filesystem; - - /** - * @var InventionManager - */ private $imageManager; /** - * Constructor. - * - * @param ManagerRegistry $managerRegistry - * @param array $options - * * @throws InvalidArgumentException */ public function __construct(ManagerRegistry $managerRegistry, array $options = []) @@ -94,17 +64,7 @@ public function __construct(ManagerRegistry $managerRegistry, array $options = [ $this->filesystem = new Filesystem(); } - /** - * Get URL for image. - * - * @param Image $image - * @param string $size - * @param string $aspect - * @param bool $showLastModifiedAt - * - * @return string - */ - public function getUrlFor(Image $image, $size = 'or', $aspect = 'or', $showLastModifiedAt = false) + public function getUrlFor(Image $image, string $size = 'or', string $aspect = 'or', bool $showLastModifiedAt = false): string { $dn = $this->getDirectoryAndNameFor($image, $size, $aspect); @@ -120,16 +80,7 @@ public function getUrlFor(Image $image, $size = 'or', $aspect = 'or', $showLastM return sprintf('%s/%s', $dn['directory'], $dn['name']); } - /** - * Get directory and name for image. - * - * @param Image $image - * @param string $size - * @param string $aspect - * - * @return array With key direcotry and name - */ - private function getDirectoryAndNameFor(Image $image, $size = 'or', $aspect = 'or') + private function getDirectoryAndNameFor(Image $image, string $size = 'or', string $aspect = 'or'): array { $name = $image->getHash(); @@ -154,13 +105,9 @@ private function getDirectoryAndNameFor(Image $image, $size = 'or', $aspect = 'o } /** - * Create response. - * * @param InventionImage|GifImage|string $image - * - * @return Response */ - public function createResponse($image) + public function createResponse($image): Response { if ($image instanceof InventionImage || $image instanceof GifImage) { $response = new Response($image, Response::HTTP_OK, [ @@ -174,33 +121,19 @@ public function createResponse($image) } /** - * Main entrypoint. - * - * @param Image $image - * @param string $size - * @param string $aspect - * - * @return InventionImage|GifImage|string - * * @throws InvalidArgumentException * @throws ImageNotFoundException + * + * @return InventionImage|GifImage|string */ - public function generate(Image $image, $size, $aspect) + public function generate(Image $image, string $size, string $aspect) { - if (!array_key_exists($aspect, $this->getAspects())) { - throw new InvalidArgumentException(sprintf( - 'Invalid aspect. "%s" given. Valid values: %s.', - $aspect, - implode(', ', array_keys($this->getAspects())) - )); + if (!\array_key_exists($aspect, $this->getAspects())) { + throw new InvalidArgumentException(sprintf('Invalid aspect. "%s" given. Valid values: %s.', $aspect, implode(', ', array_keys($this->getAspects())))); } - if (!array_key_exists($size, $this->getSizes())) { - throw new InvalidArgumentException(sprintf( - 'Invalid size. "%s" given. Valid values: %s.', - $size, - implode(', ', array_keys($this->getSizes())) - )); + if (!\array_key_exists($size, $this->getSizes())) { + throw new InvalidArgumentException(sprintf('Invalid size. "%s" given. Valid values: %s.', $size, implode(', ', array_keys($this->getSizes())))); } $originalFilename = $this->options['image_dir'].$this->getUrlFor($image); @@ -225,15 +158,7 @@ public function generate(Image $image, $size, $aspect) return $img instanceof InventionImage || $img instanceof GifImage ? $img : $newFilename; } - /** - * Handles an uploaded file. - * - * @param UploadedFile $file - * @param bool $flush - * - * @return Image - */ - public function handleUpload(UploadedFile $file, $flush = false) + public function handleUpload(UploadedFile $file, bool $flush = false): Image { $image = new Image(); @@ -276,15 +201,7 @@ public function handleUpload(UploadedFile $file, $flush = false) return $image; } - /** - * Handle an upload from server. - * - * @param File $file - * @param bool $flush - * - * @return Image - */ - public function handleCopy(File $file, $flush = false) + public function handleCopy(File $file, bool $flush = false): Image { $image = new Image(); @@ -330,15 +247,7 @@ public function handleCopy(File $file, $flush = false) return $image; } - /** - * Clones an image. - * - * @param Image $originalImage - * @param bool $flush - * - * @return Image - */ - public function cloneImage(Image $originalImage, $flush = false) + public function cloneImage(Image $originalImage, bool $flush = false): Image { $image = clone $originalImage; @@ -360,19 +269,9 @@ public function cloneImage(Image $originalImage, $flush = false) } /** - * Resize image. - * - * @param InventionImage $image - * @param Image $originalImage - * @param string $originalFilename - * @param string $newFilename - * @param string $size - * @param string $aspectString - * @param bool $isMock - * * @return InventionImage|GifImage|string */ - private function resize(InventionImage $image, Image $originalImage, $originalFilename, $newFilename, $size, $aspectString, $isMock = false) + private function resize(InventionImage $image, Image $originalImage, string $originalFilename, string $newFilename, string $size, string $aspectString, bool $isMock = false) { $origWidth = $image->getWidth(); $origHeight = $image->getHeight(); @@ -451,20 +350,7 @@ private function resize(InventionImage $image, Image $originalImage, $originalFi return $newFilename; } - /** - * Crom an image. - * - * @param Image $image - * @param int $x - * @param int $y - * @param int $width - * @param int $height - * @param bool $greyscale - * @param bool $flush - * - * @return string - */ - public function cropImage(Image $image, $x, $y, $width, $height, $greyscale = false, $flush = false) + public function cropImage(Image $image, int $x, int $y, int $width, int $height, bool $greyscale = false, bool $flush = false): string { $originalFilename = $this->options['image_dir'].$this->getUrlFor($image); @@ -529,19 +415,11 @@ public function cropImage(Image $image, $x, $y, $width, $height, $greyscale = fa } /** - * Rotate image. - * - * @param Image $image - * @param string $direction left or right - * @param bool $flush - * - * @return string - * * @throws InvalidArgumentException */ - public function rotate(Image $image, $direction = 'right', $flush = false) + public function rotate(Image $image, string $direction = 'right', bool $flush = false): sting { - if (!in_array($direction, ['left', 'right'], true)) { + if (!\in_array($direction, ['left', 'right'], true)) { throw new InvalidArgumentException(sprintf('Argument 2 of %s has to be either left or right. "%s" given.', __METHOD__, $direction)); } @@ -603,16 +481,7 @@ public function rotate(Image $image, $direction = 'right', $flush = false) return $originalFilename; } - /** - * Delete an image. - * - * @param Image $image - * @param bool $keepOriginal - * @param bool $purge - * - * @return $this - */ - public function delete(Image $image, $keepOriginal = false, $purge = false) + public function delete(Image $image, bool $keepOriginal = false, bool $purge = false): self { // delete files foreach ($this->getSizes() as $size => $sizeVal) { @@ -637,14 +506,7 @@ public function delete(Image $image, $keepOriginal = false, $purge = false) return $this; } - /** - * Get image by hash. - * - * @param string $hash - * - * @return Image|null - */ - public function getImageByHash($hash) + public function getImageByHash(string $hash): ?Image { $image = $this->managerRegistry->getRepository(Image::class)->findOneByHash($hash); @@ -656,8 +518,6 @@ public function getImageByHash($hash) } /** - * Lazy loads aspects. - * * @return Aspect[] */ private function getAspects() @@ -675,8 +535,6 @@ private function getAspects() } /** - * Lazy loads sizes. - * * @return Size[] */ private function getSizes() diff --git a/src/IngaLabsImageBundle.php b/src/IngaLabsImageBundle.php index 0eb35a9..96a0162 100644 --- a/src/IngaLabsImageBundle.php +++ b/src/IngaLabsImageBundle.php @@ -10,7 +10,6 @@ namespace IngaLabs\Bundle\ImageBundle; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass; -use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass; use Doctrine\ORM\Version; use IngaLabs\Bundle\ImageBundle\DependencyInjection\Compiler\ConfigPass; use IngaLabs\Bundle\ImageBundle\DependencyInjection\IngaLabsImageExtension; @@ -18,15 +17,10 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; /** - * IngaLabsImageBundle. - * * @author Antal Áron */ class IngaLabsImageBundle extends Bundle { - /** - * {@inheritdoc} - */ public function build(ContainerBuilder $container) { parent::build($container); @@ -49,22 +43,9 @@ public function build(ContainerBuilder $container) )); } - if (class_exists(DoctrineMongoDBMappingsPass::class)) { - $container->addCompilerPass( - DoctrineMongoDBMappingsPass::createYamlMappingDriver( - $mappings, - [], - 'ingalabs_image.backend_type_mongodb', - $aliases - )); - } - $container->addCompilerPass(new ConfigPass()); } - /** - * {@inheritdoc} - */ public function getContainerExtension() { return new IngaLabsImageExtension(); diff --git a/src/Model/Aspect.php b/src/Model/Aspect.php index 53d5ca4..9baa291 100644 --- a/src/Model/Aspect.php +++ b/src/Model/Aspect.php @@ -10,110 +10,52 @@ namespace IngaLabs\Bundle\ImageBundle\Model; /** - * Aspect. - * * @author Antal Áron */ class Aspect { - /** - * @var int - */ private $id; - - /** - * @var string - */ private $shortName; - - /** - * @var int - */ private $width; - - /** - * @var int - */ private $height; - /** - * Get id. - * - * @return int - */ - public function getId() + public function getId(): ?int { return $this->id; } - /** - * Set shortName. - * - * @param string $shortName - * - * @return $this - */ - public function setShortName($shortName) + public function setShortName(string $shortName): self { $this->shortName = $shortName; return $this; } - /** - * Get shortName. - * - * @return string - */ - public function getShortName() + public function getShortName(): string { return $this->shortName; } - /** - * Set width. - * - * @param int $width - * - * @return $this - */ - public function setWidth($width) + public function setWidth(int $width): self { $this->width = $width; return $this; } - /** - * Get width. - * - * @return int - */ - public function getWidth() + public function getWidth(): int { return $this->width; } - /** - * Set height. - * - * @param int $height - * - * @return $this - */ - public function setHeight($height) + public function setHeight(int $height): self { $this->height = $height; return $this; } - /** - * Get height. - * - * @return int - */ - public function getHeight() + public function getHeight(): int { return $this->height; } diff --git a/src/Model/Image.php b/src/Model/Image.php index 6f3ec8f..0fa5177 100644 --- a/src/Model/Image.php +++ b/src/Model/Image.php @@ -10,293 +10,136 @@ namespace IngaLabs\Bundle\ImageBundle\Model; /** - * Image. - * * @author Antal Áron */ class Image { - /** - * @var string[] - */ public static $supportedMimeTypes = [ 'image/png', 'image/jpeg', 'image/gif', ]; - /** - * @var int|null - */ private $id; - - /** - * @var string - */ private $type; - - /** - * @var string - */ private $hash; - - /** - * @var int - */ private $width; - - /** - * @var int - */ private $height; - - /** - * @var string|null - */ private $caption; - - /** - * @var string - */ private $originalName; - - /** - * @var \DateTime - */ private $createdAt; - - /** - * @var \DateTime - */ private $lastModifiedAt; - - /** - * @var bool - */ private $animated = false; - /** - * Get id. - * - * @return int|null - */ - public function getId() + public function getId(): ?int { return $this->id; } - /** - * Set type. - * - * @param string $type - * - * @return $this - */ - public function setType($type) + public function setType(string $type): self { $this->type = $type; return $this; } - /** - * Get type. - * - * @return string - */ - public function getType() + public function getType(): string { return $this->type; } - /** - * Set hash. - * - * @param string $hash - * - * @return $this - */ - public function setHash($hash) + public function setHash(string $hash): self { $this->hash = $hash; return $this; } - /** - * Get hash. - * - * @return string - */ - public function getHash() + public function getHash(): string { return $this->hash; } - /** - * Set width. - * - * @param int $width - * - * @return $this - */ - public function setWidth($width) + public function setWidth(int $width): self { $this->width = $width; return $this; } - /** - * Get width. - * - * @return int - */ - public function getWidth() + public function getWidth(): int { return $this->width; } - /** - * Set height. - * - * @param int $height - * - * @return $this - */ - public function setHeight($height) + public function setHeight(int $height): self { $this->height = $height; return $this; } - /** - * Get height. - * - * @return int - */ - public function getHeight() + public function getHeight(): int { return $this->height; } - /** - * Set caption. - * - * @param string|null $caption - * - * @return $this - */ - public function setCaption($caption = null) + public function setCaption(?string $caption): self { $this->caption = $caption; return $this; } - /** - * Get caption. - * - * @return string|null - */ - public function getCaption() + public function getCaption(): ?string { return $this->caption; } - /** - * Set originalName. - * - * @param string $originalName - * - * @return $this - */ - public function setOriginalName($originalName) + public function setOriginalName(string $originalName): self { $this->originalName = $originalName; return $this; } - /** - * Get originalName. - * - * @return string - */ - public function getOriginalName() + public function getOriginalName(): string { return $this->originalName; } - /** - * Set createdAt. - * - * @param \DateTime $createdAt - * - * @return $this - */ - public function setCreatedAt(\DateTime $createdAt) + public function setCreatedAt(\DateTimeInterface $createdAt): self { $this->createdAt = $createdAt; return $this; } - /** - * Get createdAt. - * - * @return \DateTime - */ - public function getCreatedAt() + public function getCreatedAt(): \DateTimeInterface { return $this->createdAt; } - /** - * Set lastModifiedAt. - * - * @param \DateTime $lastModifiedAt - * - * @return $this - */ - public function setLastModifiedAt($lastModifiedAt) + public function setLastModifiedAt(\DateTimeInterface $lastModifiedAt): self { $this->lastModifiedAt = $lastModifiedAt; return $this; } - /** - * Get lastModifiedAt. - * - * @return \DateTime - */ - public function getLastModifiedAt() + public function getLastModifiedAt(): \DateTimeInterface { return $this->lastModifiedAt; } - /** - * Set animated. - * - * @param bool - * - * @return $this - */ - public function setAnimated($animated = true) + public function setAnimated(bool $animated = true): self { - $this->animated = (bool) $animated; + $this->animated = $animated; return $this; } - /** - * Is animated. - * - * @return bool - */ - public function isAnimated() + public function isAnimated(): bool { return $this->animated; } diff --git a/src/Model/Size.php b/src/Model/Size.php index 76a459b..3af3046 100644 --- a/src/Model/Size.php +++ b/src/Model/Size.php @@ -10,81 +10,39 @@ namespace IngaLabs\Bundle\ImageBundle\Model; /** - * Size. - * * @author Antal Áron */ class Size { - /** - * @var int - */ private $id; - - /** - * @var string - */ private $shortName; - - /** - * @var int - */ private $maxSize; - /** - * Get id. - * - * @return int - */ - public function getId() + public function getId(): ?int { return $this->id; } - /** - * Set shortName. - * - * @param string $shortName - * - * @return $this - */ - public function setShortName($shortName) + public function setShortName(string $shortName): self { $this->shortName = $shortName; return $this; } - /** - * Get shortName. - * - * @return string - */ - public function getShortName() + public function getShortName(): string { return $this->shortName; } - /** - * Set maxSize. - * - * @param int $maxSize - * - * @return $this - */ - public function setMaxSize($maxSize) + public function setMaxSize(int $maxSize): self { $this->maxSize = $maxSize; return $this; } - /** - * Get maxSize. - * - * @return int - */ - public function getMaxSize() + public function getMaxSize(): int { return $this->maxSize; } diff --git a/src/Repository/AspectRepositoryInterface.php b/src/Repository/AspectRepositoryInterface.php index 3c6f904..903db51 100644 --- a/src/Repository/AspectRepositoryInterface.php +++ b/src/Repository/AspectRepositoryInterface.php @@ -12,8 +12,6 @@ use Doctrine\Common\Persistence\ObjectRepository; /** - * AspectRepositoryInterface. - * * @author Antal Áron */ interface AspectRepositoryInterface extends ObjectRepository diff --git a/src/Repository/ImageRepositoryInterface.php b/src/Repository/ImageRepositoryInterface.php index eb34904..2afe12f 100644 --- a/src/Repository/ImageRepositoryInterface.php +++ b/src/Repository/ImageRepositoryInterface.php @@ -13,18 +13,9 @@ use IngaLabs\Bundle\ImageBundle\Model\Image; /** - * ImageRepositoryInterface. - * * @author Antal Áron */ interface ImageRepositoryInterface extends ObjectRepository { - /** - * Find one by hash. - * - * @param string $hash - * - * @return null|Image - */ - public function findOneByHash($hash); + public function findOneByHash(string $hash): ?Image; } diff --git a/src/Repository/ImageRepositoryTrait.php b/src/Repository/ImageRepositoryTrait.php index 9349b72..621d063 100644 --- a/src/Repository/ImageRepositoryTrait.php +++ b/src/Repository/ImageRepositoryTrait.php @@ -12,20 +12,11 @@ use IngaLabs\Bundle\ImageBundle\Model\Image; /** - * ImageRepositoryTrait. - * * @author Antal Áron */ trait ImageRepositoryTrait { - /** - * Find one by hash. - * - * @param string $hash - * - * @return null|Image - */ - public function findOneByHash($hash) + public function findOneByHash(string $hash): ?Image { return $this->findOneBy([ 'hash' => $hash, diff --git a/src/Repository/MongoDB/AspectRepository.php b/src/Repository/MongoDB/AspectRepository.php deleted file mode 100644 index dd1478d..0000000 --- a/src/Repository/MongoDB/AspectRepository.php +++ /dev/null @@ -1,22 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace IngaLabs\Bundle\ImageBundle\Repository\MongoDB; - -use Doctrine\ODM\MongoDB\DocumentRepository; -use IngaLabs\Bundle\ImageBundle\Repository\AspectRepositoryInterface; - -/** - * AspectRepository. - * - * @author Antal Áron - */ -class AspectRepository extends DocumentRepository implements AspectRepositoryInterface -{ -} diff --git a/src/Repository/MongoDB/ImageRepository.php b/src/Repository/MongoDB/ImageRepository.php deleted file mode 100644 index bc89d4d..0000000 --- a/src/Repository/MongoDB/ImageRepository.php +++ /dev/null @@ -1,24 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace IngaLabs\Bundle\ImageBundle\Repository\MongoDB; - -use Doctrine\ODM\MongoDB\DocumentRepository; -use IngaLabs\Bundle\ImageBundle\Repository\ImageRepositoryInterface; -use IngaLabs\Bundle\ImageBundle\Repository\ImageRepositoryTrait; - -/** - * ImageRepository. - * - * @author Antal Áron - */ -class ImageRepository extends DocumentRepository implements ImageRepositoryInterface -{ - use ImageRepositoryTrait; -} diff --git a/src/Repository/MongoDB/SizeRepository.php b/src/Repository/MongoDB/SizeRepository.php deleted file mode 100644 index 23f1c71..0000000 --- a/src/Repository/MongoDB/SizeRepository.php +++ /dev/null @@ -1,22 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace IngaLabs\Bundle\ImageBundle\Repository\MongoDB; - -use Doctrine\ODM\MongoDB\DocumentRepository; -use IngaLabs\Bundle\ImageBundle\Repository\SizeRepositoryInterface; - -/** - * SizeRepository. - * - * @author Antal Áron - */ -class SizeRepository extends DocumentRepository implements SizeRepositoryInterface -{ -} diff --git a/src/Repository/ORM/AspectRepository.php b/src/Repository/ORM/AspectRepository.php index 4cae521..224a29c 100644 --- a/src/Repository/ORM/AspectRepository.php +++ b/src/Repository/ORM/AspectRepository.php @@ -13,8 +13,6 @@ use IngaLabs\Bundle\ImageBundle\Repository\AspectRepositoryInterface; /** - * AspectRepository. - * * @author Antal Áron */ class AspectRepository extends EntityRepository implements AspectRepositoryInterface diff --git a/src/Repository/ORM/ImageRepository.php b/src/Repository/ORM/ImageRepository.php index c4fc73d..a1b1146 100644 --- a/src/Repository/ORM/ImageRepository.php +++ b/src/Repository/ORM/ImageRepository.php @@ -14,8 +14,6 @@ use IngaLabs\Bundle\ImageBundle\Repository\ImageRepositoryTrait; /** - * ImageRepository. - * * @author Antal Áron */ class ImageRepository extends EntityRepository implements ImageRepositoryInterface diff --git a/src/Repository/ORM/SizeRepository.php b/src/Repository/ORM/SizeRepository.php index 6a71c4d..b602963 100644 --- a/src/Repository/ORM/SizeRepository.php +++ b/src/Repository/ORM/SizeRepository.php @@ -13,8 +13,6 @@ use IngaLabs\Bundle\ImageBundle\Repository\SizeRepositoryInterface; /** - * SizeRepository. - * * @author Antal Áron */ class SizeRepository extends EntityRepository implements SizeRepositoryInterface diff --git a/src/Repository/SizeRepositoryInterface.php b/src/Repository/SizeRepositoryInterface.php index 5fff397..cc3c4b9 100644 --- a/src/Repository/SizeRepositoryInterface.php +++ b/src/Repository/SizeRepositoryInterface.php @@ -12,8 +12,6 @@ use Doctrine\Common\Persistence\ObjectRepository; /** - * SizeRepositoryInterface. - * * @author Antal Áron */ interface SizeRepositoryInterface extends ObjectRepository diff --git a/src/Resources/config/doctrine-entities/Aspect.mongodb.yml b/src/Resources/config/doctrine-entities/Aspect.mongodb.yml deleted file mode 100644 index c3a00e1..0000000 --- a/src/Resources/config/doctrine-entities/Aspect.mongodb.yml +++ /dev/null @@ -1,14 +0,0 @@ -IngaLabs\Bundle\ImageBundle\Model\Aspect: - repositoryClass: 'IngaLabs\Bundle\ImageBundle\Repository\MongoDB\AspectRepository' - fields: - id: - id: true - shortName: - type: string - length: 10 - width: - type: integer - nullable: true - height: - type: integer - nullable: true diff --git a/src/Resources/config/doctrine-entities/Image.mongodb.yml b/src/Resources/config/doctrine-entities/Image.mongodb.yml deleted file mode 100644 index af4c29d..0000000 --- a/src/Resources/config/doctrine-entities/Image.mongodb.yml +++ /dev/null @@ -1,29 +0,0 @@ -IngaLabs\Bundle\ImageBundle\Model\Image: - repositoryClass: 'IngaLabs\Bundle\ImageBundle\Repository\MongoDB\ImageRepository' - fields: - id: - id: true - type: - type: string - length: 10 - hash: - type: string - length: 32 - unique: true - width: - type: integer - height: - type: integer - caption: - type: string - length: 1024 - nullable: true - originalName: - type: string - length: 255 - createdAt: - type: date - lastModifiedAt: - type: date - animated: - type: boolean diff --git a/src/Resources/config/doctrine-entities/Size.mongodb.yml b/src/Resources/config/doctrine-entities/Size.mongodb.yml deleted file mode 100644 index 7087ce3..0000000 --- a/src/Resources/config/doctrine-entities/Size.mongodb.yml +++ /dev/null @@ -1,11 +0,0 @@ -IngaLabs\Bundle\ImageBundle\Model\Size: - repositoryClass: 'IngaLabs\Bundle\ImageBundle\Repository\MongoDB\SizeRepository' - fields: - id: - id: true - shortName: - type: string - length: 10 - maxSize: - type: integer - nullable: true diff --git a/src/Routing/Loader/ImageLoader.php b/src/Routing/Loader/ImageLoader.php index ef8ce3b..74ba891 100644 --- a/src/Routing/Loader/ImageLoader.php +++ b/src/Routing/Loader/ImageLoader.php @@ -15,38 +15,21 @@ use Symfony\Component\Routing\RouteCollection; /** - * ImageLoader. - * * @author Antal Áron */ class ImageLoader extends Loader { - /** - * @var bool - */ private $loaded = false; - - /** - * @var array - */ private $options = [ 'prefix' => '/assets/images', 'file_levels' => '2:8', ]; - /** - * Constructor. - * - * @param array $options - */ - public function __construct($options = []) + public function __construct(array $options = []) { $this->options = array_merge($this->options, array_intersect_key($options, $this->options)); } - /** - * {@inheritdoc} - */ public function load($resource, $type = null) { if (true === $this->loaded) { @@ -87,9 +70,6 @@ public function load($resource, $type = null) return $routes; } - /** - * {@inheritdoc} - */ public function supports($resource, $type = null) { return 'ingalabs_image' === $type; diff --git a/src/Twig/ImageExtension.php b/src/Twig/ImageExtension.php index d0f06e0..8dfd52c 100644 --- a/src/Twig/ImageExtension.php +++ b/src/Twig/ImageExtension.php @@ -11,47 +11,28 @@ use IngaLabs\Bundle\ImageBundle\ImageManager; use IngaLabs\Bundle\ImageBundle\Model\Image; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; /** - * ImageExtension. - * * @author Antal Áron */ -class ImageExtension extends \Twig_Extension +class ImageExtension extends AbstractExtension { - /** - * @var ImageManager - */ private $imageManager; - /** - * Constructor. - * - * @param ImageManager $imageManager - */ public function __construct(ImageManager $imageManager) { $this->imageManager = $imageManager; } - /** - * {@inheritdoc} - */ public function getFunctions() { return [ - new \Twig_SimpleFunction('image', [$this, 'getUrlFor']), + new TwigFunction('image', [$this, 'getUrlFor']), ]; } - /** - * Get Url for. - * - * @param Image|null $image - * @param array $options - * - * @return string - */ public function getUrlFor(Image $image = null, array $options = []) { if (null === $image) { diff --git a/tests/Tests/.gitkeep b/tests/Tests/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tests/Tests/Controller/ImageControllerTest.php b/tests/Tests/Controller/ImageControllerTest.php index 32d8a84..5c2c89d 100644 --- a/tests/Tests/Controller/ImageControllerTest.php +++ b/tests/Tests/Controller/ImageControllerTest.php @@ -15,14 +15,13 @@ use IngaLabs\Bundle\ImageBundle\ImageManager; use IngaLabs\Bundle\ImageBundle\Model\Image; use IngaLabs\Bundle\ImageBundle\Tests\ExceptionWrapperTestCaseTrait; +use PHPUnit\Framework\TestCase; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** - * ImageControllerTest. - * * @author Antal Áron */ -class ImageControllerTest extends \PHPUnit_Framework_TestCase +class ImageControllerTest extends TestCase { use ExceptionWrapperTestCaseTrait; @@ -37,7 +36,7 @@ public function testCreateResponseCalled() $imageManager ->expects($this->once()) ->method('getImageByHash') - ->will($this->returnValue($image)); + ->willReturn($image); $imageManager ->expects($this->once()) ->method('generate'); @@ -83,7 +82,7 @@ public function testGenerateInvalid() $imageManager ->expects($this->once()) ->method('getImageByHash') - ->will($this->returnValue($image)); + ->willReturn($image); $imageManager ->expects($this->once()) ->method('generate') diff --git a/tests/Tests/DependencyInjection/Compiler/ConfigPassTest.php b/tests/Tests/DependencyInjection/Compiler/ConfigPassTest.php index ec3d552..d98b728 100644 --- a/tests/Tests/DependencyInjection/Compiler/ConfigPassTest.php +++ b/tests/Tests/DependencyInjection/Compiler/ConfigPassTest.php @@ -19,8 +19,6 @@ use Symfony\Component\DependencyInjection\Reference; /** - * ConfigPassTest. - * * @author Antal Áron */ class ConfigPassTest extends AbstractCompilerPassTestCase diff --git a/tests/Tests/DependencyInjection/ConfigurationTest.php b/tests/Tests/DependencyInjection/ConfigurationTest.php index 91ecf75..0898388 100644 --- a/tests/Tests/DependencyInjection/ConfigurationTest.php +++ b/tests/Tests/DependencyInjection/ConfigurationTest.php @@ -11,13 +11,12 @@ use IngaLabs\Bundle\ImageBundle\DependencyInjection\Configuration; use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; +use PHPUnit\Framework\TestCase; /** - * ConfigurationTest. - * * @author Antal Áron */ -class ConfigurationTest extends \PHPUnit_Framework_TestCase +class ConfigurationTest extends TestCase { use ConfigurationTestCaseTrait; diff --git a/tests/Tests/DependencyInjection/IngaLabsImageExtensionTest.php b/tests/Tests/DependencyInjection/IngaLabsImageExtensionTest.php index 81923d8..4827844 100644 --- a/tests/Tests/DependencyInjection/IngaLabsImageExtensionTest.php +++ b/tests/Tests/DependencyInjection/IngaLabsImageExtensionTest.php @@ -13,8 +13,6 @@ use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; /** - * IngaLabsImageExtensionTest. - * * @author Antal Áron */ class IngaLabsImageExtensionTest extends AbstractExtensionTestCase diff --git a/tests/Tests/ExceptionWrapperTestCaseTrait.php b/tests/Tests/ExceptionWrapperTestCaseTrait.php index 6aac853..944dd0d 100644 --- a/tests/Tests/ExceptionWrapperTestCaseTrait.php +++ b/tests/Tests/ExceptionWrapperTestCaseTrait.php @@ -10,25 +10,15 @@ namespace IngaLabs\Bundle\ImageBundle\Tests; /** - * ExceptionWrapperTestCaseTrait. - * * @author Antal Áron */ trait ExceptionWrapperTestCaseTrait { protected function expectExceptionWrapper($exception, $regexp = null) { - if (method_exists($this, 'expectException')) { - $this->expectException($exception); - if (null !== $regexp) { - $this->expectExceptionMessageRegExp($regexp); - } - } else { - if (null !== $regexp) { - $this->setExpectedExceptionRegExp($exception, $regexp); - } else { - $this->setExpectedException($exception); - } + $this->expectException($exception); + if (null !== $regexp) { + $this->expectExceptionMessageRegExp($regexp); } } } diff --git a/tests/Tests/Helper/GifImageTest.php b/tests/Tests/Helper/GifImageTest.php index 0181cb9..f0e7daa 100644 --- a/tests/Tests/Helper/GifImageTest.php +++ b/tests/Tests/Helper/GifImageTest.php @@ -10,13 +10,12 @@ namespace IngaLabs\Bundle\ImageBundle\Tests\Helper; use IngaLabs\Bundle\ImageBundle\Helper\GifImage; +use PHPUnit\Framework\TestCase; /** - * GifImageTest. - * * @author Antal Áron */ -class GifImageTest extends \PHPUnit_Framework_TestCase +class GifImageTest extends TestCase { /** * @var GifImage diff --git a/tests/Tests/ImageManagerTest.php b/tests/Tests/ImageManagerTest.php index f7839e6..f2957aa 100644 --- a/tests/Tests/ImageManagerTest.php +++ b/tests/Tests/ImageManagerTest.php @@ -23,6 +23,7 @@ use IngaLabs\Bundle\ImageBundle\Repository\SizeRepositoryInterface; use Intervention\Image\Image as InventionImage; use Intervention\Image\ImageManager as InventionManager; +use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; use Symfony\Component\HttpFoundation\File\File; @@ -30,11 +31,9 @@ use Symfony\Component\HttpFoundation\Response; /** - * ImageManagerTest. - * * @author Antal Áron */ -class ImageManagerTest extends \PHPUnit_Framework_TestCase +class ImageManagerTest extends TestCase { use ExceptionWrapperTestCaseTrait; @@ -329,10 +328,10 @@ public function testHandleUpload() $path = __DIR__.'/../Fixtures/web'.$imageManager->getUrlFor($image); $toRemove = [ - dirname($path), - dirname(dirname($path)), - dirname(dirname(dirname($path))), - dirname(dirname(dirname(dirname($path)))), + \dirname($path), + \dirname(\dirname($path)), + \dirname(\dirname(\dirname($path))), + \dirname(\dirname(\dirname(\dirname($path)))), ]; unlink($path); rmdir($toRemove[0]); @@ -375,7 +374,7 @@ public function testHandleUploadFlush() $managerRegistry ->expects($this->once()) ->method('getManagerForClass') - ->will($this->returnValue($objectManager)); + ->willReturn($objectManager); $imageManager = new ImageManager($managerRegistry, [ 'prefix' => '/images', 'image_dir' => __DIR__.'/../Fixtures/web', @@ -385,10 +384,10 @@ public function testHandleUploadFlush() $path = __DIR__.'/../Fixtures/web'.$imageManager->getUrlFor($image); $toRemove = [ - dirname($path), - dirname(dirname($path)), - dirname(dirname(dirname($path))), - dirname(dirname(dirname(dirname($path)))), + \dirname($path), + \dirname(\dirname($path)), + \dirname(\dirname(\dirname($path))), + \dirname(\dirname(\dirname(\dirname($path)))), ]; unlink($path); rmdir($toRemove[0]); @@ -430,10 +429,10 @@ public function testHandleUploadOrientate() $path = __DIR__.'/../Fixtures/web'.$imageManager->getUrlFor($image); $toRemove = [ - dirname($path), - dirname(dirname($path)), - dirname(dirname(dirname($path))), - dirname(dirname(dirname(dirname($path)))), + \dirname($path), + \dirname(\dirname($path)), + \dirname(\dirname(\dirname($path))), + \dirname(\dirname(\dirname(\dirname($path)))), ]; unlink($path); rmdir($toRemove[0]); @@ -476,10 +475,10 @@ public function testHandleUploadAnimated() $path = __DIR__.'/../Fixtures/web'.$imageManager->getUrlFor($image); $toRemove = [ - dirname($path), - dirname(dirname($path)), - dirname(dirname(dirname($path))), - dirname(dirname(dirname(dirname($path)))), + \dirname($path), + \dirname(\dirname($path)), + \dirname(\dirname(\dirname($path))), + \dirname(\dirname(\dirname(\dirname($path)))), ]; unlink($path); rmdir($toRemove[0]); @@ -519,10 +518,10 @@ public function testHandleCopy() $path = __DIR__.'/../Fixtures/web'.$imageManager->getUrlFor($image); $toRemove = [ - dirname($path), - dirname(dirname($path)), - dirname(dirname(dirname($path))), - dirname(dirname(dirname(dirname($path)))), + \dirname($path), + \dirname(\dirname($path)), + \dirname(\dirname(\dirname($path))), + \dirname(\dirname(\dirname(\dirname($path)))), ]; unlink($path); rmdir($toRemove[0]); @@ -560,10 +559,10 @@ public function testHandleCopyJpeg() $path = __DIR__.'/../Fixtures/web'.$imageManager->getUrlFor($image); $toRemove = [ - dirname($path), - dirname(dirname($path)), - dirname(dirname(dirname($path))), - dirname(dirname(dirname(dirname($path)))), + \dirname($path), + \dirname(\dirname($path)), + \dirname(\dirname(\dirname($path))), + \dirname(\dirname(\dirname(\dirname($path)))), ]; unlink($path); rmdir($toRemove[0]); @@ -601,7 +600,7 @@ public function testHandleCopyFlush() $managerRegistry ->expects($this->once()) ->method('getManagerForClass') - ->will($this->returnValue($objectManager)); + ->willReturn($objectManager); $imageManager = new ImageManager($managerRegistry, [ 'prefix' => '/images', 'image_dir' => __DIR__.'/../Fixtures/web', @@ -611,10 +610,10 @@ public function testHandleCopyFlush() $path = __DIR__.'/../Fixtures/web'.$imageManager->getUrlFor($image); $toRemove = [ - dirname($path), - dirname(dirname($path)), - dirname(dirname(dirname($path))), - dirname(dirname(dirname(dirname($path)))), + \dirname($path), + \dirname(\dirname($path)), + \dirname(\dirname(\dirname($path))), + \dirname(\dirname(\dirname(\dirname($path)))), ]; unlink($path); rmdir($toRemove[0]); @@ -651,10 +650,10 @@ public function testHandleCopyOrientate() $path = __DIR__.'/../Fixtures/web'.$imageManager->getUrlFor($image); $toRemove = [ - dirname($path), - dirname(dirname($path)), - dirname(dirname(dirname($path))), - dirname(dirname(dirname(dirname($path)))), + \dirname($path), + \dirname(\dirname($path)), + \dirname(\dirname(\dirname($path))), + \dirname(\dirname(\dirname(\dirname($path)))), ]; unlink($path); rmdir($toRemove[0]); @@ -692,10 +691,10 @@ public function testHandleCopyAnimated() $path = __DIR__.'/../Fixtures/web'.$imageManager->getUrlFor($image); $toRemove = [ - dirname($path), - dirname(dirname($path)), - dirname(dirname(dirname($path))), - dirname(dirname(dirname(dirname($path)))), + \dirname($path), + \dirname(\dirname($path)), + \dirname(\dirname(\dirname($path))), + \dirname(\dirname(\dirname(\dirname($path)))), ]; unlink($path); rmdir($toRemove[0]); @@ -743,8 +742,8 @@ public function testCloneImage() $path = __DIR__.'/../Fixtures/web'.$imageManager->getUrlFor($image); $toRemove = [ - dirname($path), - dirname(dirname($path)), + \dirname($path), + \dirname(\dirname($path)), ]; unlink($path); rmdir($toRemove[0]); @@ -752,10 +751,10 @@ public function testCloneImage() $path = __DIR__.'/../Fixtures/web'.$imageManager->getUrlFor($newImage); $toRemove = [ - dirname($path), - dirname(dirname($path)), - dirname(dirname(dirname($path))), - dirname(dirname(dirname(dirname($path)))), + \dirname($path), + \dirname(\dirname($path)), + \dirname(\dirname(\dirname($path))), + \dirname(\dirname(\dirname(\dirname($path)))), ]; unlink($path); rmdir($toRemove[0]); @@ -802,7 +801,7 @@ public function testCloneImageFlush() $managerRegistry ->expects($this->once()) ->method('getManagerForClass') - ->will($this->returnValue($objectManager)); + ->willReturn($objectManager); $imageManager = new ImageManager($managerRegistry, [ 'prefix' => '/images', @@ -815,8 +814,8 @@ public function testCloneImageFlush() $path = __DIR__.'/../Fixtures/web'.$imageManager->getUrlFor($image); $toRemove = [ - dirname($path), - dirname(dirname($path)), + \dirname($path), + \dirname(\dirname($path)), ]; unlink($path); rmdir($toRemove[0]); @@ -824,10 +823,10 @@ public function testCloneImageFlush() $path = __DIR__.'/../Fixtures/web'.$imageManager->getUrlFor($newImage); $toRemove = [ - dirname($path), - dirname(dirname($path)), - dirname(dirname(dirname($path))), - dirname(dirname(dirname(dirname($path)))), + \dirname($path), + \dirname(\dirname($path)), + \dirname(\dirname(\dirname($path))), + \dirname(\dirname(\dirname(\dirname($path)))), ]; unlink($path); rmdir($toRemove[0]); @@ -1416,7 +1415,7 @@ public function testCropImageFlush() $managerRegistry ->expects($this->once()) ->method('getManagerForClass') - ->will($this->returnValue($objectManager)); + ->willReturn($objectManager); $imageManager = new ImageManager($managerRegistry, [ 'prefix' => '/images', @@ -1841,7 +1840,7 @@ public function testRotateFlush() $managerRegistry ->expects($this->once()) ->method('getManagerForClass') - ->will($this->returnValue($objectManager)); + ->willReturn($objectManager); $imageManager = new ImageManager($managerRegistry, [ 'prefix' => '/images', @@ -1925,7 +1924,7 @@ public function testDelete() $managerRegistry ->expects($this->never()) ->method('getManagerForClass') - ->will($this->returnValue($objectManager)); + ->willReturn($objectManager); $imageManager = new ImageManager($managerRegistry, [ 'prefix' => '/images', @@ -1979,7 +1978,7 @@ public function testDeleteKeepOriginal() $managerRegistry ->expects($this->never()) ->method('getManagerForClass') - ->will($this->returnValue($objectManager)); + ->willReturn($objectManager); $imageManager = new ImageManager($managerRegistry, [ 'prefix' => '/images', @@ -2034,7 +2033,7 @@ public function testDeleteKeepOriginalAndPurge() $managerRegistry ->expects($this->never()) ->method('getManagerForClass') - ->will($this->returnValue($objectManager)); + ->willReturn($objectManager); $imageManager = new ImageManager($managerRegistry, [ 'prefix' => '/images', @@ -2089,7 +2088,7 @@ public function testDeleteNotKeepOriginalAndPurge() $managerRegistry ->expects($this->once()) ->method('getManagerForClass') - ->will($this->returnValue($objectManager)); + ->willReturn($objectManager); $imageManager = new ImageManager($managerRegistry, [ 'prefix' => '/images', @@ -2231,10 +2230,10 @@ public function getManagerRegistryMock($imagesArray = [], $aspectsArray = [], $s ->getMock(); $imageRepository ->method('find') - ->will($this->returnValueMap($images)); + ->willReturnMap($images); $imageRepository ->method('findOneByHash') - ->will($this->returnValueMap($imagesByHash)); + ->willReturnMap($imagesByHash); $aspectRepository = $this ->getMockBuilder(AspectRepositoryInterface::class) @@ -2242,10 +2241,10 @@ public function getManagerRegistryMock($imagesArray = [], $aspectsArray = [], $s ->getMock(); $aspectRepository ->method('find') - ->will($this->returnValueMap($aspects)); + ->willReturnMap($aspects); $aspectRepository ->method('findAll') - ->will($this->returnValue($aspectsArray)); + ->willReturn($aspectsArray); $sizeRepository = $this ->getMockBuilder(SizeRepositoryInterface::class) @@ -2253,10 +2252,10 @@ public function getManagerRegistryMock($imagesArray = [], $aspectsArray = [], $s ->getMock(); $sizeRepository ->method('find') - ->will($this->returnValueMap($sizes)); + ->willReturnMap($sizes); $sizeRepository ->method('findAll') - ->will($this->returnValue($sizesArray)); + ->willReturn($sizesArray); $repositoryMap = [ [Image::class, null, $imageRepository], @@ -2270,7 +2269,7 @@ public function getManagerRegistryMock($imagesArray = [], $aspectsArray = [], $s ->getMock(); $managerRegistry ->method('getRepository') - ->will($this->returnValueMap($repositoryMap)); + ->willReturnMap($repositoryMap); return $managerRegistry; } diff --git a/tests/Tests/IngaLabsImageBundleTest.php b/tests/Tests/IngaLabsImageBundleTest.php index 830eec5..39a02d7 100644 --- a/tests/Tests/IngaLabsImageBundleTest.php +++ b/tests/Tests/IngaLabsImageBundleTest.php @@ -15,14 +15,13 @@ use IngaLabs\Bundle\ImageBundle\DependencyInjection\Compiler\ConfigPass; use IngaLabs\Bundle\ImageBundle\DependencyInjection\IngaLabsImageExtension; use IngaLabs\Bundle\ImageBundle\IngaLabsImageBundle; +use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; /** - * IngaLabsImageBundleTest. - * * @author Antal Áron */ -class IngaLabsImageBundleTest extends \PHPUnit_Framework_TestCase +class IngaLabsImageBundleTest extends TestCase { public function testConfigCompilerPass() { diff --git a/tests/Tests/Model/AspectTest.php b/tests/Tests/Model/AspectTest.php index 4bd1499..6389e98 100644 --- a/tests/Tests/Model/AspectTest.php +++ b/tests/Tests/Model/AspectTest.php @@ -10,12 +10,13 @@ namespace IngaLabs\Bundle\ImageBundle\Tests\Model; use IngaLabs\Bundle\ImageBundle\Model\Aspect; +use PHPUnit\Framework\TestCase; -class AspectTest extends \PHPUnit_Framework_TestCase +/** + * @author Antal Áron + */ +class AspectTest extends TestCase { - /** - * @var Aspect - */ protected $object; protected function setUp() diff --git a/tests/Tests/Model/ImageTest.php b/tests/Tests/Model/ImageTest.php index 6f9295a..c7f880b 100644 --- a/tests/Tests/Model/ImageTest.php +++ b/tests/Tests/Model/ImageTest.php @@ -10,12 +10,13 @@ namespace IngaLabs\Bundle\ImageBundle\Tests\Model; use IngaLabs\Bundle\ImageBundle\Model\Image; +use PHPUnit\Framework\TestCase; -class ImageTest extends \PHPUnit_Framework_TestCase +/** + * @author Antal Áron + */ +class ImageTest extends TestCase { - /** - * @var Image - */ protected $object; protected function setUp() diff --git a/tests/Tests/Model/SizeTest.php b/tests/Tests/Model/SizeTest.php index fd99669..daaa40e 100644 --- a/tests/Tests/Model/SizeTest.php +++ b/tests/Tests/Model/SizeTest.php @@ -10,12 +10,13 @@ namespace IngaLabs\Bundle\ImageBundle\Tests\Model; use IngaLabs\Bundle\ImageBundle\Model\Size; +use PHPUnit\Framework\TestCase; -class SizeTest extends \PHPUnit_Framework_TestCase +/** + * @author Antal Áron + */ +class SizeTest extends TestCase { - /** - * @var Size - */ protected $object; protected function setUp() diff --git a/tests/Tests/Repository/ImageRepositoryTraitTest.php b/tests/Tests/Repository/ImageRepositoryTraitTest.php index c41b311..488d678 100644 --- a/tests/Tests/Repository/ImageRepositoryTraitTest.php +++ b/tests/Tests/Repository/ImageRepositoryTraitTest.php @@ -11,13 +11,12 @@ use Doctrine\Common\Persistence\ObjectRepository; use IngaLabs\Bundle\ImageBundle\Repository\ImageRepositoryTrait; +use PHPUnit\Framework\TestCase; /** - * ImageRepositoryTraitTest. - * * @author Antal Áron */ -class ImageRepositoryTraitTest extends \PHPUnit_Framework_TestCase +class ImageRepositoryTraitTest extends TestCase { public function testFindOneByHashCallsTheAbstractMethod() { @@ -26,9 +25,9 @@ public function testFindOneByHashCallsTheAbstractMethod() $repository ->expects($this->once()) ->method('findOneBy') - ->will($this->returnCallback(function ($criteria) { + ->willReturnCallback(function ($criteria) { return $criteria; - })); + }); $this->assertSame(['hash' => 'foo_bar'], $repository->findOneByHash('foo_bar')); } diff --git a/tests/Tests/Routing/Loader/ImageLoaderTest.php b/tests/Tests/Routing/Loader/ImageLoaderTest.php index 3fcdaf7..dde10c0 100644 --- a/tests/Tests/Routing/Loader/ImageLoaderTest.php +++ b/tests/Tests/Routing/Loader/ImageLoaderTest.php @@ -12,13 +12,12 @@ use IngaLabs\Bundle\ImageBundle\Exception\LoaderException; use IngaLabs\Bundle\ImageBundle\Routing\Loader\ImageLoader; use IngaLabs\Bundle\ImageBundle\Tests\ExceptionWrapperTestCaseTrait; +use PHPUnit\Framework\TestCase; /** - * ImageLoaderTest. - * * @author Antal Áron */ -class ImageLoaderTest extends \PHPUnit_Framework_TestCase +class ImageLoaderTest extends TestCase { use ExceptionWrapperTestCaseTrait; diff --git a/tests/Tests/Twig/ImageExtensionTest.php b/tests/Tests/Twig/ImageExtensionTest.php index 397cfd1..4863528 100644 --- a/tests/Tests/Twig/ImageExtensionTest.php +++ b/tests/Tests/Twig/ImageExtensionTest.php @@ -13,13 +13,14 @@ use IngaLabs\Bundle\ImageBundle\ImageManager; use IngaLabs\Bundle\ImageBundle\Model\Image; use IngaLabs\Bundle\ImageBundle\Twig\ImageExtension; +use PHPUnit\Framework\TestCase; +use Twig\Environment; +use Twig\Loader\ArrayLoader; /** - * ImageExtensionTest. - * * @author Antal Áron */ -class ImageExtensionTest extends \PHPUnit_Framework_TestCase +class ImageExtensionTest extends TestCase { public function testImage() { @@ -31,10 +32,10 @@ public function testImage() $managerRegistry = $this->getManagerRegistryMock(); $imageManager = new ImageManager($managerRegistry, ['prefix' => '/images']); - $loader = new \Twig_Loader_Array([ + $loader = new ArrayLoader([ 'index.html' => '{{ image(image) }}', ]); - $twig = new \Twig_Environment($loader, ['debug' => false, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0]); + $twig = new Environment($loader, ['debug' => false, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0]); $twig->addExtension(new ImageExtension($imageManager)); $this->assertSame('/images/01/01234567/01234567890123456789012345678901_or_or.jpg', $twig->render('index.html', ['image' => $image])); @@ -51,10 +52,10 @@ public function testImageFull() $managerRegistry = $this->getManagerRegistryMock(); $imageManager = new ImageManager($managerRegistry, ['prefix' => '/images']); - $loader = new \Twig_Loader_Array([ + $loader = new ArrayLoader([ 'index.html' => '{{ image(image, {\'size\': \'sm\', \'aspect\': \'1x1\', \'show_last_modified\': true}) }}', ]); - $twig = new \Twig_Environment($loader, ['debug' => false, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0]); + $twig = new Environment($loader, ['debug' => false, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0]); $twig->addExtension(new ImageExtension($imageManager)); $this->assertSame('/images/01/01234567/01234567890123456789012345678901_sm_1x1.jpg?timestamp=522538840', $twig->render('index.html', ['image' => $image])); @@ -67,10 +68,10 @@ public function testImageNull() $managerRegistry = $this->getManagerRegistryMock(); $imageManager = new ImageManager($managerRegistry, ['prefix' => '/images']); - $loader = new \Twig_Loader_Array([ + $loader = new ArrayLoader([ 'index.html' => '{{ image(image) }}', ]); - $twig = new \Twig_Environment($loader, ['debug' => false, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0]); + $twig = new Environment($loader, ['debug' => false, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0]); $twig->addExtension(new ImageExtension($imageManager)); $this->assertSame('', $twig->render('index.html', ['image' => $image]));