From 8c254a4ce8260970120e90a957a050060dee4f62 Mon Sep 17 00:00:00 2001 From: Johann Untereiner Date: Sat, 16 Feb 2019 23:15:55 +0100 Subject: [PATCH] Upgrade jms/metadata to 2.0 * Up minimum php version to 7.2 * Used ::class instead of FQCN string * phpcsfixer * update travis * fix some tests deprecations --- .travis.yml | 5 +- Command/MappingDebugClassCommand.php | 6 +- Command/MappingDebugCommand.php | 6 +- Command/MappingListClassesCommand.php | 4 +- .../Compiler/RegisterMappingDriversPass.php | 2 +- .../Compiler/RegisterPropelModelsPass.php | 4 +- DependencyInjection/VichUploaderExtension.php | 26 ++++---- Form/Type/VichFileType.php | 4 +- Form/Type/VichImageType.php | 2 +- Metadata/Driver/AnnotationDriver.php | 7 ++- Metadata/Driver/XmlDriver.php | 9 +-- Metadata/Driver/YamlDriver.php | 21 ++++--- .../ODM/MongoDB/MongoDBAdapterTest.php | 5 +- Tests/Adapter/ORM/DoctrineORMAdapterTest.php | 5 +- Tests/Adapter/PHPCR/PHPCRAdapterTest.php | 2 +- Tests/Adapter/Propel/PropelORMAdapterTest.php | 7 ++- .../VichUploaderExtensionTest.php | 8 ++- .../Doctrine/CleanListenerTest.php | 7 ++- .../Doctrine/InjectListenerTest.php | 7 ++- .../Doctrine/ListenerTestCase.php | 8 +-- .../Doctrine/RemoveListenerTest.php | 9 +-- .../Doctrine/UploadListenerTest.php | 13 ++-- .../EventListener/Propel/ListenerTestCase.php | 10 +-- Tests/Fixtures/App/app/AppKernel.php | 4 +- Tests/Form/Type/VichImageTypeTest.php | 2 +- Tests/Functional/WebTestCase.php | 3 +- Tests/Handler/DownloadHandlerTest.php | 8 +-- Tests/Handler/UploadHandlerTest.php | 9 ++- Tests/Injector/FileInjectorTest.php | 14 +++-- Tests/Mapping/PropertyMappingFactoryTest.php | 63 ++++++++++--------- Tests/Mapping/PropertyMappingTest.php | 3 +- Tests/Metadata/ClassMetadataTest.php | 2 +- .../Metadata/Driver/AnnotationDriverTest.php | 12 ++-- Tests/Metadata/MetadataReaderTest.php | 3 +- .../CurrentDateTimeDirectoryNamerTest.php | 2 +- Tests/Naming/OrignameNamerTest.php | 3 +- Tests/Naming/UniqidNamerTest.php | 3 +- Tests/Storage/FileSystemStorageTest.php | 4 +- Tests/Storage/FlysystemStorageTest.php | 6 +- Tests/Storage/GaufretteStorageTest.php | 6 +- Tests/Templating/Helper/UploadHelperTest.php | 3 +- Tests/TestCase.php | 2 +- .../Twig/Extension/UploaderExtensionTest.php | 3 +- Util/ClassUtils.php | 2 +- Util/FilenameUtils.php | 4 +- composer.json | 7 ++- 46 files changed, 186 insertions(+), 159 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7cd5cda7..69def179 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 7.1 - 7.2 - 7.3 - nightly @@ -18,10 +17,8 @@ env: matrix: include: - - php: 7.1 + - php: 7.2 env: VALIDATE_DOCS=true COMPOSER_FLAGS="--prefer-lowest" - - php: 7.1 - env: SYMFONY_VERSION="~4.1.0" WITH_LIIP_IMAGINE=true - php: 7.2 env: SYMFONY_VERSION="~4.2.0" WITH_LIIP_IMAGINE=true - php: 7.3 diff --git a/Command/MappingDebugClassCommand.php b/Command/MappingDebugClassCommand.php index aec18d01..7a4b5554 100644 --- a/Command/MappingDebugClassCommand.php +++ b/Command/MappingDebugClassCommand.php @@ -34,16 +34,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int $fqcn = $input->getArgument('fqcn'); if (!$this->metadataReader->isUploadable($fqcn)) { - $output->writeln(sprintf('"%s" is not uploadable.', $fqcn)); + $output->writeln(\sprintf('"%s" is not uploadable.', $fqcn)); return 1; } $uploadableFields = $this->metadataReader->getUploadableFields($fqcn); - $output->writeln(sprintf('Introspecting class %s:', $fqcn)); + $output->writeln(\sprintf('Introspecting class %s:', $fqcn)); foreach ($uploadableFields as $data) { - $output->writeln(sprintf('Found field "%s", storing file name in "%s" and using mapping "%s"', $data['propertyName'], $data['fileNameProperty'], $data['mapping'])); + $output->writeln(\sprintf('Found field "%s", storing file name in "%s" and using mapping "%s"', $data['propertyName'], $data['fileNameProperty'], $data['mapping'])); } return 0; diff --git a/Command/MappingDebugCommand.php b/Command/MappingDebugCommand.php index 30c991e3..c54d6ca5 100644 --- a/Command/MappingDebugCommand.php +++ b/Command/MappingDebugCommand.php @@ -34,13 +34,13 @@ protected function execute(InputInterface $input, OutputInterface $output): void $mapping = $input->getArgument('mapping'); if (!isset($this->mappings[$mapping])) { - throw new MappingNotFoundException(sprintf('Mapping "%s" does not exist.', $mapping)); + throw new MappingNotFoundException(\sprintf('Mapping "%s" does not exist.', $mapping)); } - $output->writeln(sprintf('Debug information for mapping %s', $mapping)); + $output->writeln(\sprintf('Debug information for mapping %s', $mapping)); foreach ($this->mappings[$mapping] as $key => $value) { - $output->writeln(sprintf('%s: %s', $key, var_export($value, true))); + $output->writeln(\sprintf('%s: %s', $key, \var_export($value, true))); } } } diff --git a/Command/MappingListClassesCommand.php b/Command/MappingListClassesCommand.php index a4fa97bd..4b206a46 100644 --- a/Command/MappingListClassesCommand.php +++ b/Command/MappingListClassesCommand.php @@ -34,10 +34,10 @@ protected function execute(InputInterface $input, OutputInterface $output): void $uploadableClasses = $this->metadataReader->getUploadableClasses(); foreach ($uploadableClasses as $class) { - $output->writeln(sprintf('Found %s', $class)); + $output->writeln(\sprintf('Found %s', $class)); } - $output->writeln(sprintf('Found %d classes.', \count($uploadableClasses))); + $output->writeln(\sprintf('Found %d classes.', \count($uploadableClasses))); $output->writeln('NOTE: Only classes configured using XML or YAML are displayed.'); } } diff --git a/DependencyInjection/Compiler/RegisterMappingDriversPass.php b/DependencyInjection/Compiler/RegisterMappingDriversPass.php index c3ad0f38..e68e7be2 100644 --- a/DependencyInjection/Compiler/RegisterMappingDriversPass.php +++ b/DependencyInjection/Compiler/RegisterMappingDriversPass.php @@ -19,7 +19,7 @@ public function process(ContainerBuilder $container): void $drivers[] = new Reference('vich_uploader.metadata_driver.annotation'); } - if (class_exists(Yaml::class)) { + if (\class_exists(Yaml::class)) { $drivers[] = new Reference('vich_uploader.metadata_driver.yaml'); } diff --git a/DependencyInjection/Compiler/RegisterPropelModelsPass.php b/DependencyInjection/Compiler/RegisterPropelModelsPass.php index e48d85d2..a085b027 100644 --- a/DependencyInjection/Compiler/RegisterPropelModelsPass.php +++ b/DependencyInjection/Compiler/RegisterPropelModelsPass.php @@ -56,11 +56,11 @@ public function process(ContainerBuilder $container): void } foreach ($serviceTypes as $type) { - if (!$container->has(sprintf('vich_uploader.listener.%s.%s', $type, $field['mapping']))) { + if (!$container->has(\sprintf('vich_uploader.listener.%s.%s', $type, $field['mapping']))) { continue; } - $definition = $container->getDefinition(sprintf('vich_uploader.listener.%s.%s', $type, $field['mapping'])); + $definition = $container->getDefinition(\sprintf('vich_uploader.listener.%s.%s', $type, $field['mapping'])); $definition->setClass($container->getDefinition($definition->getParent())->getClass()); $definition->setPublic(true); $definition->addTag('propel.event_subscriber', ['class' => $class]); diff --git a/DependencyInjection/VichUploaderExtension.php b/DependencyInjection/VichUploaderExtension.php index c2fd1197..b4f11094 100644 --- a/DependencyInjection/VichUploaderExtension.php +++ b/DependencyInjection/VichUploaderExtension.php @@ -38,8 +38,8 @@ public function load(array $configs, ContainerBuilder $container): void $container->setParameter('vich_uploader.default_filename_attribute_suffix', $config['default_filename_attribute_suffix']); $container->setParameter('vich_uploader.mappings', $config['mappings']); - if (0 === strpos($config['storage'], '@')) { - $container->setAlias('vich_uploader.storage', substr($config['storage'], 1)); + if (0 === \strpos($config['storage'], '@')) { + $container->setAlias('vich_uploader.storage', \substr($config['storage'], 1)); } else { $container->setAlias('vich_uploader.storage', 'vich_uploader.storage.'.$config['storage']); } @@ -93,7 +93,7 @@ protected function registerMetadataDirectories(ContainerBuilder $container, arra $ref = new \ReflectionClass($class); $directory = \dirname($ref->getFileName()).'/Resources/config/vich_uploader'; - if (!is_dir($directory)) { + if (!\is_dir($directory)) { continue; } @@ -102,20 +102,20 @@ protected function registerMetadataDirectories(ContainerBuilder $container, arra } foreach ($config['metadata']['directories'] as $directory) { - $directory['path'] = rtrim(str_replace('\\', '/', $directory['path']), '/'); + $directory['path'] = \rtrim(\str_replace('\\', '/', $directory['path']), '/'); if ('@' === $directory['path'][0]) { - $bundleName = substr($directory['path'], 1, strpos($directory['path'], '/') - 1); + $bundleName = \substr($directory['path'], 1, \strpos($directory['path'], '/') - 1); if (!isset($bundles[$bundleName])) { - throw new \RuntimeException(sprintf('The bundle "%s" has not been registered with AppKernel. Available bundles: %s', $bundleName, implode(', ', array_keys($bundles)))); + throw new \RuntimeException(\sprintf('The bundle "%s" has not been registered with AppKernel. Available bundles: %s', $bundleName, \implode(', ', \array_keys($bundles)))); } $ref = new \ReflectionClass($bundles[$bundleName]); - $directory['path'] = \dirname($ref->getFileName()).substr($directory['path'], \strlen('@'.$bundleName)); + $directory['path'] = \dirname($ref->getFileName()).\substr($directory['path'], \strlen('@'.$bundleName)); } - $directories[rtrim($directory['namespace_prefix'], '\\')] = rtrim($directory['path'], '\\/'); + $directories[\rtrim($directory['namespace_prefix'], '\\')] = \rtrim($directory['path'], '\\/'); } $container @@ -135,8 +135,8 @@ protected function registerCacheStrategy(ContainerBuilder $container, array $con ; $dir = $container->getParameterBag()->resolveValue($config['metadata']['file_cache']['dir']); - if (!file_exists($dir) && !@mkdir($dir, 0777, true)) { - throw new \RuntimeException(sprintf('Could not create cache directory "%s".', $dir)); + if (!\file_exists($dir) && !@\mkdir($dir, 0777, true)) { + throw new \RuntimeException(\sprintf('Could not create cache directory "%s".', $dir)); } } else { $container->setAlias('vich_uploader.metadata.cache', new Alias($config['metadata']['cache'], false)); @@ -191,7 +191,7 @@ protected function createNamerServices(ContainerBuilder $container, array $confi protected function createNamerService(ContainerBuilder $container, string $mappingName, array $mapping): array { - $serviceId = sprintf('%s.%s', $mapping['namer']['service'], $mappingName); + $serviceId = \sprintf('%s.%s', $mapping['namer']['service'], $mappingName); $container->setDefinition( $serviceId, new ChildDefinition($mapping['namer']['service']) ); @@ -209,7 +209,7 @@ protected function createListener( int $priority = 0 ): void { $definition = $container - ->setDefinition(sprintf('vich_uploader.listener.%s.%s', $type, $name), new ChildDefinition(sprintf('vich_uploader.listener.%s.%s', $type, $driver))) + ->setDefinition(\sprintf('vich_uploader.listener.%s.%s', $type, $name), new ChildDefinition(\sprintf('vich_uploader.listener.%s.%s', $type, $driver))) ->replaceArgument(0, $name) ->replaceArgument(1, new Reference('vich_uploader.adapter.'.$driver)); @@ -224,7 +224,7 @@ private function registerFormTheme(ContainerBuilder $container): void $resources = $container->hasParameter('twig.form.resources') ? $container->getParameter('twig.form.resources') : []; - array_unshift($resources, '@VichUploader/Form/fields.html.twig'); + \array_unshift($resources, '@VichUploader/Form/fields.html.twig'); $container->setParameter('twig.form.resources', $resources); } } diff --git a/Form/Type/VichFileType.php b/Form/Type/VichFileType.php index 0ca4dab1..55ce98d2 100644 --- a/Form/Type/VichFileType.php +++ b/Form/Type/VichFileType.php @@ -79,7 +79,7 @@ public function configureOptions(OptionsResolver $resolver): void $downloadUriNormalizer = function (Options $options, $downloadUri) { if (null !== $options['download_link']) { - @trigger_error('The "download_link" option is deprecated since version 1.6 and will be removed in 2.0. You should use "download_uri" instead.', E_USER_DEPRECATED); + @\trigger_error('The "download_link" option is deprecated since version 1.6 and will be removed in 2.0. You should use "download_uri" instead.', E_USER_DEPRECATED); return $options['download_link']; } @@ -153,7 +153,7 @@ public function buildView(FormView $view, FormInterface $form, array $options): $view->vars['download_uri'] = null; if ($options['download_uri'] && $object) { $view->vars['download_uri'] = $this->resolveUriOption($options['download_uri'], $object, $form); - $view->vars = array_replace( + $view->vars = \array_replace( $view->vars, $this->resolveDownloadLabel($options['download_label'], $object, $form) ); diff --git a/Form/Type/VichImageType.php b/Form/Type/VichImageType.php index d11588f3..bd49985f 100644 --- a/Form/Type/VichImageType.php +++ b/Form/Type/VichImageType.php @@ -74,7 +74,7 @@ public function buildView(FormView $view, FormInterface $form, array $options): $view->vars['image_uri'] = $this->resolveUriOption($options['image_uri'], $object, $form); } - $view->vars = array_replace( + $view->vars = \array_replace( $view->vars, $this->resolveDownloadLabel($options['download_label'], $object, $form) ); diff --git a/Metadata/Driver/AnnotationDriver.php b/Metadata/Driver/AnnotationDriver.php index 7463d78d..30e49134 100644 --- a/Metadata/Driver/AnnotationDriver.php +++ b/Metadata/Driver/AnnotationDriver.php @@ -3,6 +3,7 @@ namespace Vich\UploaderBundle\Metadata\Driver; use Doctrine\Common\Annotations\Reader as AnnotationReader; +use Metadata\ClassMetadata as JMSClassMetadata; use Metadata\Driver\AdvancedDriverInterface; use Vich\UploaderBundle\Mapping\Annotation\Uploadable; use Vich\UploaderBundle\Mapping\Annotation\UploadableField; @@ -31,10 +32,10 @@ public function __construct(AnnotationReader $reader) $this->reader = $reader; } - public function loadMetadataForClass(\ReflectionClass $class) + public function loadMetadataForClass(\ReflectionClass $class): ?JMSClassMetadata { if (!$this->isUploadable($class)) { - return; + return null; } $classMetadata = new ClassMetadata($class->name); @@ -65,7 +66,7 @@ public function loadMetadataForClass(\ReflectionClass $class) return $classMetadata; } - public function getAllClassNames() + public function getAllClassNames(): array { return []; } diff --git a/Metadata/Driver/XmlDriver.php b/Metadata/Driver/XmlDriver.php index bc22fa24..856ff7e7 100644 --- a/Metadata/Driver/XmlDriver.php +++ b/Metadata/Driver/XmlDriver.php @@ -2,6 +2,7 @@ namespace Vich\UploaderBundle\Metadata\Driver; +use Metadata\ClassMetadata as JMSClassMetadata; use Metadata\Driver\AbstractFileDriver; use Symfony\Component\Config\Util\XmlUtils; use Vich\UploaderBundle\Metadata\ClassMetadata; @@ -12,10 +13,10 @@ */ class XmlDriver extends AbstractFileDriver { - protected function loadMetadataFromFile(\ReflectionClass $class, $file) + protected function loadMetadataFromFile(\ReflectionClass $class, string $file): ?JMSClassMetadata { $elem = XmlUtils::loadFile($file); - $elem = simplexml_import_dom($elem); + $elem = \simplexml_import_dom($elem); $className = $this->guessClassName($file, $elem, $class); $classMetadata = new ClassMetadata($className); @@ -42,7 +43,7 @@ protected function loadMetadataFromFile(\ReflectionClass $class, $file) /** * {@inheritdoc} */ - protected function getExtension() + protected function getExtension(): string { return 'xml'; } @@ -54,7 +55,7 @@ protected function guessClassName($file, \SimpleXMLElement $elem, \ReflectionCla } if ($class->name !== (string) $elem->attributes()->class) { - throw new \RuntimeException(sprintf('Expected metadata for class %s to be defined in %s.', $class->name, $file)); + throw new \RuntimeException(\sprintf('Expected metadata for class %s to be defined in %s.', $class->name, $file)); } return $class->name; diff --git a/Metadata/Driver/YamlDriver.php b/Metadata/Driver/YamlDriver.php index b2bb8dcd..35b1f4a8 100644 --- a/Metadata/Driver/YamlDriver.php +++ b/Metadata/Driver/YamlDriver.php @@ -2,6 +2,7 @@ namespace Vich\UploaderBundle\Metadata\Driver; +use Metadata\ClassMetadata as JMSClassMetadata; use Metadata\Driver\AbstractFileDriver; use Symfony\Component\Yaml\Yaml as YmlParser; use Vich\UploaderBundle\Metadata\ClassMetadata; @@ -15,7 +16,7 @@ class YamlDriver extends AbstractFileDriver /** * {@inheritdoc} */ - protected function loadMetadataFromFile(\ReflectionClass $class, $file) + protected function loadMetadataFromFile(\ReflectionClass $class, string $file): ?JMSClassMetadata { $config = $this->loadMappingFile($file); $className = $this->guessClassName($file, $config, $class); @@ -27,11 +28,11 @@ protected function loadMetadataFromFile(\ReflectionClass $class, $file) $fieldMetadata = [ 'mapping' => $mappingData['mapping'], 'propertyName' => $field, - 'fileNameProperty' => isset($mappingData['filename_property']) ? $mappingData['filename_property'] : null, - 'size' => isset($mappingData['size']) ? $mappingData['size'] : null, - 'mimeType' => isset($mappingData['mime_type']) ? $mappingData['mime_type'] : null, - 'originalName' => isset($mappingData['original_name']) ? $mappingData['original_name'] : null, - 'dimensions' => isset($mappingData['dimensions']) ? $mappingData['dimensions'] : null, + 'fileNameProperty' => $mappingData['filename_property'] ?? null, + 'size' => $mappingData['size'] ?? null, + 'mimeType' => $mappingData['mime_type'] ?? null, + 'originalName' => $mappingData['original_name'] ?? null, + 'dimensions' => $mappingData['dimensions'] ?? null, ]; $classMetadata->fields[$field] = $fieldMetadata; @@ -42,13 +43,13 @@ protected function loadMetadataFromFile(\ReflectionClass $class, $file) protected function loadMappingFile($file) { - return YmlParser::parse(file_get_contents($file)); + return YmlParser::parse(\file_get_contents($file)); } /** * {@inheritdoc} */ - protected function getExtension() + protected function getExtension(): string { return 'yml'; } @@ -56,11 +57,11 @@ protected function getExtension() protected function guessClassName($file, array $config, \ReflectionClass $class = null) { if (null === $class) { - return current(array_keys($config)); + return \current(\array_keys($config)); } if (!isset($config[$class->name])) { - throw new \RuntimeException(sprintf('Expected metadata for class %s to be defined in %s.', $class->name, $file)); + throw new \RuntimeException(\sprintf('Expected metadata for class %s to be defined in %s.', $class->name, $file)); } return $class->name; diff --git a/Tests/Adapter/ODM/MongoDB/MongoDBAdapterTest.php b/Tests/Adapter/ODM/MongoDB/MongoDBAdapterTest.php index 2f44e9a5..28f7ba6f 100644 --- a/Tests/Adapter/ODM/MongoDB/MongoDBAdapterTest.php +++ b/Tests/Adapter/ODM/MongoDB/MongoDBAdapterTest.php @@ -2,6 +2,7 @@ namespace Vich\UploaderBundle\Tests\Adapter\ODM\MongoDB; +use Doctrine\ODM\MongoDB\Event\LifecycleEventArgs; use PHPUnit\Framework\TestCase; use Vich\UploaderBundle\Adapter\ODM\MongoDB\MongoDBAdapter; use Vich\UploaderBundle\Tests\DummyEntity; @@ -15,7 +16,7 @@ class MongoDBAdapterTest extends TestCase { public static function setUpBeforeClass(): void { - if (!class_exists('Doctrine\ODM\MongoDB\Event\LifecycleEventArgs')) { + if (!\class_exists(LifecycleEventArgs::class)) { self::markTestSkipped('Doctrine\ODM\MongoDB\Event\LifecycleEventArgs does not exist.'); } } @@ -27,7 +28,7 @@ public function testGetObjectFromArgs(): void { $entity = new DummyEntity(); - $args = $this->getMockBuilder('Doctrine\ODM\MongoDB\Event\LifecycleEventArgs') + $args = $this->getMockBuilder(LifecycleEventArgs::class) ->disableOriginalConstructor() ->getMock(); $args diff --git a/Tests/Adapter/ORM/DoctrineORMAdapterTest.php b/Tests/Adapter/ORM/DoctrineORMAdapterTest.php index e44b0bd4..3a9ac1d1 100644 --- a/Tests/Adapter/ORM/DoctrineORMAdapterTest.php +++ b/Tests/Adapter/ORM/DoctrineORMAdapterTest.php @@ -2,6 +2,7 @@ namespace Vich\UploaderBundle\Tests\Adapter\ORM; +use Doctrine\ORM\Event\LifecycleEventArgs; use PHPUnit\Framework\TestCase; use Vich\UploaderBundle\Adapter\ORM\DoctrineORMAdapter; use Vich\UploaderBundle\Tests\DummyEntity; @@ -15,7 +16,7 @@ class DoctrineORMAdapterTest extends TestCase { public static function setUpBeforeClass(): void { - if (!class_exists('Doctrine\ORM\Event\LifecycleEventArgs')) { + if (!\class_exists(LifecycleEventArgs::class)) { self::markTestSkipped('Doctrine\ORM\Event\LifecycleEventArgs does not exist.'); } } @@ -27,7 +28,7 @@ public function testGetObjectFromArgs(): void { $entity = new DummyEntity(); - $args = $this->getMockBuilder('Doctrine\ORM\Event\LifecycleEventArgs') + $args = $this->getMockBuilder(LifecycleEventArgs::class) ->disableOriginalConstructor() ->getMock(); $args diff --git a/Tests/Adapter/PHPCR/PHPCRAdapterTest.php b/Tests/Adapter/PHPCR/PHPCRAdapterTest.php index 7f5161d2..11dbca51 100644 --- a/Tests/Adapter/PHPCR/PHPCRAdapterTest.php +++ b/Tests/Adapter/PHPCR/PHPCRAdapterTest.php @@ -14,7 +14,7 @@ class PHPCRAdapterTest extends TestCase { public static function setUpBeforeClass(): void { - if (!class_exists(LifecycleEventArgs::class)) { + if (!\class_exists(LifecycleEventArgs::class)) { self::markTestSkipped('Doctrine\Common\Persistence\Event\LifecycleEventArgs does not exist.'); } } diff --git a/Tests/Adapter/Propel/PropelORMAdapterTest.php b/Tests/Adapter/Propel/PropelORMAdapterTest.php index 68231396..1e4b434a 100644 --- a/Tests/Adapter/Propel/PropelORMAdapterTest.php +++ b/Tests/Adapter/Propel/PropelORMAdapterTest.php @@ -3,6 +3,7 @@ namespace Vich\UploaderBundle\Tests\Adapter\Propel; use PHPUnit\Framework\TestCase; +use Symfony\Component\EventDispatcher\GenericEvent; use Vich\UploaderBundle\Adapter\Propel\PropelORMAdapter; /** @@ -16,7 +17,7 @@ class PropelORMAdapterTest extends TestCase public static function setUpBeforeClass(): void { - if (!class_exists('Symfony\Component\EventDispatcher\GenericEvent')) { + if (!\class_exists(GenericEvent::class)) { self::markTestSkipped('Symfony\Component\EventDispatcher\GenericEvent does not exist.'); } } @@ -28,7 +29,7 @@ protected function setUp(): void public function testGetObjectFromArgs(): void { - $event = $this->createMock('\Symfony\Component\EventDispatcher\GenericEvent'); + $event = $this->createMock(GenericEvent::class); $event ->expects($this->once()) ->method('getSubject') @@ -39,7 +40,7 @@ public function testGetObjectFromArgs(): void public function testRecomputeChangeset(): void { - $event = $this->createMock('\Symfony\Component\EventDispatcher\GenericEvent'); + $event = $this->createMock(GenericEvent::class); // does nothing but should be callable $this->adapter->recomputeChangeSet($event); diff --git a/Tests/DependencyInjection/VichUploaderExtensionTest.php b/Tests/DependencyInjection/VichUploaderExtensionTest.php index 40a6b0cf..32b12aa4 100644 --- a/Tests/DependencyInjection/VichUploaderExtensionTest.php +++ b/Tests/DependencyInjection/VichUploaderExtensionTest.php @@ -5,6 +5,8 @@ use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension; use Vich\UploaderBundle\DependencyInjection\VichUploaderExtension; +use Vich\UploaderBundle\Storage\FlysystemStorage; +use Vich\UploaderBundle\Twig\Extension\UploaderExtension; class VichUploaderExtensionTest extends AbstractExtensionTestCase { @@ -30,7 +32,7 @@ protected function setUp(): void $this->container->setParameter('kernel.bundles_metadata', []); $this->container->setParameter('kernel.root_dir', __DIR__.'/../Fixtures/App/app'); $this->container->setParameter('kernel.project_dir', __DIR__.'/../Fixtures/App'); - $this->container->setParameter('kernel.cache_dir', sys_get_temp_dir()); + $this->container->setParameter('kernel.cache_dir', \sys_get_temp_dir()); $this->container->setParameter('kernel.debug', true); } @@ -59,8 +61,8 @@ public function testExtraServiceFilesAreLoaded(): void 'storage' => 'flysystem', ]); - $this->assertContainerBuilderHasService('vich_uploader.storage.flysystem', 'Vich\UploaderBundle\Storage\FlysystemStorage'); - $this->assertContainerBuilderHasService('vich_uploader.twig.extension.uploader', 'Vich\UploaderBundle\Twig\Extension\UploaderExtension'); + $this->assertContainerBuilderHasService('vich_uploader.storage.flysystem', FlysystemStorage::class); + $this->assertContainerBuilderHasService('vich_uploader.twig.extension.uploader', UploaderExtension::class); } public function testMappingsServiceParameterIsSet(): void diff --git a/Tests/EventListener/Doctrine/CleanListenerTest.php b/Tests/EventListener/Doctrine/CleanListenerTest.php index 3ad9889a..5d205743 100644 --- a/Tests/EventListener/Doctrine/CleanListenerTest.php +++ b/Tests/EventListener/Doctrine/CleanListenerTest.php @@ -3,6 +3,7 @@ namespace Vich\UploaderBundle\Tests\EventListener\Doctrine; use Vich\UploaderBundle\EventListener\Doctrine\CleanListener; +use Vich\UploaderBundle\Tests\DummyEntity; /** * Doctrine CleanListener test. @@ -39,13 +40,13 @@ public function testPreUpdate(): void $this->metadata ->expects($this->once()) ->method('isUploadable') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(true)); $this->metadata ->expects($this->once()) ->method('getUploadableFields') - ->with('Vich\UploaderBundle\Tests\DummyEntity', self::MAPPING_NAME) + ->with(DummyEntity::class, self::MAPPING_NAME) ->will($this->returnValue([ ['propertyName' => 'field_name'], ])); @@ -71,7 +72,7 @@ public function testPreUpdateSkipsNonUploadable(): void $this->metadata ->expects($this->once()) ->method('isUploadable') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(false)); $this->handler diff --git a/Tests/EventListener/Doctrine/InjectListenerTest.php b/Tests/EventListener/Doctrine/InjectListenerTest.php index 7753f4be..07a26d50 100644 --- a/Tests/EventListener/Doctrine/InjectListenerTest.php +++ b/Tests/EventListener/Doctrine/InjectListenerTest.php @@ -3,6 +3,7 @@ namespace Vich\UploaderBundle\Tests\EventListener\Doctrine; use Vich\UploaderBundle\EventListener\Doctrine\InjectListener; +use Vich\UploaderBundle\Tests\DummyEntity; /** * Doctrine InjectListener test. @@ -39,13 +40,13 @@ public function testPostLoad(): void $this->metadata ->expects($this->once()) ->method('isUploadable') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(true)); $this->metadata ->expects($this->once()) ->method('getUploadableFields') - ->with('Vich\UploaderBundle\Tests\DummyEntity', self::MAPPING_NAME) + ->with(DummyEntity::class, self::MAPPING_NAME) ->will($this->returnValue([ ['propertyName' => 'field_name'], ])); @@ -66,7 +67,7 @@ public function testPostLoadSkipsNonUploadable(): void $this->metadata ->expects($this->once()) ->method('isUploadable') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(false)); $this->handler diff --git a/Tests/EventListener/Doctrine/ListenerTestCase.php b/Tests/EventListener/Doctrine/ListenerTestCase.php index 5308a78b..33ab5c91 100644 --- a/Tests/EventListener/Doctrine/ListenerTestCase.php +++ b/Tests/EventListener/Doctrine/ListenerTestCase.php @@ -75,7 +75,7 @@ protected function setUp(): void */ protected function getAdapterMock() { - return $this->createMock('Vich\UploaderBundle\Adapter\AdapterInterface'); + return $this->createMock(AdapterInterface::class); } /** @@ -85,7 +85,7 @@ protected function getAdapterMock() */ protected function getMetadataReaderMock() { - return $this->getMockBuilder('Vich\UploaderBundle\Metadata\MetadataReader') + return $this->getMockBuilder(MetadataReader::class) ->disableOriginalConstructor() ->getMock(); } @@ -97,7 +97,7 @@ protected function getMetadataReaderMock() */ protected function getHandlerMock() { - return $this->getMockBuilder('Vich\UploaderBundle\Handler\UploadHandler') + return $this->getMockBuilder(UploadHandler::class) ->disableOriginalConstructor() ->getMock(); } @@ -109,7 +109,7 @@ protected function getHandlerMock() */ protected function getEventMock() { - return $this->getMockBuilder('Doctrine\Common\EventArgs') + return $this->getMockBuilder(EventArgs::class) ->disableOriginalConstructor() ->getMock(); } diff --git a/Tests/EventListener/Doctrine/RemoveListenerTest.php b/Tests/EventListener/Doctrine/RemoveListenerTest.php index 2c0d10f3..2be0cc02 100644 --- a/Tests/EventListener/Doctrine/RemoveListenerTest.php +++ b/Tests/EventListener/Doctrine/RemoveListenerTest.php @@ -4,6 +4,7 @@ use Doctrine\Common\Persistence\Proxy; use Vich\UploaderBundle\EventListener\Doctrine\RemoveListener; +use Vich\UploaderBundle\Tests\DummyEntity; /** * Doctrine RemoveListener test. @@ -72,13 +73,13 @@ public function testPostRemove(): void $this->metadata ->expects($this->once()) ->method('isUploadable') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(true)); $this->metadata ->expects($this->once()) ->method('getUploadableFields') - ->with('Vich\UploaderBundle\Tests\DummyEntity', self::MAPPING_NAME) + ->with(DummyEntity::class, self::MAPPING_NAME) ->will($this->returnValue([ ['propertyName' => 'field_name'], ])); @@ -99,7 +100,7 @@ public function testPostRemoveSkipsNonUploadable(): void $this->metadata ->expects($this->once()) ->method('isUploadable') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(false)); $this->handler @@ -116,7 +117,7 @@ public function testPostRemoveSkipsNonUploadable(): void */ protected function getEntityProxyMock() { - return $this->getMockBuilder('Doctrine\Common\Persistence\Proxy') + return $this->getMockBuilder(Proxy::class) ->setMockClassName('VichUploaderEntityProxy') ->getMock(); } diff --git a/Tests/EventListener/Doctrine/UploadListenerTest.php b/Tests/EventListener/Doctrine/UploadListenerTest.php index 6f3d239c..ff5963ed 100644 --- a/Tests/EventListener/Doctrine/UploadListenerTest.php +++ b/Tests/EventListener/Doctrine/UploadListenerTest.php @@ -3,6 +3,7 @@ namespace Vich\UploaderBundle\Tests\EventListener\Doctrine; use Vich\UploaderBundle\EventListener\Doctrine\UploadListener; +use Vich\UploaderBundle\Tests\DummyEntity; /** * Doctrine UploadListener test. @@ -39,13 +40,13 @@ public function testPrePersist(): void $this->metadata ->expects($this->once()) ->method('isUploadable') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(true)); $this->metadata ->expects($this->once()) ->method('getUploadableFields') - ->with('Vich\UploaderBundle\Tests\DummyEntity', self::MAPPING_NAME) + ->with(DummyEntity::class, self::MAPPING_NAME) ->will($this->returnValue([ ['propertyName' => 'field_name'], ])); @@ -66,7 +67,7 @@ public function testPrePersistSkipsNonUploadable(): void $this->metadata ->expects($this->once()) ->method('isUploadable') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(false)); $this->handler @@ -89,13 +90,13 @@ public function testPreUpdate(): void $this->metadata ->expects($this->once()) ->method('isUploadable') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(true)); $this->metadata ->expects($this->once()) ->method('getUploadableFields') - ->with('Vich\UploaderBundle\Tests\DummyEntity', self::MAPPING_NAME) + ->with(DummyEntity::class, self::MAPPING_NAME) ->will($this->returnValue([ ['propertyName' => 'field_name'], ])); @@ -116,7 +117,7 @@ public function testPreUpdateSkipsNonUploadable(): void $this->metadata ->expects($this->once()) ->method('isUploadable') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(false)); $this->adapter diff --git a/Tests/EventListener/Propel/ListenerTestCase.php b/Tests/EventListener/Propel/ListenerTestCase.php index 89a74126..845fe9a5 100644 --- a/Tests/EventListener/Propel/ListenerTestCase.php +++ b/Tests/EventListener/Propel/ListenerTestCase.php @@ -71,7 +71,7 @@ protected function setUp(): void $this->metadata ->expects($this->any()) ->method('getUploadableFields') - ->with('Vich\UploaderBundle\Tests\DummyEntity', self::MAPPING_NAME) + ->with(DummyEntity::class, self::MAPPING_NAME) ->will($this->returnValue([ ['propertyName' => self::FIELD_NAME], ])); @@ -84,7 +84,7 @@ protected function setUp(): void */ protected function getAdapterMock() { - return $this->createMock('Vich\UploaderBundle\Adapter\AdapterInterface'); + return $this->createMock(AdapterInterface::class); } /** @@ -94,7 +94,7 @@ protected function getAdapterMock() */ protected function getHandlerMock() { - return $this->getMockBuilder('Vich\UploaderBundle\Handler\UploadHandler') + return $this->getMockBuilder(UploadHandler::class) ->disableOriginalConstructor() ->getMock(); } @@ -106,7 +106,7 @@ protected function getHandlerMock() */ protected function getEventMock() { - return $this->getMockBuilder('\Symfony\Component\EventDispatcher\GenericEvent') + return $this->getMockBuilder(GenericEvent::class) ->disableOriginalConstructor() ->getMock(); } @@ -118,7 +118,7 @@ protected function getEventMock() */ protected function getMetadataReaderMock() { - return $this->getMockBuilder('Vich\UploaderBundle\Metadata\MetadataReader') + return $this->getMockBuilder(MetadataReader::class) ->disableOriginalConstructor() ->getMock(); } diff --git a/Tests/Fixtures/App/app/AppKernel.php b/Tests/Fixtures/App/app/AppKernel.php index 3922cdfb..343cf115 100644 --- a/Tests/Fixtures/App/app/AppKernel.php +++ b/Tests/Fixtures/App/app/AppKernel.php @@ -24,11 +24,11 @@ public function registerContainerConfiguration(LoaderInterface $loader): void public function getCacheDir(): string { - return sys_get_temp_dir().'/VichUploaderBundle/cache'; + return \sys_get_temp_dir().'/VichUploaderBundle/cache'; } public function getLogDir(): string { - return sys_get_temp_dir().'/VichUploaderBundle/logs'; + return \sys_get_temp_dir().'/VichUploaderBundle/logs'; } } diff --git a/Tests/Form/Type/VichImageTypeTest.php b/Tests/Form/Type/VichImageTypeTest.php index 46e6d9fd..dba3adb7 100644 --- a/Tests/Form/Type/VichImageTypeTest.php +++ b/Tests/Form/Type/VichImageTypeTest.php @@ -136,7 +136,7 @@ public function buildViewDataProvider(): array public function testLiipImagineBundleIntegration(): void { - if (!class_exists(CacheManager::class)) { + if (!\class_exists(CacheManager::class)) { $this->markTestSkipped('LiipImagineBundle is not installed.'); } diff --git a/Tests/Functional/WebTestCase.php b/Tests/Functional/WebTestCase.php index 12aafbcc..47630185 100644 --- a/Tests/Functional/WebTestCase.php +++ b/Tests/Functional/WebTestCase.php @@ -21,8 +21,7 @@ protected function getUploadedFile($client, $name, $mimeType = 'image/png') return new UploadedFile( $this->getImagesDir($client).\DIRECTORY_SEPARATOR.$name, $name, - $mimeType, - 123 + $mimeType ); } diff --git a/Tests/Handler/DownloadHandlerTest.php b/Tests/Handler/DownloadHandlerTest.php index ccc26362..fd1ad992 100644 --- a/Tests/Handler/DownloadHandlerTest.php +++ b/Tests/Handler/DownloadHandlerTest.php @@ -87,7 +87,7 @@ public function testDownloadObject($fileName, $expectedFileName): void $response = $this->handler->downloadObject($this->object, 'file_field'); $this->assertInstanceOf(StreamedResponse::class, $response); - $this->assertRegexp(sprintf('/attachment; filename=["]{0,1}%s["]{0,1}/', $expectedFileName), $response->headers->get('Content-Disposition')); + $this->assertRegexp(\sprintf('/attachment; filename=["]{0,1}%s["]{0,1}/', $expectedFileName), $response->headers->get('Content-Disposition')); } /** @@ -123,7 +123,7 @@ public function testDisplayObject($fileName, $expectedFileName): void $response = $this->handler->downloadObject($this->object, 'file_field', null, null, false); $this->assertInstanceOf(StreamedResponse::class, $response); - $this->assertRegexp(sprintf('/inline; filename=["]{0,1}%s["]{0,1}/', $expectedFileName), $response->headers->get('Content-Disposition')); + $this->assertRegexp(\sprintf('/inline; filename=["]{0,1}%s["]{0,1}/', $expectedFileName), $response->headers->get('Content-Disposition')); } /** @@ -152,7 +152,7 @@ public function testDownloadObjectWithoutFile($fileName, $expectedFileName): voi $response = $this->handler->downloadObject($this->object, 'file_field'); $this->assertInstanceOf(StreamedResponse::class, $response); - $this->assertRegexp(sprintf('/attachment; filename=["]{0,1}%s["]{0,1}/', $expectedFileName), $response->headers->get('Content-Disposition')); + $this->assertRegexp(\sprintf('/attachment; filename=["]{0,1}%s["]{0,1}/', $expectedFileName), $response->headers->get('Content-Disposition')); } public function testDownloadObjectCallOriginalName(): void @@ -188,7 +188,7 @@ public function testDownloadObjectCallOriginalName(): void $this->assertInstanceOf(StreamedResponse::class, $response); $expectedFileName = $this->object->getImageOriginalName(); - $this->assertRegexp(sprintf('/attachment; filename=["]{0,1}%s["]{0,1}/', $expectedFileName), $response->headers->get('Content-Disposition')); + $this->assertRegexp(\sprintf('/attachment; filename=["]{0,1}%s["]{0,1}/', $expectedFileName), $response->headers->get('Content-Disposition')); } public function testNonAsciiFilenameIsTransliterated(): void diff --git a/Tests/Handler/UploadHandlerTest.php b/Tests/Handler/UploadHandlerTest.php index 2efb0710..c0baddbc 100644 --- a/Tests/Handler/UploadHandlerTest.php +++ b/Tests/Handler/UploadHandlerTest.php @@ -2,10 +2,13 @@ namespace Vich\UploaderBundle\Tests\Handler; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Vich\TestBundle\Entity\Article; use Vich\UploaderBundle\Event\Event; use Vich\UploaderBundle\Event\Events; use Vich\UploaderBundle\Handler\UploadHandler; +use Vich\UploaderBundle\Injector\FileInjectorInterface; +use Vich\UploaderBundle\Storage\StorageInterface; use Vich\UploaderBundle\Tests\TestCase; /** @@ -207,17 +210,17 @@ public function testRemoveWithEmptyObject(): void protected function getStorageMock() { - return $this->createMock('Vich\UploaderBundle\Storage\StorageInterface'); + return $this->createMock(StorageInterface::class); } protected function getInjectorMock() { - return $this->createMock('Vich\UploaderBundle\Injector\FileInjectorInterface'); + return $this->createMock(FileInjectorInterface::class); } protected function getDispatcherMock() { - return $this->createMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); + return $this->createMock(EventDispatcherInterface::class); } protected function validEvent() diff --git a/Tests/Injector/FileInjectorTest.php b/Tests/Injector/FileInjectorTest.php index 2877188c..e5f92b34 100644 --- a/Tests/Injector/FileInjectorTest.php +++ b/Tests/Injector/FileInjectorTest.php @@ -3,8 +3,10 @@ namespace Vich\UploaderBundle\Tests\Injector; use PHPUnit\Framework\TestCase; -use Symfony\Component\HttpFoundation\File\File; use Vich\UploaderBundle\Injector\FileInjector; +use Vich\UploaderBundle\Mapping\PropertyMapping; +use Vich\UploaderBundle\Storage\GaufretteStorage; +use Vich\UploaderBundle\Tests\DummyEntity; /** * FileInjectorTest. @@ -31,9 +33,9 @@ protected function setUp(): void */ public function testInjectsOneFile(): void { - $obj = $this->createMock('Vich\UploaderBundle\Tests\DummyEntity'); + $obj = $this->createMock(DummyEntity::class); - $fileMapping = $this->getMockBuilder('Vich\UploaderBundle\Mapping\PropertyMapping') + $fileMapping = $this->getMockBuilder(PropertyMapping::class) ->disableOriginalConstructor() ->getMock(); $fileMapping @@ -60,9 +62,9 @@ public function testInjectsOneFile(): void */ public function testPropertyIsNullWhenFileNamePropertyIsNull(): void { - $obj = $this->createMock('Vich\UploaderBundle\Tests\DummyEntity'); + $obj = $this->createMock(DummyEntity::class); - $fileMapping = $this->getMockBuilder('Vich\UploaderBundle\Mapping\PropertyMapping') + $fileMapping = $this->getMockBuilder(PropertyMapping::class) ->disableOriginalConstructor() ->getMock(); @@ -82,7 +84,7 @@ public function testPropertyIsNullWhenFileNamePropertyIsNull(): void */ protected function getMockStorage() { - return $this->getMockBuilder('Vich\UploaderBundle\Storage\GaufretteStorage') + return $this->getMockBuilder(GaufretteStorage::class) ->disableOriginalConstructor() ->getMock(); } diff --git a/Tests/Mapping/PropertyMappingFactoryTest.php b/Tests/Mapping/PropertyMappingFactoryTest.php index 1d07aa68..a99df3c0 100644 --- a/Tests/Mapping/PropertyMappingFactoryTest.php +++ b/Tests/Mapping/PropertyMappingFactoryTest.php @@ -2,10 +2,13 @@ namespace Vich\UploaderBundle\Tests\Mapping; +use Doctrine\Common\Persistence\Proxy; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerInterface; use Vich\UploaderBundle\Mapping\PropertyMappingFactory; use Vich\UploaderBundle\Metadata\MetadataReader; +use Vich\UploaderBundle\Naming\DirectoryNamerInterface; +use Vich\UploaderBundle\Naming\NamerInterface; use Vich\UploaderBundle\Tests\DummyEntity; /** @@ -87,7 +90,7 @@ public function testFromObjectOneField($object, $givenClassName, $expectedClassN $this->assertCount(1, $mappings); - $mapping = current($mappings); + $mapping = \current($mappings); $this->assertEquals('dummy_file', $mapping->getMappingName()); $this->assertEquals('images', $mapping->getUploadDestination()); @@ -98,13 +101,13 @@ public function testFromObjectOneField($object, $givenClassName, $expectedClassN public function fromObjectProvider(): array { $obj = new DummyEntity(); - $proxy = $this->createMock('Doctrine\Common\Persistence\Proxy'); + $proxy = $this->createMock(Proxy::class); return [ - [$obj, null, 'Vich\UploaderBundle\Tests\DummyEntity'], - [$obj, 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity'], - [$proxy, 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity'], - [[], 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity'], + [$obj, null, DummyEntity::class], + [$obj, DummyEntity::class, DummyEntity::class], + [$proxy, DummyEntity::class, DummyEntity::class], + [[], DummyEntity::class, DummyEntity::class], ]; } @@ -131,13 +134,13 @@ public function testFromObjectOneFieldWithNoExplicitFilenameProperty(): void $this->metadata ->expects($this->once()) ->method('isUploadable') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(true)); $this->metadata ->expects($this->once()) ->method('getUploadableFields') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue([ 'file' => [ 'mapping' => 'dummy_file', @@ -150,7 +153,7 @@ public function testFromObjectOneFieldWithNoExplicitFilenameProperty(): void $this->assertCount(1, $mappings); - $mapping = current($mappings); + $mapping = \current($mappings); $this->assertEquals('dummy_file', $mapping->getMappingName()); $this->assertEquals('images', $mapping->getUploadDestination()); @@ -177,13 +180,13 @@ public function testFromObjectWithExplicitMapping(): void $this->metadata ->expects($this->once()) ->method('isUploadable') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(true)); $this->metadata ->expects($this->once()) ->method('getUploadableFields') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue([ 'file' => [ 'mapping' => 'dummy_file', @@ -204,7 +207,7 @@ public function testFromObjectWithExplicitMapping(): void $this->assertCount(1, $mappings); - $mapping = current($mappings); + $mapping = \current($mappings); $this->assertEquals('other_mapping', $mapping->getMappingName()); } @@ -224,13 +227,13 @@ public function testThrowsExceptionOnInvalidMappingName(): void $this->metadata ->expects($this->once()) ->method('isUploadable') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(true)); $this->metadata ->expects($this->once()) ->method('getUploadableFields') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue([ 'file' => [ 'mapping' => 'dummy_file', @@ -282,13 +285,13 @@ public function testFromField($object, $className, $expectedClassName): void public function fromFieldProvider(): array { $obj = new DummyEntity(); - $proxy = $this->createMock('Doctrine\Common\Persistence\Proxy'); + $proxy = $this->createMock(Proxy::class); return [ - [$obj, null, 'Vich\UploaderBundle\Tests\DummyEntity'], - [$obj, 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity'], - [$proxy, 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity'], - [[], 'Vich\UploaderBundle\Tests\DummyEntity', 'Vich\UploaderBundle\Tests\DummyEntity'], + [$obj, null, DummyEntity::class], + [$obj, DummyEntity::class, DummyEntity::class], + [$proxy, DummyEntity::class, DummyEntity::class], + [[], DummyEntity::class, DummyEntity::class], ]; } @@ -301,13 +304,13 @@ public function testFromFieldReturnsNullOnInvalidFieldName(): void $this->metadata ->expects($this->once()) ->method('isUploadable') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(true)); $this->metadata ->expects($this->once()) ->method('getUploadableField') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(null)); $factory = new PropertyMappingFactory($this->container, $this->metadata, []); @@ -328,13 +331,13 @@ public function testCustomFileNameProperty(): void $this->metadata ->expects($this->once()) ->method('isUploadable') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(true)); $this->metadata ->expects($this->once()) ->method('getUploadableField') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue([ 'mapping' => 'dummy_file', 'propertyName' => 'file', @@ -356,8 +359,8 @@ public function testConfiguredNamersAreRetrievedFromContainer(): void ], ]; - $namer = $this->createMock('Vich\UploaderBundle\Naming\NamerInterface'); - $directoryNamer = $this->createMock('Vich\UploaderBundle\Naming\DirectoryNamerInterface'); + $namer = $this->createMock(NamerInterface::class); + $directoryNamer = $this->createMock(DirectoryNamerInterface::class); $this->container ->method('get') @@ -369,13 +372,13 @@ public function testConfiguredNamersAreRetrievedFromContainer(): void $this->metadata ->expects($this->once()) ->method('isUploadable') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue(true)); $this->metadata ->expects($this->once()) ->method('getUploadableFields') - ->with('Vich\UploaderBundle\Tests\DummyEntity') + ->with(DummyEntity::class) ->will($this->returnValue([ 'file' => [ 'mapping' => 'dummy_file', @@ -389,7 +392,7 @@ public function testConfiguredNamersAreRetrievedFromContainer(): void $this->assertCount(1, $mappings); - $mapping = current($mappings); + $mapping = \current($mappings); $this->assertEquals($namer, $mapping->getNamer()); $this->assertTrue($mapping->hasNamer()); @@ -404,7 +407,7 @@ public function testConfiguredNamersAreRetrievedFromContainer(): void */ protected function getContainerMock() { - return $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface'); + return $this->createMock(ContainerInterface::class); } /** @@ -414,7 +417,7 @@ protected function getContainerMock() */ protected function getMetadataReaderMock() { - return $this->getMockBuilder('Vich\UploaderBundle\Metadata\MetadataReader') + return $this->getMockBuilder(MetadataReader::class) ->disableOriginalConstructor() ->getMock(); } diff --git a/Tests/Mapping/PropertyMappingTest.php b/Tests/Mapping/PropertyMappingTest.php index 62c811e8..3f314e7b 100644 --- a/Tests/Mapping/PropertyMappingTest.php +++ b/Tests/Mapping/PropertyMappingTest.php @@ -4,6 +4,7 @@ use Vich\TestBundle\Entity\Article; use Vich\UploaderBundle\Mapping\PropertyMapping; +use Vich\UploaderBundle\Naming\DirectoryNamerInterface; use Vich\UploaderBundle\Naming\NamerInterface; use Vich\UploaderBundle\Tests\DummyEntity; use Vich\UploaderBundle\Tests\TestCase; @@ -44,7 +45,7 @@ public function testDirectoryNamerIsCalled($dir, $expectedDir): void 'upload_destination' => '/tmp', ]); - $namer = $this->createMock('Vich\UploaderBundle\Naming\DirectoryNamerInterface'); + $namer = $this->createMock(DirectoryNamerInterface::class); $namer ->expects($this->once()) ->method('directoryName') diff --git a/Tests/Metadata/ClassMetadataTest.php b/Tests/Metadata/ClassMetadataTest.php index 56ecd1de..180e44c8 100644 --- a/Tests/Metadata/ClassMetadataTest.php +++ b/Tests/Metadata/ClassMetadataTest.php @@ -13,7 +13,7 @@ public function testFieldsAreSerialized(): void $metadata = new ClassMetadata('DateTime'); $metadata->fields = $fields; - $deserializedMetadata = unserialize(serialize($metadata)); + $deserializedMetadata = \unserialize(\serialize($metadata)); $this->assertSame($fields, $deserializedMetadata->fields); } diff --git a/Tests/Metadata/Driver/AnnotationDriverTest.php b/Tests/Metadata/Driver/AnnotationDriverTest.php index 55fc6f73..545761ba 100644 --- a/Tests/Metadata/Driver/AnnotationDriverTest.php +++ b/Tests/Metadata/Driver/AnnotationDriverTest.php @@ -2,6 +2,8 @@ namespace Vich\UploaderBundle\Tests\Metadata\Driver; +use Doctrine\Common\Annotations\Reader; +use Metadata\ClassMetadata; use PHPUnit\Framework\TestCase; use Vich\TestBundle\Entity\Article; use Vich\UploaderBundle\Mapping\Annotation\UploadableField; @@ -19,7 +21,7 @@ public function testReadUploadableAnnotation(): void { $entity = new DummyEntity(); - $reader = $this->createMock('Doctrine\Common\Annotations\Reader'); + $reader = $this->createMock(Reader::class); $reader ->expects($this->once()) ->method('getClassAnnotation') @@ -35,7 +37,7 @@ public function testReadUploadableAnnotation(): void $driver = new AnnotationDriver($reader); $metadata = $driver->loadMetadataForClass(new \ReflectionClass($entity)); - $this->assertInstanceOf('\Vich\UploaderBundle\Metadata\ClassMetadata', $metadata); + $this->assertInstanceOf(ClassMetadata::class, $metadata); $this->assertObjectHasAttribute('fields', $metadata); $this->assertEquals([ 'file' => [ @@ -54,7 +56,7 @@ public function testReadUploadableAnnotationReturnsNullWhenNonePresent(): void { $entity = new DummyEntity(); - $reader = $this->createMock('Doctrine\Common\Annotations\Reader'); + $reader = $this->createMock(Reader::class); $reader ->expects($this->once()) ->method('getClassAnnotation') @@ -73,7 +75,7 @@ public function testReadTwoUploadableFields(): void { $entity = new Article(); - $reader = $this->createMock('Doctrine\Common\Annotations\Reader'); + $reader = $this->createMock(Reader::class); $reader ->expects($this->once()) ->method('getClassAnnotation') @@ -126,7 +128,7 @@ public function testReadNoUploadableFieldsWhenNoneExist(): void { $entity = new DummyEntity(); - $reader = $this->createMock('Doctrine\Common\Annotations\Reader'); + $reader = $this->createMock(Reader::class); $reader ->expects($this->once()) ->method('getClassAnnotation') diff --git a/Tests/Metadata/MetadataReaderTest.php b/Tests/Metadata/MetadataReaderTest.php index 0a7dedfb..ed95ef21 100644 --- a/Tests/Metadata/MetadataReaderTest.php +++ b/Tests/Metadata/MetadataReaderTest.php @@ -2,6 +2,7 @@ namespace Vich\UploaderBundle\Tests\Metadata; +use Metadata\AdvancedMetadataFactoryInterface; use PHPUnit\Framework\TestCase; use Vich\UploaderBundle\Metadata\MetadataReader; @@ -13,7 +14,7 @@ class MetadataReaderTest extends TestCase protected function setUp(): void { - $this->factory = $this->createMock('Metadata\AdvancedMetadataFactoryInterface'); + $this->factory = $this->createMock(AdvancedMetadataFactoryInterface::class); $this->reader = new MetadataReader($this->factory); } diff --git a/Tests/Naming/CurrentDateTimeDirectoryNamerTest.php b/Tests/Naming/CurrentDateTimeDirectoryNamerTest.php index a2b0be06..55f3d2bd 100644 --- a/Tests/Naming/CurrentDateTimeDirectoryNamerTest.php +++ b/Tests/Naming/CurrentDateTimeDirectoryNamerTest.php @@ -30,7 +30,7 @@ public function directoryNameDataProvider(): array * @dataProvider directoryNameDataProvider * * @param int $timestamp - * @param null|string $dateTimeFormat + * @param string|null $dateTimeFormat * @param string $expectedName */ public function testNameReturnsTheRightName(int $timestamp, ?string $dateTimeFormat, string $expectedName): void diff --git a/Tests/Naming/OrignameNamerTest.php b/Tests/Naming/OrignameNamerTest.php index 4d9b0e42..e1b4c766 100644 --- a/Tests/Naming/OrignameNamerTest.php +++ b/Tests/Naming/OrignameNamerTest.php @@ -2,6 +2,7 @@ namespace Vich\UploaderBundle\Tests\Naming; +use Vich\UploaderBundle\Mapping\PropertyMapping; use Vich\UploaderBundle\Naming\OrignameNamer; use Vich\UploaderBundle\Tests\TestCase; @@ -34,7 +35,7 @@ public function testNameReturnsAnUniqueName($name, $pattern, $transliterate): vo $entity = new \DateTime(); - $mapping = $this->getMockBuilder('Vich\UploaderBundle\Mapping\PropertyMapping') + $mapping = $this->getMockBuilder(PropertyMapping::class) ->disableOriginalConstructor() ->getMock(); $mapping->expects($this->once()) diff --git a/Tests/Naming/UniqidNamerTest.php b/Tests/Naming/UniqidNamerTest.php index 2439cbb9..cbeec6e8 100644 --- a/Tests/Naming/UniqidNamerTest.php +++ b/Tests/Naming/UniqidNamerTest.php @@ -2,6 +2,7 @@ namespace Vich\UploaderBundle\Tests\Naming; +use Vich\UploaderBundle\Mapping\PropertyMapping; use Vich\UploaderBundle\Naming\UniqidNamer; use Vich\UploaderBundle\Tests\TestCase; @@ -40,7 +41,7 @@ public function testNameReturnsAnUniqueName($originalName, $guessedExtension, $p $entity = new \DateTime(); - $mapping = $this->getMockBuilder('Vich\UploaderBundle\Mapping\PropertyMapping') + $mapping = $this->getMockBuilder(PropertyMapping::class) ->disableOriginalConstructor() ->getMock(); $mapping->expects($this->once()) diff --git a/Tests/Storage/FileSystemStorageTest.php b/Tests/Storage/FileSystemStorageTest.php index f74ca9ba..47357eb8 100644 --- a/Tests/Storage/FileSystemStorageTest.php +++ b/Tests/Storage/FileSystemStorageTest.php @@ -99,7 +99,7 @@ public function testResolvePath(): void $path = $this->storage->resolvePath($this->object, 'file_field'); - $this->assertEquals(sprintf('/tmp%sfile.txt', \DIRECTORY_SEPARATOR), $path); + $this->assertEquals(\sprintf('/tmp%sfile.txt', \DIRECTORY_SEPARATOR), $path); } /** @@ -125,7 +125,7 @@ public function testResolveRelativePath(): void $path = $this->storage->resolvePath($this->object, 'file_field', null, true); - $this->assertEquals(sprintf('upload_dir%sfile.txt', \DIRECTORY_SEPARATOR), $path); + $this->assertEquals(\sprintf('upload_dir%sfile.txt', \DIRECTORY_SEPARATOR), $path); } public function testResolveUriReturnsNullIfNoFile(): void diff --git a/Tests/Storage/FlysystemStorageTest.php b/Tests/Storage/FlysystemStorageTest.php index 61f5b280..34781297 100644 --- a/Tests/Storage/FlysystemStorageTest.php +++ b/Tests/Storage/FlysystemStorageTest.php @@ -28,7 +28,7 @@ class FlysystemStorageTest extends StorageTestCase public static function setUpBeforeClass(): void { - if (!class_exists('League\Flysystem\MountManager')) { + if (!\class_exists(MountManager::class)) { self::markTestSkipped('Flysystem is not installed.'); } } @@ -41,7 +41,7 @@ protected function getStorage(): StorageInterface protected function setUp(): void { $this->mountManager = $this->getMountManagerMock(); - $this->filesystem = $this->createMock('League\Flysystem\FilesystemInterface'); + $this->filesystem = $this->createMock(FilesystemInterface::class); $this->mountManager ->expects($this->any()) @@ -180,7 +180,7 @@ public function pathProvider(): array protected function getMountManagerMock() { return $this - ->getMockBuilder('League\Flysystem\MountManager') + ->getMockBuilder(MountManager::class) ->disableOriginalConstructor() ->getMock(); } diff --git a/Tests/Storage/GaufretteStorageTest.php b/Tests/Storage/GaufretteStorageTest.php index 9cffa4c0..259191c5 100644 --- a/Tests/Storage/GaufretteStorageTest.php +++ b/Tests/Storage/GaufretteStorageTest.php @@ -2,6 +2,8 @@ namespace Vich\UploaderBundle\Tests\Storage; +use Gaufrette\Adapter; +use Gaufrette\Adapter\MetadataSupporter; use Gaufrette\Exception\FileNotFound; use Gaufrette\Filesystem; use Knp\Bundle\GaufretteBundle\FilesystemMap; @@ -203,7 +205,7 @@ public function testUploadSetsMetadataWhenUsingMetadataSupporterAdapter(): void { $filesystem = $this->getFilesystemMock(); $file = $this->getUploadedFileMock(); - $adapter = $this->createMock('\Gaufrette\Adapter\MetadataSupporter'); + $adapter = $this->createMock(MetadataSupporter::class); $file ->expects($this->once()) @@ -256,7 +258,7 @@ public function testUploadSetsMetadataWhenUsingMetadataSupporterAdapter(): void public function testUploadDoesNotSetMetadataWhenUsingNonMetadataSupporterAdapter(): void { - $adapter = $this->createMock('\Gaufrette\Adapter'); + $adapter = $this->createMock(Adapter::class); $filesystem = $this->getFilesystemMock(); $file = $this->getUploadedFileMock(); diff --git a/Tests/Templating/Helper/UploadHelperTest.php b/Tests/Templating/Helper/UploadHelperTest.php index 82d90dfb..239a3901 100644 --- a/Tests/Templating/Helper/UploadHelperTest.php +++ b/Tests/Templating/Helper/UploadHelperTest.php @@ -3,6 +3,7 @@ namespace Vich\UploaderBundle\Tests\Templating\Helper; use PHPUnit\Framework\TestCase; +use Vich\UploaderBundle\Storage\StorageInterface; use Vich\UploaderBundle\Templating\Helper\UploaderHelper; /** @@ -18,7 +19,7 @@ class UploadHelperTest extends TestCase protected function setUp(): void { - $this->storage = $this->createMock('Vich\UploaderBundle\Storage\StorageInterface'); + $this->storage = $this->createMock(StorageInterface::class); $this->helper = new UploaderHelper($this->storage); } diff --git a/Tests/TestCase.php b/Tests/TestCase.php index 3b663b9d..271710b3 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -12,7 +12,7 @@ class TestCase extends BaseTestCase protected function getUploadedFileMock(): UploadedFile { return $this->getMockBuilder(UploadedFile::class) - ->setConstructorArgs(['lala', 'lala', $mimeType = null, $size = null, $error = 9, $test = true]) + ->setConstructorArgs(['lala', 'lala', $mimeType = null, $error = 9, $test = true]) ->getMock(); } diff --git a/Tests/Twig/Extension/UploaderExtensionTest.php b/Tests/Twig/Extension/UploaderExtensionTest.php index 139fced5..1fe3506c 100644 --- a/Tests/Twig/Extension/UploaderExtensionTest.php +++ b/Tests/Twig/Extension/UploaderExtensionTest.php @@ -3,6 +3,7 @@ namespace Vich\UploaderBundle\Tests\Twig\Extension; use PHPUnit\Framework\TestCase; +use Vich\UploaderBundle\Templating\Helper\UploaderHelper; use Vich\UploaderBundle\Twig\Extension\UploaderExtension; /** @@ -18,7 +19,7 @@ class UploaderExtensionTest extends TestCase protected function setUp(): void { - $this->helper = $this->getMockBuilder('Vich\UploaderBundle\Templating\Helper\UploaderHelper')->disableOriginalConstructor()->getMock(); + $this->helper = $this->getMockBuilder(UploaderHelper::class)->disableOriginalConstructor()->getMock(); $this->extension = new UploaderExtension($this->helper); } diff --git a/Util/ClassUtils.php b/Util/ClassUtils.php index e1cda30e..80017b5a 100644 --- a/Util/ClassUtils.php +++ b/Util/ClassUtils.php @@ -22,7 +22,7 @@ private function __construct() */ public static function getClass($object): string { - if (class_exists(DoctrineClassUtils::class)) { + if (\class_exists(DoctrineClassUtils::class)) { return DoctrineClassUtils::getClass($object); } diff --git a/Util/FilenameUtils.php b/Util/FilenameUtils.php index 384fddfa..3ab52c0e 100644 --- a/Util/FilenameUtils.php +++ b/Util/FilenameUtils.php @@ -20,10 +20,10 @@ private function __construct() */ public static function spitNameByExtension(string $filename): array { - if (false === $pos = strrpos($filename, '.')) { + if (false === $pos = \strrpos($filename, '.')) { return [$filename, '']; } - return [substr($filename, 0, $pos), substr($filename, $pos + 1)]; + return [\substr($filename, 0, $pos), \substr($filename, $pos + 1)]; } } diff --git a/composer.json b/composer.json index c2784bfe..2e9f1e07 100644 --- a/composer.json +++ b/composer.json @@ -20,9 +20,10 @@ } }, "require": { - "php": "^7.1", + "php": "^7.2", + "ext-simplexml": "*", "behat/transliterator": "^1.2", - "jms/metadata": "^1.6", + "jms/metadata": "^2.0", "symfony/config": "^3.4|^4.0", "symfony/dependency-injection": "^3.4|^4.0", "symfony/event-dispatcher": "^3.4|^4.0", @@ -40,7 +41,7 @@ "doctrine/orm": "^2.5", "knplabs/knp-gaufrette-bundle": "^0.5", "matthiasnoback/symfony-dependency-injection-test": "^2.3|^3.0", - "mikey179/vfsStream": "^1.6", + "mikey179/vfsstream": "^1.6", "oneup/flysystem-bundle": "^3.0", "phpunit/phpunit": "^6.5|^7.0", "symfony/browser-kit": "^3.4|^4.0",