diff --git a/.gitignore b/.gitignore index 9f372e2..ab2443b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /vendor /tests/temp composer.lock -composer.phar -autoload.php +.phpcs-cache +.phpunit.result.cache diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index b7e5595..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -filter: - excluded_paths: [vendor/*, tests/*, bin/*] - -checks: - php: - code_rating: true - duplication: true - -tools: - php_cpd: true - php_pdepend: - excluded_dirs: [vendor] diff --git a/.travis.yml b/.travis.yml index 1d246cc..62d5adb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,15 @@ matrix: - php: 7.4 env: - SYMFONY_DEPRECATIONS_HELPER=weak + - php: 8.0 + env: + - SYMFONY_DEPRECATIONS_HELPER=weak before_script: - composer validate - composer update $COMPOSER_FLAGS -script: vendor/bin/phpunit +script: + - vendor/bin/phpcs + - vendor/bin/phpstan analyze -c phpstan.neon + - vendor/bin/phpunit diff --git a/composer.json b/composer.json index f6f3cc0..c14bb48 100644 --- a/composer.json +++ b/composer.json @@ -15,18 +15,23 @@ } ], "require": { - "php": ">=7.1", - "doctrine/common": "^2.5", + "php": "^7.1|^8.0", + "doctrine/common": "^2.9|^3.0", "doctrine/orm": "^2.5", - "symfony/property-access": "^2.3|^3.0|^4.0", - "symfony/yaml": "^2.2|^3.0|^4.0", + "doctrine/persistence": "^1.3|^2.0", + "symfony/property-access": "^3.0|^4.0|^5.0", + "symfony/yaml": "^3.0|^4.0|^5.0", "knplabs/gaufrette": "~0.1,>=0.1.4" }, "require-dev": { - "doctrine/dbal": "^2.5", + "ext-dom": "*", "ext-intl": "*", - "ext-sqlite3": "*", - "phpunit/phpunit": "^7.5", + "ext-pdo_sqlite": "*", + "ext-simplexml": "*", + "doctrine/dbal": "^2.5", + "phpstan/phpstan": "^0.12.26", + "phpunit/phpunit": "^7.5|^8.0", + "squizlabs/php_codesniffer": "^3.4", "symfony/phpunit-bridge": "^5.0" }, "autoload": { @@ -45,6 +50,7 @@ "extra": { "branch-alias": { "dev-master": "3.0-dev", + "2.1": "2.1-dev", "2.0": "2.0-dev", "1.2": "1.2-dev", "1.1": "1.1-dev", diff --git a/lib/FSi/DoctrineExtensions/Mapping/Driver/AbstractAnnotationDriver.php b/lib/FSi/DoctrineExtensions/Mapping/Driver/AbstractAnnotationDriver.php index dc49ebf..5d89132 100644 --- a/lib/FSi/DoctrineExtensions/Mapping/Driver/AbstractAnnotationDriver.php +++ b/lib/FSi/DoctrineExtensions/Mapping/Driver/AbstractAnnotationDriver.php @@ -12,8 +12,8 @@ namespace FSi\DoctrineExtensions\Mapping\Driver; use Doctrine\Common\Annotations\Reader; -use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\Persistence\Mapping\ClassMetadataFactory; use FSi\DoctrineExtensions\Mapping\Driver\DriverInterface; use FSi\DoctrineExtensions\Mapping\Exception\RuntimeException; use FSi\DoctrineExtensions\Metadata\ClassMetadataInterface; @@ -50,7 +50,10 @@ public function loadClassMetadata(ClassMetadataInterface $metadata): void return; } - $this->loadExtendedClassMetadata($this->getBaseMetadataFactory()->getMetadataFor($metadata->getClassName()), $metadata); + $this->loadExtendedClassMetadata( + $this->getBaseMetadataFactory()->getMetadataFor($metadata->getClassName()), + $metadata + ); } public function setAnnotationReader(Reader $reader): void diff --git a/lib/FSi/DoctrineExtensions/Mapping/Driver/AbstractFileDriver.php b/lib/FSi/DoctrineExtensions/Mapping/Driver/AbstractFileDriver.php index baed68f..a3e755b 100644 --- a/lib/FSi/DoctrineExtensions/Mapping/Driver/AbstractFileDriver.php +++ b/lib/FSi/DoctrineExtensions/Mapping/Driver/AbstractFileDriver.php @@ -11,9 +11,9 @@ namespace FSi\DoctrineExtensions\Mapping\Driver; -use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory; -use Doctrine\Common\Persistence\Mapping\Driver\FileLocator; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\Persistence\Mapping\ClassMetadataFactory; +use Doctrine\Persistence\Mapping\Driver\FileLocator; use FSi\DoctrineExtensions\Mapping\Driver\DriverInterface; use FSi\DoctrineExtensions\Mapping\Exception\RuntimeException; use FSi\DoctrineExtensions\Metadata\ClassMetadataInterface; @@ -54,7 +54,10 @@ public function loadClassMetadata(ClassMetadataInterface $metadata): void return; } - $this->loadExtendedClassMetadata($this->getBaseMetadataFactory()->getMetadataFor($metadata->getClassName()), $metadata); + $this->loadExtendedClassMetadata( + $this->getBaseMetadataFactory()->getMetadataFor($metadata->getClassName()), + $metadata + ); } public function setFileLocator(FileLocator $locator): void diff --git a/lib/FSi/DoctrineExtensions/Mapping/Driver/AbstractXmlDriver.php b/lib/FSi/DoctrineExtensions/Mapping/Driver/AbstractXmlDriver.php index 843b605..388d97a 100644 --- a/lib/FSi/DoctrineExtensions/Mapping/Driver/AbstractXmlDriver.php +++ b/lib/FSi/DoctrineExtensions/Mapping/Driver/AbstractXmlDriver.php @@ -71,7 +71,8 @@ private function validateFile(DOMDocument $dom): bool { // Schemas for validation. $schemaLocations = [ - 'http://fsi.pl/schemas/orm/doctrine-extensions-mapping' => realpath(__DIR__ . '/../../../../../doctrine-extensions-mapping.xsd'), + 'http://fsi.pl/schemas/orm/doctrine-extensions-mapping' + => dirname(__DIR__, 5) . '/doctrine-extensions-mapping.xsd', 'http://doctrine-project.org/schemas/orm/doctrine-mapping' => $this->getDoctrineSchemePath(), ]; @@ -89,7 +90,7 @@ private function validateFile(DOMDocument $dom): bool } $domNodeList = $dom->getElementsByTagNameNS($xmlns->nodeValue, '*'); - for ($i = $domNodeList->length; --$i >= 0; ) { + for ($i = $domNodeList->length; --$i >= 0;) { $element = $domNodeList->item($i); $element->parentNode->removeChild($element); } diff --git a/lib/FSi/DoctrineExtensions/Mapping/Driver/DriverChain.php b/lib/FSi/DoctrineExtensions/Mapping/Driver/DriverChain.php index f0f59e2..547a66c 100644 --- a/lib/FSi/DoctrineExtensions/Mapping/Driver/DriverChain.php +++ b/lib/FSi/DoctrineExtensions/Mapping/Driver/DriverChain.php @@ -11,7 +11,7 @@ namespace FSi\DoctrineExtensions\Mapping\Driver; -use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory; +use Doctrine\Persistence\Mapping\ClassMetadataFactory; use FSi\DoctrineExtensions\Mapping\Exception\RuntimeException; use FSi\DoctrineExtensions\Metadata\ClassMetadataInterface; diff --git a/lib/FSi/DoctrineExtensions/Mapping/Driver/DriverInterface.php b/lib/FSi/DoctrineExtensions/Mapping/Driver/DriverInterface.php index 4cdd5f4..d0aa971 100644 --- a/lib/FSi/DoctrineExtensions/Mapping/Driver/DriverInterface.php +++ b/lib/FSi/DoctrineExtensions/Mapping/Driver/DriverInterface.php @@ -11,7 +11,7 @@ namespace FSi\DoctrineExtensions\Mapping\Driver; -use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory; +use Doctrine\Persistence\Mapping\ClassMetadataFactory; use FSi\DoctrineExtensions\Metadata\ClassMetadataInterface; interface DriverInterface diff --git a/lib/FSi/DoctrineExtensions/Mapping/ExtendedMetadataFactory.php b/lib/FSi/DoctrineExtensions/Mapping/ExtendedMetadataFactory.php index 2e1c38a..73de651 100644 --- a/lib/FSi/DoctrineExtensions/Mapping/ExtendedMetadataFactory.php +++ b/lib/FSi/DoctrineExtensions/Mapping/ExtendedMetadataFactory.php @@ -13,19 +13,19 @@ use Doctrine\Common\Annotations\Reader; use Doctrine\Common\Cache\Cache; -use Doctrine\Common\Persistence\Mapping\Driver\FileDriver; -use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; -use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\Mapping\Driver\FileDriver; +use Doctrine\Persistence\Mapping\Driver\MappingDriver; +use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; use FSi\DoctrineExtensions\Mapping\Driver\AbstractAnnotationDriver; use FSi\DoctrineExtensions\Mapping\Driver\AbstractFileDriver; use FSi\DoctrineExtensions\Mapping\Driver\DriverChain; use FSi\DoctrineExtensions\Mapping\Driver\DriverInterface; use FSi\DoctrineExtensions\Mapping\Exception\RuntimeException; -use FSi\DoctrineExtensions\Metadata\ClassMetadata; use FSi\DoctrineExtensions\Metadata\ClassMetadataInterface; use ReflectionClass; use Symfony\Component\PropertyAccess\Exception\InvalidArgumentException; +use function class_exists; final class ExtendedMetadataFactory { @@ -104,7 +104,9 @@ public function __construct( '\\' ); if (!class_exists($metadataClassName)) { - throw new RuntimeException(sprintf('Metadata class "%s" does not exist!')); + throw new RuntimeException( + sprintf('Metadata class "%s" does not exist!', class_exists($metadataClassName)) + ); } $metadataClassReflection = new ReflectionClass($metadataClassName); diff --git a/lib/FSi/DoctrineExtensions/Mapping/MappedEventSubscriber.php b/lib/FSi/DoctrineExtensions/Mapping/MappedEventSubscriber.php index 385adc9..c24fb45 100644 --- a/lib/FSi/DoctrineExtensions/Mapping/MappedEventSubscriber.php +++ b/lib/FSi/DoctrineExtensions/Mapping/MappedEventSubscriber.php @@ -16,9 +16,9 @@ use Doctrine\Common\Annotations\Reader; use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\EventSubscriber; -use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\Persistence\Mapping\ClassMetadata; use FSi\DoctrineExtensions\Metadata\ClassMetadataInterface; use RuntimeException; diff --git a/lib/FSi/DoctrineExtensions/Translatable/ClassTranslationContext.php b/lib/FSi/DoctrineExtensions/Translatable/ClassTranslationContext.php index f9da409..86d3ebd 100644 --- a/lib/FSi/DoctrineExtensions/Translatable/ClassTranslationContext.php +++ b/lib/FSi/DoctrineExtensions/Translatable/ClassTranslationContext.php @@ -11,8 +11,8 @@ namespace FSi\DoctrineExtensions\Translatable; -use Doctrine\Common\Persistence\Mapping\ClassMetadata; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Persistence\Mapping\ClassMetadata; +use Doctrine\Persistence\ObjectManager; use FSi\DoctrineExtensions\Translatable\Mapping\TranslationAssociationMetadata; use FSi\DoctrineExtensions\Translatable\Model\TranslatableRepositoryInterface; use FSi\DoctrineExtensions\Translatable\Mapping\ClassMetadata as TranslatableClassMetadata; diff --git a/lib/FSi/DoctrineExtensions/Translatable/Entity/Repository/TranslatableRepository.php b/lib/FSi/DoctrineExtensions/Translatable/Entity/Repository/TranslatableRepository.php index ef2f752..e6d0334 100644 --- a/lib/FSi/DoctrineExtensions/Translatable/Entity/Repository/TranslatableRepository.php +++ b/lib/FSi/DoctrineExtensions/Translatable/Entity/Repository/TranslatableRepository.php @@ -88,16 +88,8 @@ public function createTranslatableQueryBuilder( $translatableProperties = $this->getExtendedMetadata()->getTranslatableProperties(); foreach (array_keys($translatableProperties) as $translationAssociation) { $join = sprintf('%s.%s', $alias, $translationAssociation); - $qb->joinAndSelectCurrentTranslations( - $join, Expr\Join::LEFT_JOIN, - $translationAlias, - 'locale' - ); - $qb->joinAndSelectDefaultTranslations( - $join, Expr\Join::LEFT_JOIN, - $defaultTranslationAlias, - 'deflocale' - ); + $qb->joinAndSelectCurrentTranslations($join, Expr\Join::LEFT_JOIN, $translationAlias, 'locale'); + $qb->joinAndSelectDefaultTranslations($join, Expr\Join::LEFT_JOIN, $defaultTranslationAlias, 'deflocale'); } return $qb; diff --git a/lib/FSi/DoctrineExtensions/Translatable/Mapping/Driver/Annotation.php b/lib/FSi/DoctrineExtensions/Translatable/Mapping/Driver/Annotation.php index 5bf285c..4cb27a8 100644 --- a/lib/FSi/DoctrineExtensions/Translatable/Mapping/Driver/Annotation.php +++ b/lib/FSi/DoctrineExtensions/Translatable/Mapping/Driver/Annotation.php @@ -17,11 +17,13 @@ use FSi\DoctrineExtensions\Translatable\Exception\AnnotationException; use FSi\DoctrineExtensions\Translatable\Mapping\ClassMetadata; use RuntimeException; +use FSi\DoctrineExtensions\Translatable\Mapping\Annotation\Translatable; +use FSi\DoctrineExtensions\Translatable\Mapping\Annotation\Locale; class Annotation extends AbstractAnnotationDriver { - public const TRANSLATABLE = 'FSi\\DoctrineExtensions\\Translatable\\Mapping\\Annotation\\Translatable'; - public const LOCALE = 'FSi\\DoctrineExtensions\\Translatable\\Mapping\\Annotation\\Locale'; + public const TRANSLATABLE = Translatable::class; + public const LOCALE = Locale::class; /** * @param ClassMetadataInfo $baseClassMetadata @@ -52,7 +54,8 @@ protected function loadExtendedClassMetadata( continue; } - $translatableAnnotation = $this->getAnnotationReader()->getPropertyAnnotation($property, self::TRANSLATABLE); + $translatableAnnotation = $this->getAnnotationReader() + ->getPropertyAnnotation($property, self::TRANSLATABLE); if ($translatableAnnotation) { if (!isset($translatableAnnotation->mappedBy)) { throw new AnnotationException( diff --git a/lib/FSi/DoctrineExtensions/Translatable/Query/QueryBuilder.php b/lib/FSi/DoctrineExtensions/Translatable/Query/QueryBuilder.php index 0f4d43f..7abaf06 100644 --- a/lib/FSi/DoctrineExtensions/Translatable/Query/QueryBuilder.php +++ b/lib/FSi/DoctrineExtensions/Translatable/Query/QueryBuilder.php @@ -18,6 +18,7 @@ use FSi\DoctrineExtensions\Translatable\Mapping\ClassMetadata as TranslatableClassMetadata; use FSi\DoctrineExtensions\Translatable\Exception\RuntimeException; use FSi\DoctrineExtensions\Translatable\TranslatableListener; +use function sprintf; class QueryBuilder extends BaseQueryBuilder { @@ -532,6 +533,8 @@ private function getJoinedTranslationsAlias(string $join, string $locale): ?stri if (isset($this->translationsAliases[$join][$locale])) { return $this->translationsAliases[$join][$locale]; } + + return null; } private function getTranslationField(string $alias, string $property): string @@ -546,7 +549,11 @@ private function getTranslationField(string $alias, string $property): string } } - $this->throwUnknownTranslatablePropertyException($alias, $property); + throw new RuntimeException(sprintf( + 'Unknown translatable property "%s" in class "%s"', + $property, + $this->getClassByAlias($alias) + )); } private function getTranslationAssociation(string $alias, string $property): string @@ -561,7 +568,11 @@ private function getTranslationAssociation(string $alias, string $property): str } } - $this->throwUnknownTranslatablePropertyException($alias, $property); + throw new RuntimeException(sprintf( + 'Unknown translatable property "%s" in class "%s"', + $property, + $this->getClassByAlias($alias) + )); } private function joinCurrentTranslationsOnce( @@ -623,21 +634,6 @@ private function joinAndSelectTranslationsOnce( } } - /** - * @param string $alias - * @param string $property - * @return void - * @throws RuntimeException - */ - private function throwUnknownTranslatablePropertyException(string $alias, string $property): void - { - throw new RuntimeException(sprintf( - 'Unknown translatable property "%s" in class "%s"', - $property, - $this->getClassByAlias($alias) - )); - } - private function hasDefaultLocaleDifferentThanCurrentLocale(?string $locale): bool { $defaultLocale = $this->getTranslatableListener()->getDefaultLocale(); @@ -751,7 +747,7 @@ private function addTranslatableWhereOnCollection( $this->andWhere($collectionExpr); } elseif (is_array($value)) { if ($this->isTranslatableProperty($alias, $field)) { - $fieldExpr = $this->expr()->in('%s', $parameter); + $fieldExpr = (string) $this->expr()->in('%s', $parameter); $collectionExpr = $this->getTranslatableCollectionExpr($alias, $field, $fieldExpr, true, $locale); $this->andWhere($collectionExpr); } else { diff --git a/lib/FSi/DoctrineExtensions/Translatable/TranslatableListener.php b/lib/FSi/DoctrineExtensions/Translatable/TranslatableListener.php index d2cad43..230c16d 100644 --- a/lib/FSi/DoctrineExtensions/Translatable/TranslatableListener.php +++ b/lib/FSi/DoctrineExtensions/Translatable/TranslatableListener.php @@ -11,10 +11,10 @@ namespace FSi\DoctrineExtensions\Translatable; -use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Event\PreFlushEventArgs; +use Doctrine\Persistence\Mapping\ClassMetadata; use FSi\DoctrineExtensions\Mapping\MappedEventSubscriber; use FSi\DoctrineExtensions\Metadata\ClassMetadataInterface; use FSi\DoctrineExtensions\Translatable\Exception; diff --git a/lib/FSi/DoctrineExtensions/Uploadable/Keymaker/Entity.php b/lib/FSi/DoctrineExtensions/Uploadable/Keymaker/Entity.php index 66f8ad6..ddc3018 100644 --- a/lib/FSi/DoctrineExtensions/Uploadable/Keymaker/Entity.php +++ b/lib/FSi/DoctrineExtensions/Uploadable/Keymaker/Entity.php @@ -45,4 +45,3 @@ public function createKey( ); } } - diff --git a/lib/FSi/DoctrineExtensions/Uploadable/Keymaker/TransliterateEntity.php b/lib/FSi/DoctrineExtensions/Uploadable/Keymaker/TransliterateEntity.php index cd1007a..c3553e1 100644 --- a/lib/FSi/DoctrineExtensions/Uploadable/Keymaker/TransliterateEntity.php +++ b/lib/FSi/DoctrineExtensions/Uploadable/Keymaker/TransliterateEntity.php @@ -12,6 +12,9 @@ namespace FSi\DoctrineExtensions\Uploadable\Keymaker; use Doctrine\Common\Util\ClassUtils; +use function preg_replace; +use function transliterator_transliterate; +use function trim; class TransliterateEntity implements KeymakerInterface { @@ -52,9 +55,6 @@ private function cleanFileName(string $originalName): string $originalName ); - return trim(preg_replace( - '/[-\s]+/', '-', - preg_replace('/[^\da-z.\-\s]+/', '', $transliteratedName) - )); + return trim(preg_replace('/[-\s]+/', '-', preg_replace('/[^\da-z.\-\s]+/', '', $transliteratedName))); } } diff --git a/lib/FSi/DoctrineExtensions/Uploadable/UploadableListener.php b/lib/FSi/DoctrineExtensions/Uploadable/UploadableListener.php index 712f6f3..a7b9d8b 100644 --- a/lib/FSi/DoctrineExtensions/Uploadable/UploadableListener.php +++ b/lib/FSi/DoctrineExtensions/Uploadable/UploadableListener.php @@ -11,12 +11,12 @@ namespace FSi\DoctrineExtensions\Uploadable; -use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Event\PostFlushEventArgs; use Doctrine\ORM\Event\PreFlushEventArgs; use Doctrine\ORM\Proxy\Proxy; +use Doctrine\Persistence\Mapping\ClassMetadata; use FSi\DoctrineExtensions\Mapping\MappedEventSubscriber; use FSi\DoctrineExtensions\Metadata\ClassMetadataInterface; use FSi\DoctrineExtensions\PropertyManipulator; @@ -470,31 +470,25 @@ protected function validateExtendedMetadata( if (false === $baseClassMetadata->hasField($field)) { throw new MappingException(sprintf( - 'Property "%s" of class "%s" have mapping "Uploadable" but isn\'t' - . ' mapped as Doctrine\'s column.', + 'Property "%s" of class "%s" have mapping "Uploadable" but isn\'t mapped as Doctrine\'s column.', $field, - $className, - $options['targetField'] + $className )); } if (null !== $options['keyLength'] && false === is_numeric($options['keyLength'])) { throw new MappingException(sprintf( - 'Property "%s" of class "%s" have mapping "Uploadable" with key' - . ' length is not a number.', + 'Property "%s" of class "%s" have mapping "Uploadable" with key length is not a number.', $field, - $className, - $options['targetField'] + $className )); } if (null !== $options['keyLength'] && 1 > $options['keyLength']) { throw new MappingException(sprintf( - 'Property "%s" of class "%s" have mapping "Uploadable" with' - . ' key length less than 1.', + 'Property "%s" of class "%s" have mapping "Uploadable" with key length less than 1.', $field, - $className, - $options['targetField'] + $className )); } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..7a6f45b --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,17 @@ + + + + + + lib + tests + tests/bootstrap.php + + + + + + + + + diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..bd2fe81 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,7 @@ +parameters: + bootstrapFiles: + - tests/bootstrap.php + level: 1 + paths: + - lib + - tests diff --git a/tests/FSi/DoctrineExtensions/Tests/PropertyManipulatorTest.php b/tests/FSi/DoctrineExtensions/Tests/PropertyManipulatorTest.php index bf106ee..cd4baff 100644 --- a/tests/FSi/DoctrineExtensions/Tests/PropertyManipulatorTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/PropertyManipulatorTest.php @@ -9,16 +9,15 @@ declare(strict_types=1); -namespace FSi\DoctrineExtensions\Tests\Uploadable\PropertyManipulator; +namespace FSi\DoctrineExtensions\Tests; use FSi\DoctrineExtensions\PropertyManipulator; -use FSi\DoctrineExtensions\Tests\Uploadable\PropertyManipulator\TestObject; use PHPUnit\Framework\TestCase; use RuntimeException; class PropertyManipulatorTest extends TestCase { - public function testValueChanged() + public function testValueChanged(): void { $this->expectException(RuntimeException::class); @@ -34,17 +33,17 @@ public function testValueChanged() $object->property1 = 'new value 1'; $object->property3 = 'new value 3'; - $this->assertTrue($observer->hasSavedValue($object, 'property1')); - $this->assertTrue($observer->hasChangedValue($object, 'property1')); - $this->assertTrue($observer->hasSavedValue($object, 'property2')); - $this->assertFalse($observer->hasChangedValue($object, 'property2')); - $this->assertTrue($observer->hasChangedValue($object, 'property3')); - $this->assertTrue($observer->hasSavedValue($object, 'property3')); - $this->assertFalse($observer->hasSavedValue($object, 'property4')); + self::assertTrue($observer->hasSavedValue($object, 'property1')); + self::assertTrue($observer->hasChangedValue($object, 'property1')); + self::assertTrue($observer->hasSavedValue($object, 'property2')); + self::assertFalse($observer->hasChangedValue($object, 'property2')); + self::assertTrue($observer->hasChangedValue($object, 'property3')); + self::assertTrue($observer->hasSavedValue($object, 'property3')); + self::assertFalse($observer->hasSavedValue($object, 'property4')); $observer->hasChangedValue($object, 'property4'); } - public function testChangedValue() + public function testChangedValue(): void { $this->expectException(RuntimeException::class); @@ -60,17 +59,17 @@ public function testChangedValue() $object->property1 = 'new value 1'; $object->property3 = 'new value 3'; - $this->assertTrue($observer->hasSavedValue($object, 'property1')); - $this->assertTrue($observer->hasChangedValue($object, 'property1')); - $this->assertTrue($observer->hasSavedValue($object, 'property2')); - $this->assertFalse($observer->hasChangedValue($object, 'property2')); - $this->assertTrue($observer->hasChangedValue($object, 'property3')); - $this->assertTrue($observer->hasSavedValue($object, 'property3')); - $this->assertFalse($observer->hasSavedValue($object, 'property4')); + self::assertTrue($observer->hasSavedValue($object, 'property1')); + self::assertTrue($observer->hasChangedValue($object, 'property1')); + self::assertTrue($observer->hasSavedValue($object, 'property2')); + self::assertFalse($observer->hasChangedValue($object, 'property2')); + self::assertTrue($observer->hasChangedValue($object, 'property3')); + self::assertTrue($observer->hasSavedValue($object, 'property3')); + self::assertFalse($observer->hasSavedValue($object, 'property4')); $observer->hasChangedValue($object, 'property4'); } - public function testSetValue() + public function testSetValue(): void { $this->expectException(RuntimeException::class); @@ -83,13 +82,13 @@ public function testSetValue() $object->property1 = 'new value 1'; $object->property3 = 'new value 3'; - $this->assertTrue($observer->hasChangedValue($object, 'property1')); - $this->assertFalse($observer->hasChangedValue($object, 'property2')); - $this->assertTrue($observer->hasChangedValue($object, 'property3')); + self::assertTrue($observer->hasChangedValue($object, 'property1')); + self::assertFalse($observer->hasChangedValue($object, 'property2')); + self::assertTrue($observer->hasChangedValue($object, 'property3')); $observer->hasChangedValue($object, 'property4'); } - public function testGetSavedValue() + public function testGetSavedValue(): void { $this->expectException(RuntimeException::class); @@ -105,19 +104,19 @@ public function testGetSavedValue() $object->property1 = 'new value 1'; $object->property3 = 'new value 3'; - $this->assertEquals( + self::assertEquals( $observer->getSavedValue($object, 'property1'), 'original value 1' ); - $this->assertEquals( + self::assertEquals( $observer->getSavedValue($object, 'property2'), 'original value 2' ); - $this->assertNull($observer->getSavedValue($object, 'property3')); + self::assertNull($observer->getSavedValue($object, 'property3')); $observer->getSavedValue($object, 'property4'); } - public function testTreatNotSavedAsNull() + public function testTreatNotSavedAsNull(): void { $observer = new PropertyManipulator(); @@ -127,20 +126,9 @@ public function testTreatNotSavedAsNull() $object->property1 = 'new value 1'; $object->property3 = 'new value 3'; - $this->assertTrue($observer->hasChangedValue($object, 'property1', true)); - $this->assertTrue($observer->hasChangedValue($object, 'property2', true)); - $this->assertTrue($observer->hasChangedValue($object, 'property3', true)); - $this->assertFalse($observer->hasChangedValue($object, 'property4', true)); + self::assertTrue($observer->hasChangedValue($object, 'property1', true)); + self::assertTrue($observer->hasChangedValue($object, 'property2', true)); + self::assertTrue($observer->hasChangedValue($object, 'property3', true)); + self::assertFalse($observer->hasChangedValue($object, 'property4', true)); } } - -class TestObject -{ - public $property1; - - public $property2; - - public $property3; - - public $property4; -} diff --git a/tests/FSi/DoctrineExtensions/Tests/TestObject.php b/tests/FSi/DoctrineExtensions/Tests/TestObject.php new file mode 100644 index 0000000..85c6e36 --- /dev/null +++ b/tests/FSi/DoctrineExtensions/Tests/TestObject.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace FSi\DoctrineExtensions\Tests; + +final class TestObject +{ + public $property1; + + public $property2; + + public $property3; + + public $property4; +} diff --git a/tests/FSi/DoctrineExtensions/Tests/Tool/BaseORMTest.php b/tests/FSi/DoctrineExtensions/Tests/Tool/BaseORMTest.php index 60b19e4..90e257a 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Tool/BaseORMTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Tool/BaseORMTest.php @@ -13,7 +13,6 @@ use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\EventManager; -use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Logging\DebugStack; use Doctrine\DBAL\Logging\SQLLogger; @@ -21,11 +20,13 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\DefaultQuoteStrategy; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Repository\DefaultRepositoryFactory; use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\Persistence\Mapping\Driver\MappingDriver; use FSi\DoctrineExtensions\Translatable\TranslatableListener; use FSi\DoctrineExtensions\Uploadable\FileHandler; use FSi\DoctrineExtensions\Uploadable\Keymaker\Entity; @@ -72,7 +73,7 @@ abstract class BaseORMTest extends TestCase */ protected $filesystem2; - protected function setUp() + protected function setUp(): void { $this->entityManager = $this->getEntityManager(); } @@ -82,70 +83,25 @@ protected function getMetadataDriverImplementation(): MappingDriver return new AnnotationDriver($_ENV['annotation_reader']); } - /** - * @return Configuration - */ - protected function getMockAnnotatedConfig() + protected function getMockAnnotatedConfig(): Configuration { $config = $this->createMock(Configuration::class); - $config->expects($this->once()) - ->method('getProxyDir') - ->will($this->returnValue(TESTS_TEMP_DIR)) - ; - - $config->expects($this->once()) - ->method('getProxyNamespace') - ->will($this->returnValue('Proxy')) - ; - - $config->expects($this->once()) - ->method('getAutoGenerateProxyClasses') - ->will($this->returnValue(true)) - ; - - $config->expects($this->once()) - ->method('getClassMetadataFactoryName') - ->will($this->returnValue(ClassMetadataFactory::class)) - ; - - $config->expects($this->any()) - ->method('getMetadataCacheImpl') - ->will($this->returnValue(new ArrayCache())) - ; - - $config->expects($this->any()) - ->method('getQuoteStrategy') - ->will($this->returnValue(new DefaultQuoteStrategy())) - ; - - $config->expects($this->any()) - ->method('getDefaultQueryHints') - ->will($this->returnValue([])); - - $config->expects($this->any()) - ->method('getRepositoryFactory') - ->will($this->returnValue(new DefaultRepositoryFactory())) - ; + $config->expects(self::once())->method('getProxyDir')->willReturn(TESTS_TEMP_DIR); + $config->expects(self::once())->method('getProxyNamespace')->willReturn('Proxy'); + $config->expects(self::once())->method('getAutoGenerateProxyClasses')->willReturn(true); + $config->expects(self::once())->method('getClassMetadataFactoryName')->willReturn(ClassMetadataFactory::class); + $config->method('getMetadataCacheImpl')->willReturn(new ArrayCache()); + $config->method('getQuoteStrategy')->willReturn(new DefaultQuoteStrategy()); + $config->method('getDefaultQueryHints')->willReturn([]); + $config->method('getRepositoryFactory')->willReturn(new DefaultRepositoryFactory()); $mappingDriver = $this->getMetadataDriverImplementation(); - - $config->expects($this->any()) - ->method('getMetadataDriverImpl') - ->will($this->returnValue($mappingDriver)) - ; - - $config->expects($this->any()) - ->method('getDefaultRepositoryClassName') - ->will($this->returnValue(EntityRepository::class)) - ; + $config->method('getMetadataDriverImpl')->willReturn($mappingDriver); + $config->method('getDefaultRepositoryClassName')->willReturn(EntityRepository::class); $this->logger = new DebugStack(); $this->logger->enabled = false; - - $config->expects($this->any()) - ->method('getSQLLogger') - ->will($this->returnValue($this->logger)) - ; + $config->method('getSQLLogger')->willReturn($this->logger); return $config; } @@ -174,16 +130,15 @@ protected function getEntityManager(): EntityManagerInterface $evm->addEventSubscriber($this->uploadableListener); $config = $this->getMockAnnotatedConfig(); - $conn = DriverManager::getConnection( - ['driver' => 'pdo_sqlite', 'memory' => true], - $config, - $evm - ); + $conn = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true], $config, $evm); $em = EntityManager::create($conn, $config, $evm); - $schema = array_map(function($class) use ($em) { - return $em->getClassMetadata($class); - }, (array) $this->getUsedEntityFixtures()); + $schema = array_map( + static function (string $class) use ($em): ClassMetadata { + return $em->getClassMetadata($class); + }, + $this->getUsedEntityFixtures() + ); $schemaTool = new SchemaTool($em); $schemaTool->dropSchema($schema); @@ -192,10 +147,5 @@ protected function getEntityManager(): EntityManagerInterface return $em; } - /** - * Get array of classes of entities used in test. - * - * @return array - */ - abstract protected function getUsedEntityFixtures(); + abstract protected function getUsedEntityFixtures(): array; } diff --git a/tests/FSi/DoctrineExtensions/Tests/Translatable/BaseTranslatableTest.php b/tests/FSi/DoctrineExtensions/Tests/Translatable/BaseTranslatableTest.php index d2dda84..13fcfa1 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Translatable/BaseTranslatableTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Translatable/BaseTranslatableTest.php @@ -39,24 +39,22 @@ abstract class BaseTranslatableTest extends BaseORMTest public const LANGUAGE_EN = 'en'; public const LANGUAGE_DE = 'de'; - protected function setUp() + protected function setUp(): void { parent::setUp(); + $this->entityManager = $this->getEntityManager(); } - /** - * @return Article - */ protected function createArticle( - $title = self::POLISH_TITLE_1, - $subtitle = self::POLISH_SUBTITLE, - $contents = self::POLISH_CONTENTS_1, - $locale = null - ) { + string $title = self::POLISH_TITLE_1, + string $subtitle = self::POLISH_SUBTITLE, + string $contents = self::POLISH_CONTENTS_1, + ?string $locale = null + ): Article { $article = new Article(); $article->setDate(new DateTime()); - $article->setLocale($locale ? $locale : self::LANGUAGE_PL); + $article->setLocale($locale ?? self::LANGUAGE_PL); $article->setTitle($title); $article->setSubtitle($subtitle); $article->setContents($contents); @@ -67,7 +65,7 @@ protected function createArticle( /** * @param object $object */ - protected function persistAndFlush($object) + protected function persistAndFlush($object): void { $this->entityManager->persist($object); $this->entityManager->flush(); diff --git a/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithLocalelessTranslation.php b/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithLocalelessTranslation.php index 5509f74..1b96144 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithLocalelessTranslation.php +++ b/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithLocalelessTranslation.php @@ -42,7 +42,11 @@ class TranslatableWithLocalelessTranslation private $contents; /** - * @ORM\OneToMany(targetEntity="TranslatableWithPersistentLocaleTranslation", mappedBy="translatable", indexBy="locale") + * @ORM\OneToMany( + * targetEntity="TranslatableWithPersistentLocaleTranslation", + * mappedBy="translatable", + * indexBy="locale" + * ) * @var \Doctrine\Common\Collections\ArrayCollection */ private $translations; diff --git a/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithPersistentLocale.php b/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithPersistentLocale.php index e333f80..7c9a16a 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithPersistentLocale.php +++ b/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithPersistentLocale.php @@ -43,7 +43,11 @@ class TranslatableWithPersistentLocale private $contents; /** - * @ORM\OneToMany(targetEntity="TranslatableWithPersistentLocaleTranslation", mappedBy="translatable", indexBy="locale") + * @ORM\OneToMany( + * targetEntity="TranslatableWithPersistentLocaleTranslation", + * mappedBy="translatable", + * indexBy="locale" + * ) * @var \Doctrine\Common\Collections\ArrayCollection */ private $translations; diff --git a/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithPersistentLocaleTranslation.php b/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithPersistentLocaleTranslation.php index 0d1f154..0e5e1c5 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithPersistentLocaleTranslation.php +++ b/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithPersistentLocaleTranslation.php @@ -81,5 +81,4 @@ public function getLocale(): ?string { return $this->locale; } - } diff --git a/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithoutLocale.php b/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithoutLocale.php index 1370623..ad7aac9 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithoutLocale.php +++ b/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithoutLocale.php @@ -11,6 +11,7 @@ namespace FSi\DoctrineExtensions\Tests\Translatable\Fixture; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use FSi\DoctrineExtensions\Translatable\Mapping\Annotation as Translatable; diff --git a/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithoutLocaleTranslation.php b/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithoutLocaleTranslation.php index 13fb339..5f41cb7 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithoutLocaleTranslation.php +++ b/tests/FSi/DoctrineExtensions/Tests/Translatable/Fixture/TranslatableWithoutLocaleTranslation.php @@ -66,5 +66,4 @@ public function getLocale(): ?string { return $this->locale; } - } diff --git a/tests/FSi/DoctrineExtensions/Tests/Translatable/ListenerTest.php b/tests/FSi/DoctrineExtensions/Tests/Translatable/ListenerTest.php index 515a241..593bc69 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Translatable/ListenerTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Translatable/ListenerTest.php @@ -35,7 +35,7 @@ class ListenerTest extends BaseTranslatableTest /** * Test simple entity creation with translation its state after $em->flush() */ - public function testInsert() + public function testInsert(): void { $article = $this->createArticle(); $this->entityManager->persist($article); @@ -43,28 +43,21 @@ public function testInsert() $this->translatableListener->setLocale(self::LANGUAGE_PL); $this->entityManager->flush(); - $this->assertEquals( - 4, - count($this->logger->queries), - 'Flushing executed wrong number of queries' - ); + self::assertCount(4, $this->logger->queries, 'Flushing executed wrong number of queries'); - $this->assertAttributeEquals( + self::assertEquals( self::POLISH_TITLE_1, - 'title', - $article->getTranslations()->get(self::LANGUAGE_PL) + $article->getTranslations()->get(self::LANGUAGE_PL)->getTitle() ); - $this->assertAttributeEquals( + self::assertEquals( self::POLISH_SUBTITLE, - 'subtitle', - $article->getTranslations()->get(self::LANGUAGE_PL) + $article->getTranslations()->get(self::LANGUAGE_PL)->getSubtitle() ); - $this->assertAttributeEquals( + self::assertEquals( self::POLISH_CONTENTS_1, - 'contents', - $article->getTranslations()->get(self::LANGUAGE_PL) + $article->getTranslations()->get(self::LANGUAGE_PL)->getContents() ); } @@ -72,7 +65,7 @@ public function testInsert() * Test simple entity creation without translations and adding translation * later its state after $em->flush() */ - public function testInsertAndAddFirstTranslation() + public function testInsertAndAddFirstTranslation(): void { $article = new Article(); $article->setDate(new DateTime()); @@ -86,38 +79,26 @@ public function testInsertAndAddFirstTranslation() $this->logger->enabled = true; $this->entityManager->flush(); - $this->assertEquals( - 3, - count($this->logger->queries), - 'Flushing executed wrong number of queries' - ); - - $this->assertEquals( - 1, - count($article->getTranslations()), - 'Number of translations is not valid' - ); + self::assertCount(3, $this->logger->queries, 'Flushing executed wrong number of queries'); + self::assertCount(1, $article->getTranslations(), 'Number of translations is not valid'); - $this->assertAttributeEquals( + self::assertEquals( self::POLISH_TITLE_1, - 'title', - $article->getTranslations()->get(self::LANGUAGE_PL) + $article->getTranslations()->get(self::LANGUAGE_PL)->getTitle() ); - $this->assertAttributeEquals( + self::assertEquals( self::POLISH_SUBTITLE, - 'subtitle', - $article->getTranslations()->get(self::LANGUAGE_PL) + $article->getTranslations()->get(self::LANGUAGE_PL)->getSubtitle() ); - $this->assertAttributeEquals( + self::assertEquals( self::POLISH_CONTENTS_1, - 'contents', - $article->getTranslations()->get(self::LANGUAGE_PL) + $article->getTranslations()->get(self::LANGUAGE_PL)->getContents() ); } - public function testNotInsertTranslation() + public function testNotInsertTranslation(): void { $article = new Article(); $article->setDate(new DateTime()); @@ -127,19 +108,14 @@ public function testNotInsertTranslation() $this->translatableListener->setLocale(self::LANGUAGE_PL); $this->entityManager->flush(); - $this->assertEquals( - 3, - count($this->logger->queries), - 'Flushing executed wrong number of queries' - ); - - $this->assertEquals(0, $article->getTranslations()->count()); + self::assertCount(3, $this->logger->queries, 'Flushing executed wrong number of queries'); + self::assertEquals(0, $article->getTranslations()->count()); } /** * Test simple entity creation with one translation and adding one later */ - public function testInsertAndAddTranslation() + public function testInsertAndAddTranslation(): void { $article = $this->createArticle(); $this->entityManager->persist($article); @@ -152,41 +128,21 @@ public function testInsertAndAddTranslation() $this->logger->enabled = true; $this->entityManager->flush(); - $this->assertEquals( - 3, - count($this->logger->queries), - 'Flushing executed wrong number of queries' - ); - - $this->assertEquals( - 2, - count($article->getTranslations()), - 'Number of translations is not valid' - ); - - $this->assertAttributeEquals( - self::ENGLISH_TITLE_1, - 'title', - $article->getTranslations()->get(self::LANGUAGE_EN) - ); - - $this->assertAttributeEquals( - self::ENGLISH_SUBTITLE, - 'subtitle', - $article->getTranslations()->get(self::LANGUAGE_EN) - ); - - $this->assertAttributeEquals( + self::assertCount(3, $this->logger->queries, 'Flushing executed wrong number of queries'); + self::assertCount(2, $article->getTranslations(), 'Number of translations is not valid'); + self::assertEquals(self::ENGLISH_TITLE_1, $article->getTranslations()->get(self::LANGUAGE_EN)->getTitle()); + self::assertEquals(self::ENGLISH_SUBTITLE, $article->getTranslations()->get(self::LANGUAGE_EN)->getSubtitle()); + self::assertEquals( self::ENGLISH_CONTENTS_1, - 'contents', - $article->getTranslations()->get(self::LANGUAGE_EN) + $article->getTranslations()->get(self::LANGUAGE_EN)->getContents() ); } /** - * Test simple entity creation with two translation and check its state after $em->clear(), change default locale and load + * Test simple entity creation with two translation and check its state after $em->clear(), + * change default locale and load */ - public function testInsertWithTwoTranslationsClearAndLoad() + public function testInsertWithTwoTranslationsClearAndLoad(): void { $article = $this->createArticle(); $this->entityManager->persist($article); @@ -203,45 +159,20 @@ public function testInsertWithTwoTranslationsClearAndLoad() $this->translatableListener->setLocale(self::LANGUAGE_PL); $article = $this->entityManager->find(Article::class, $article->getId()); - $this->assertEquals( - 5, - count($this->logger->queries), - 'Reloading executed wrong number of queries' - ); - - $this->assertEquals( - 2, - count($article->getTranslations()), - 'Number of translations is not valid' - ); - - $this->assertAttributeEquals(self::POLISH_TITLE_1, 'title', $article); - $this->assertAttributeEquals(self::POLISH_SUBTITLE, 'subtitle', $article); - $this->assertAttributeEquals(self::POLISH_CONTENTS_1, 'contents', $article); - - $this->assertAttributeEquals( - self::POLISH_TITLE_1, - 'title', - $article->getTranslations()->get(self::LANGUAGE_PL) - ); - - $this->assertAttributeEquals( - self::POLISH_SUBTITLE, - 'subtitle', - $article->getTranslations()->get(self::LANGUAGE_PL) - ); - - $this->assertAttributeEquals( - self::POLISH_CONTENTS_1, - 'contents', - $article->getTranslations()->get(self::LANGUAGE_PL) - ); + self::assertCount(5, $this->logger->queries, 'Reloading executed wrong number of queries'); + self::assertCount(2, $article->getTranslations(), 'Number of translations is not valid'); + self::assertEquals(self::POLISH_TITLE_1, $article->getTitle()); + self::assertEquals(self::POLISH_SUBTITLE, $article->getSubtitle()); + self::assertEquals(self::POLISH_CONTENTS_1, $article->getContents()); + self::assertEquals(self::POLISH_TITLE_1, $article->getTranslations()->get(self::LANGUAGE_PL)->getTitle()); + self::assertEquals(self::POLISH_SUBTITLE, $article->getTranslations()->get(self::LANGUAGE_PL)->getSubtitle()); + self::assertEquals(self::POLISH_CONTENTS_1, $article->getTranslations()->get(self::LANGUAGE_PL)->getContents()); } /** * Test simple entity creation with two translations and removing one of them later */ - public function testInsertAndRemoveTranslation() + public function testInsertAndRemoveTranslation(): void { $article = new Article(); $article->setDate(new DateTime()); @@ -265,29 +196,10 @@ public function testInsertAndRemoveTranslation() $this->logger->enabled = true; $this->entityManager->flush(); - $this->assertEquals( - 4, - count($this->logger->queries), - 'Flushing executed wrong number of queries' - ); - - $this->assertEquals( - 1, - count($article->getTranslations()), - 'Number of translations is not valid' - ); - - $this->assertAttributeEquals( - self::POLISH_TITLE_1, - 'title', - $article->getTranslations()->get(self::LANGUAGE_PL) - ); - - $this->assertAttributeEquals( - self::POLISH_CONTENTS_1, - 'contents', - $article->getTranslations()->get(self::LANGUAGE_PL) - ); + self::assertCount(4, $this->logger->queries, 'Flushing executed wrong number of queries'); + self::assertCount(1, $article->getTranslations(), 'Number of translations is not valid'); + self::assertEquals(self::POLISH_TITLE_1, $article->getTranslations()->get(self::LANGUAGE_PL)->getTitle()); + self::assertEquals(self::POLISH_CONTENTS_1, $article->getTranslations()->get(self::LANGUAGE_PL)->getContents()); } /** @@ -302,38 +214,18 @@ public function testInsertClearAndLoad() $this->translatableListener->setLocale(self::LANGUAGE_PL); $article = $this->entityManager->find(Article::class, $article->getId()); - $this->assertEquals( - 5, - count($this->logger->queries), - 'Reloading executed wrong number of queries' - ); - - $this->assertEquals( - 1, - count($article->getTranslations()), - 'Number of translations is not valid' - ); - - $this->assertAttributeEquals(self::POLISH_TITLE_1, 'title', $article); - $this->assertAttributeEquals(self::POLISH_CONTENTS_1, 'contents', $article); - - $this->assertAttributeEquals( - self::POLISH_TITLE_1, - 'title', - $article->getTranslations()->get(self::LANGUAGE_PL) - ); - - $this->assertAttributeEquals( - self::POLISH_CONTENTS_1, - 'contents', - $article->getTranslations()->get(self::LANGUAGE_PL) - ); + self::assertCount(5, $this->logger->queries, 'Reloading executed wrong number of queries'); + self::assertCount(1, $article->getTranslations(), 'Number of translations is not valid'); + self::assertEquals(self::POLISH_TITLE_1, $article->getTitle()); + self::assertEquals(self::POLISH_CONTENTS_1, $article->getContents()); + self::assertEquals(self::POLISH_TITLE_1, $article->getTranslations()->get(self::LANGUAGE_PL)->getTitle()); + self::assertEquals(self::POLISH_CONTENTS_1, $article->getTranslations()->get(self::LANGUAGE_PL)->getContents()); } /** * Test updating previously created and persisted translation and its state after $em->flush() */ - public function testUpdate() + public function testUpdate(): void { $article = $this->createArticle(); $this->entityManager->persist($article); @@ -344,35 +236,16 @@ public function testUpdate() $this->logger->enabled = true; $this->entityManager->flush(); - $this->assertEquals( - 3, - count($this->logger->queries), - 'Flushing executed wrong number of queries' - ); - - $this->assertEquals( - 1, - count($article->getTranslations()), - 'Number of translations is not valid' - ); - - $this->assertAttributeEquals( - self::POLISH_TITLE_2, - 'title', - $article->getTranslations()->get(self::LANGUAGE_PL) - ); - - $this->assertAttributeEquals( - self::POLISH_CONTENTS_2, - 'contents', - $article->getTranslations()->get(self::LANGUAGE_PL) - ); + self::assertCount(3, $this->logger->queries, 'Flushing executed wrong number of queries'); + self::assertCount(1, $article->getTranslations(), 'Number of translations is not valid'); + self::assertEquals(self::POLISH_TITLE_2, $article->getTranslations()->get(self::LANGUAGE_PL)->getTitle()); + self::assertEquals(self::POLISH_CONTENTS_2, $article->getTranslations()->get(self::LANGUAGE_PL)->getContents()); } /** * Test updating previously created and persisted translation and its state after $em->clear() */ - public function testUpdateClearAndLoad() + public function testUpdateClearAndLoad(): void { $article = $this->createArticle(); $this->entityManager->persist($article); @@ -387,38 +260,18 @@ public function testUpdateClearAndLoad() $this->translatableListener->setLocale(self::LANGUAGE_PL); $article = $this->entityManager->find(Article::class, $article->getId()); - $this->assertEquals( - 5, - count($this->logger->queries), - 'Reloading executed wrong number of queries' - ); - - $this->assertEquals( - 1, - count($article->getTranslations()), - 'Number of translations is not valid' - ); - - $this->assertAttributeEquals(self::POLISH_TITLE_2, 'title', $article); - $this->assertAttributeEquals(self::POLISH_CONTENTS_2, 'contents', $article); - - $this->assertAttributeEquals( - self::POLISH_TITLE_2, - 'title', - $article->getTranslations()->get(self::LANGUAGE_PL) - ); - - $this->assertAttributeEquals( - self::POLISH_CONTENTS_2, - 'contents', - $article->getTranslations()->get(self::LANGUAGE_PL) - ); + self::assertCount(5, $this->logger->queries, 'Reloading executed wrong number of queries'); + self::assertCount(1, $article->getTranslations(), 'Number of translations is not valid'); + self::assertEquals(self::POLISH_TITLE_2, $article->getTitle()); + self::assertEquals(self::POLISH_CONTENTS_2, $article->getContents()); + self::assertEquals(self::POLISH_TITLE_2, $article->getTranslations()->get(self::LANGUAGE_PL)->getTitle()); + self::assertEquals(self::POLISH_CONTENTS_2, $article->getTranslations()->get(self::LANGUAGE_PL)->getContents()); } /** * Test copying one translation to another */ - public function testCopyTranslation() + public function testCopyTranslation(): void { $article = $this->createArticle(); $this->entityManager->persist($article); @@ -428,39 +281,19 @@ public function testCopyTranslation() $this->logger->enabled = true; $this->entityManager->flush(); - $this->assertEquals( - 3, - count($this->logger->queries), - 'Flushing executed wrong number of queries' - ); - - $this->assertEquals( - 2, - count($article->getTranslations()), - 'Number of translations is not valid' - ); - - $this->assertAttributeEquals(self::POLISH_TITLE_1, 'title', $article); - $this->assertAttributeEquals(self::POLISH_CONTENTS_1, 'contents', $article); - - $this->assertAttributeEquals( - self::POLISH_TITLE_1, - 'title', - $article->getTranslations()->get(self::LANGUAGE_EN) - ); - - $this->assertAttributeEquals( - self::POLISH_CONTENTS_1, - 'contents', - $article->getTranslations()->get(self::LANGUAGE_EN) - ); + self::assertCount(3, $this->logger->queries, 'Flushing executed wrong number of queries'); + self::assertCount(2, $article->getTranslations(), 'Number of translations is not valid'); + self::assertEquals(self::POLISH_TITLE_1, $article->getTitle()); + self::assertEquals(self::POLISH_CONTENTS_1, $article->getContents()); + self::assertEquals(self::POLISH_TITLE_1, $article->getTranslations()->get(self::LANGUAGE_EN)->getTitle()); + self::assertEquals(self::POLISH_CONTENTS_1, $article->getTranslations()->get(self::LANGUAGE_EN)->getContents()); } /** - * Test entity creation with one translation in default language and check if that translation is loaded after changing language - * to other + * Test entity creation with one translation in default language and check if that translation is loaded after + * changing language to other */ - public function testLoadDefaultTranslation() + public function testLoadDefaultTranslation(): void { $article = $this->createArticle(); $this->entityManager->persist($article); @@ -472,32 +305,27 @@ public function testLoadDefaultTranslation() $this->logger->enabled = true; $article = $this->entityManager->find(Article::class, $article->getId()); - $this->assertEquals( - 5, - count($this->logger->queries), - 'Reloading executed wrong number of queries' - ); - - $this->assertAttributeEquals(self::LANGUAGE_PL, 'locale', $article); - $this->assertAttributeEquals(self::POLISH_TITLE_1, 'title', $article); - $this->assertAttributeEquals(self::POLISH_SUBTITLE, 'subtitle', $article); - $this->assertAttributeEquals(self::POLISH_CONTENTS_1, 'contents', $article); + self::assertCount(5, $this->logger->queries, 'Reloading executed wrong number of queries'); + self::assertEquals(self::LANGUAGE_PL, $article->getLocale()); + self::assertEquals(self::POLISH_TITLE_1, $article->getTitle()); + self::assertEquals(self::POLISH_SUBTITLE, $article->getSubtitle()); + self::assertEquals(self::POLISH_CONTENTS_1, $article->getContents()); $article->setLocale(self::LANGUAGE_EN); $this->entityManager->flush(); $this->entityManager->clear(); $article = $this->entityManager->find(Article::class, $article->getId()); - $this->assertAttributeEquals(self::LANGUAGE_EN, 'locale', $article); - $this->assertAttributeEquals(self::POLISH_TITLE_1, 'title', $article); - $this->assertAttributeEquals(self::POLISH_CONTENTS_1, 'contents', $article); + self::assertEquals(self::LANGUAGE_EN, $article->getLocale()); + self::assertEquals(self::POLISH_TITLE_1, $article->getTitle()); + self::assertEquals(self::POLISH_CONTENTS_1, $article->getContents()); } /** * Assert that an empty string returned in Article::getLocale() will not mask * the fact that no locale was set for either the listener or the entity. */ - public function testCurrentLocaleSetToNull() + public function testCurrentLocaleSetToNull(): void { $this->translatableListener->setDefaultLocale(self::LANGUAGE_PL); $this->translatableListener->setLocale(null); @@ -518,10 +346,10 @@ public function testCurrentLocaleSetToNull() } /** - * Test entity creation with two translation and check its state after $em->clear(), change default locale and load with some - * specific translation + * Test entity creation with two translation and check its state after $em->clear(), + * change default locale and load with some specific translation */ - public function testInsertWithTwoTranslationsClearAndLoadTranslation() + public function testInsertWithTwoTranslationsClearAndLoadTranslation(): void { $article = $this->createArticle(); $this->entityManager->persist($article); @@ -539,20 +367,15 @@ public function testInsertWithTwoTranslationsClearAndLoadTranslation() $this->logger->enabled = true; $this->translatableListener->loadTranslation($this->entityManager, $article, self::LANGUAGE_EN); - $this->assertEquals( - 2, - count($article->getTranslations()), - 'Number of translations is not valid' - ); - - $this->assertAttributeEquals(self::ENGLISH_TITLE_1, 'title', $article); - $this->assertAttributeEquals(self::ENGLISH_CONTENTS_1, 'contents', $article); + self::assertCount(2, $article->getTranslations(), 'Number of translations is not valid'); + self::assertEquals(self::ENGLISH_TITLE_1, $article->getTitle()); + self::assertEquals(self::ENGLISH_CONTENTS_1, $article->getContents()); } /** * Test translatable and uploadable properties */ - public function testTranslatableUplodableProperties() + public function testTranslatableUplodableProperties(): void { $this->translatableListener->setDefaultLocale(self::LANGUAGE_PL); @@ -577,19 +400,19 @@ public function testTranslatableUplodableProperties() $article = $this->entityManager->find(Article::class, $article->getId()); $file1 = $article->getIntroImage()->getKey(); - $this->assertFileExists(FILESYSTEM1 . $file1); + self::assertFileExists(FILESYSTEM1 . $file1); $this->entityManager->clear(); $this->translatableListener->setLocale(self::LANGUAGE_EN); $article = $this->entityManager->find(Article::class, $article->getId()); $file2 = $article->getIntroImage()->getKey(); - $this->assertFileExists(FILESYSTEM1 . $file2); + self::assertFileExists(FILESYSTEM1 . $file2); - $this->assertNotSame($file1, $file2); + self::assertNotSame($file1, $file2); } - public function testPostHydrate() + public function testPostHydrate(): void { $this->translatableListener->setLocale(self::LANGUAGE_EN); /* @var $repository TranslatableRepository */ @@ -615,33 +438,26 @@ public function testPostHydrate() $articles = $query->execute(); foreach ($articles as $article) { - $this->assertAttributeEquals(self::ENGLISH_TITLE_1, 'title', $article); - $this->assertAttributeEquals(self::ENGLISH_CONTENTS_1, 'contents', $article); + self::assertEquals(self::ENGLISH_TITLE_1, $article->getTitle()); + self::assertEquals(self::ENGLISH_CONTENTS_1, $article->getContents()); } - $this->assertEquals( - 4, - count($this->logger->queries), - 'Reloading executed wrong number of queries' - ); + self::assertCount(4, $this->logger->queries, 'Reloading executed wrong number of queries'); } - public function testTranslatableWithoutLocaleProperty() + public function testTranslatableWithoutLocaleProperty(): void { $this->expectException(MappingException::class); $this->expectExceptionMessage(sprintf( "Entity '%s' has translatable properties so it must have property" - . " marked with @Translatable\Language annotation", + . " marked with @Translatable\Language annotation", TranslatableWithoutLocale::class )); - $this->translatableListener->getExtendedMetadata( - $this->entityManager, - TranslatableWithoutLocale::class - ); + $this->translatableListener->getExtendedMetadata($this->entityManager, TranslatableWithoutLocale::class); } - public function testTranslatableWithoutTranslations() + public function testTranslatableWithoutTranslations(): void { $this->expectException(MappingException::class); $this->expectExceptionMessage(sprintf( @@ -649,13 +465,10 @@ public function testTranslatableWithoutTranslations() TranslatableWithoutTranslations::class )); - $this->translatableListener->getExtendedMetadata( - $this->entityManager, - TranslatableWithoutTranslations::class - ); + $this->translatableListener->getExtendedMetadata($this->entityManager, TranslatableWithoutTranslations::class); } - public function testTranslatableWithPersistentLocale() + public function testTranslatableWithPersistentLocale(): void { $this->expectException(MappingException::class); $this->expectExceptionMessage(sprintf( @@ -664,13 +477,10 @@ public function testTranslatableWithPersistentLocale() TranslatableWithPersistentLocale::class )); - $this->translatableListener->getExtendedMetadata( - $this->entityManager, - TranslatableWithPersistentLocale::class - ); + $this->translatableListener->getExtendedMetadata($this->entityManager, TranslatableWithPersistentLocale::class); } - public function testTranslationsWithoutPersistentLocale() + public function testTranslationsWithoutPersistentLocale(): void { $this->expectException(MappingException::class); $this->expectExceptionMessage(sprintf( diff --git a/tests/FSi/DoctrineExtensions/Tests/Translatable/QueryBuilderTest.php b/tests/FSi/DoctrineExtensions/Tests/Translatable/QueryBuilderTest.php index 9007c02..af26734 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Translatable/QueryBuilderTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Translatable/QueryBuilderTest.php @@ -23,7 +23,7 @@ class QueryBuilderTest extends BaseTranslatableTest { - public function testJoinTranslationWithWrongJoinType() + public function testJoinTranslationWithWrongJoinType(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Unknown join type "RIGHT"'); @@ -32,12 +32,12 @@ public function testJoinTranslationWithWrongJoinType() $qb->from(Article::class, 'a')->joinTranslations('a.translations', 'RIGHT'); } - public function testJoinTranslationWithAllDefaultArguments() + public function testJoinTranslationWithAllDefaultArguments(): void { $qb = new QueryBuilder($this->entityManager); $qb->select('a')->from(Article::class, 'a')->joinTranslations('a.translations'); - $this->assertEquals( + self::assertEquals( $this->normalizeDql(sprintf( 'SELECT a FROM %s a LEFT JOIN a.translations atranslations', Article::class @@ -48,7 +48,7 @@ public function testJoinTranslationWithAllDefaultArguments() $qb->getQuery()->execute(); } - public function testJoinTranslationWithDefaultLocale() + public function testJoinTranslationWithDefaultLocale(): void { $this->translatableListener->setLocale(self::LANGUAGE_EN); $qb = new QueryBuilder($this->entityManager); @@ -56,9 +56,9 @@ public function testJoinTranslationWithDefaultLocale() $qb->from(Article::class, 'a'); $qb->joinTranslations('a.translations'); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.translations atranslationsen WITH atranslationsen.locale = :atranslationsenloc', Article::class @@ -66,12 +66,8 @@ public function testJoinTranslationWithDefaultLocale() $qb->getDQL() ); - $this->assertNotNull($qb->getParameter('atranslationsenloc')); - - $this->assertEquals( - self::LANGUAGE_EN, - $qb->getParameter('atranslationsenloc')->getValue() - ); + self::assertNotNull($qb->getParameter('atranslationsenloc')); + self::assertEquals(self::LANGUAGE_EN, $qb->getParameter('atranslationsenloc')->getValue()); $qb->getQuery()->execute(); } @@ -84,9 +80,9 @@ public function testInnerJoinTranslationWithCustomLocale() $qb->from(Article::class, 'a'); $qb->joinTranslations('a.translations', Expr\Join::INNER_JOIN, self::LANGUAGE_PL); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a INNER JOIN a.translations atranslationspl WITH atranslationspl.locale = :atranslationsplloc', Article::class @@ -94,17 +90,13 @@ public function testInnerJoinTranslationWithCustomLocale() $qb->getDQL() ); - $this->assertNotNull($qb->getParameter('atranslationsplloc')); - - $this->assertEquals( - self::LANGUAGE_PL, - $qb->getParameter('atranslationsplloc')->getValue() - ); + self::assertNotNull($qb->getParameter('atranslationsplloc')); + self::assertEquals(self::LANGUAGE_PL, $qb->getParameter('atranslationsplloc')->getValue()); $qb->getQuery()->execute(); } - public function testJoinTranslationWithAllCustomParameters() + public function testJoinTranslationWithAllCustomParameters(): void { $this->translatableListener->setLocale(self::LANGUAGE_EN); $qb = new QueryBuilder($this->entityManager); @@ -112,9 +104,9 @@ public function testJoinTranslationWithAllCustomParameters() $qb->from(Article::class, 'a'); $qb->joinTranslations('a.translations', Expr\Join::INNER_JOIN, self::LANGUAGE_PL, 't', 'locale'); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a INNER JOIN a.translations t WITH t.locale = :locale', Article::class @@ -122,17 +114,13 @@ public function testJoinTranslationWithAllCustomParameters() $qb->getDQL() ); - $this->assertNotNull($qb->getParameter('locale')); - - $this->assertEquals( - self::LANGUAGE_PL, - $qb->getParameter('locale')->getValue() - ); + self::assertNotNull($qb->getParameter('locale')); + self::assertEquals(self::LANGUAGE_PL, $qb->getParameter('locale')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableWhereWithCurrentLocale() + public function testTranslatableWhereWithCurrentLocale(): void { $this->translatableListener->setLocale(self::LANGUAGE_EN); $qb = new QueryBuilder($this->entityManager); @@ -140,9 +128,9 @@ public function testTranslatableWhereWithCurrentLocale() $qb->from(Article::class, 'a'); $qb->addTranslatableWhere('a', 'title', 'some title'); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.translations atranslationsen WITH atranslationsen.locale = :atranslationsenloc WHERE atranslationsen.title = :atitleval', @@ -151,15 +139,12 @@ public function testTranslatableWhereWithCurrentLocale() $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_EN, - $qb->getParameter('atranslationsenloc')->getValue() - ); + self::assertEquals(self::LANGUAGE_EN, $qb->getParameter('atranslationsenloc')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableWhereWithDefaultLocale() + public function testTranslatableWhereWithDefaultLocale(): void { $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); $this->translatableListener->setLocale(self::LANGUAGE_PL); @@ -168,32 +153,28 @@ public function testTranslatableWhereWithDefaultLocale() $qb->from(Article::class, 'a'); $qb->addTranslatableWhere('a', 'title', 'some title'); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.translations atranslationspl WITH atranslationspl.locale = :atranslationsplloc LEFT JOIN a.translations atranslationsen WITH atranslationsen.locale = :atranslationsenloc - WHERE CASE WHEN atranslationspl.id IS NOT NULL THEN atranslationspl.title ELSE atranslationsen.title END = :atitleval', + WHERE CASE + WHEN atranslationspl.id IS NOT NULL THEN atranslationspl.title + ELSE atranslationsen.title + END = :atitleval', Article::class )), $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_PL, - $qb->getParameter('atranslationsplloc')->getValue() - ); - - $this->assertEquals( - self::LANGUAGE_EN, - $qb->getParameter('atranslationsenloc')->getValue() - ); + self::assertEquals(self::LANGUAGE_PL, $qb->getParameter('atranslationsplloc')->getValue()); + self::assertEquals(self::LANGUAGE_EN, $qb->getParameter('atranslationsenloc')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableWhereWithCustomAndDefaultLocale() + public function testTranslatableWhereWithCustomAndDefaultLocale(): void { $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); $this->translatableListener->setLocale(self::LANGUAGE_PL); @@ -202,32 +183,28 @@ public function testTranslatableWhereWithCustomAndDefaultLocale() $qb->from(Article::class, 'a'); $qb->addTranslatableWhere('a', 'title', 'some title', self::LANGUAGE_DE); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.translations atranslationsde WITH atranslationsde.locale = :atranslationsdeloc LEFT JOIN a.translations atranslationsen WITH atranslationsen.locale = :atranslationsenloc - WHERE CASE WHEN atranslationsde.id IS NOT NULL THEN atranslationsde.title ELSE atranslationsen.title END = :atitleval', + WHERE CASE + WHEN atranslationsde.id IS NOT NULL THEN atranslationsde.title + ELSE atranslationsen.title + END = :atitleval', Article::class )), $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_DE, - $qb->getParameter('atranslationsdeloc')->getValue() - ); - - $this->assertEquals( - self::LANGUAGE_EN, - $qb->getParameter('atranslationsenloc')->getValue() - ); + self::assertEquals(self::LANGUAGE_DE, $qb->getParameter('atranslationsdeloc')->getValue()); + self::assertEquals(self::LANGUAGE_EN, $qb->getParameter('atranslationsenloc')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableWhereWithSameCurrentAndDefaultLocale() + public function testTranslatableWhereWithSameCurrentAndDefaultLocale(): void { $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); $this->translatableListener->setLocale(self::LANGUAGE_EN); @@ -236,9 +213,9 @@ public function testTranslatableWhereWithSameCurrentAndDefaultLocale() $qb->from(Article::class, 'a'); $qb->addTranslatableWhere('a', 'title', 'some title'); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.translations atranslationsen WITH atranslationsen.locale = :atranslationsenloc WHERE atranslationsen.title = :atitleval', @@ -247,23 +224,20 @@ public function testTranslatableWhereWithSameCurrentAndDefaultLocale() $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_EN, - $qb->getParameter('atranslationsenloc')->getValue() - ); + self::assertEquals(self::LANGUAGE_EN, $qb->getParameter('atranslationsenloc')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableOrderByWithCurrentLocale() + public function testTranslatableOrderByWithCurrentLocale(): void { $this->translatableListener->setLocale(self::LANGUAGE_EN); $qb = new QueryBuilder($this->entityManager); $qb->select('a')->from(Article::class, 'a')->addTranslatableOrderBY('a', 'title', 'ASC'); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.translations atranslationsen WITH atranslationsen.locale = :atranslationsenloc ORDER BY atranslationsen.title ASC', @@ -272,15 +246,12 @@ public function testTranslatableOrderByWithCurrentLocale() $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_EN, - $qb->getParameter('atranslationsenloc')->getValue() - ); + self::assertEquals(self::LANGUAGE_EN, $qb->getParameter('atranslationsenloc')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableOrderByWithDefaultLocale() + public function testTranslatableOrderByWithDefaultLocale(): void { $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); $this->translatableListener->setLocale(self::LANGUAGE_PL); @@ -289,9 +260,12 @@ public function testTranslatableOrderByWithDefaultLocale() $qb->from(Article::class, 'a'); $qb->addTranslatableOrderBy('a', 'title', 'DESC'); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a, CASE WHEN atranslationspl.id IS NOT NULL THEN atranslationspl.title ELSE atranslationsen.title END HIDDEN atitle + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a, CASE + WHEN atranslationspl.id IS NOT NULL THEN atranslationspl.title + ELSE atranslationsen.title + END HIDDEN atitle FROM %s a LEFT JOIN a.translations atranslationspl WITH atranslationspl.locale = :atranslationsplloc LEFT JOIN a.translations atranslationsen WITH atranslationsen.locale = :atranslationsenloc @@ -301,20 +275,13 @@ public function testTranslatableOrderByWithDefaultLocale() $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_PL, - $qb->getParameter('atranslationsplloc')->getValue() - ); - - $this->assertEquals( - self::LANGUAGE_EN, - $qb->getParameter('atranslationsenloc')->getValue() - ); + self::assertEquals(self::LANGUAGE_PL, $qb->getParameter('atranslationsplloc')->getValue()); + self::assertEquals(self::LANGUAGE_EN, $qb->getParameter('atranslationsenloc')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableOrderByWithCustomAndDefaultLocale() + public function testTranslatableOrderByWithCustomAndDefaultLocale(): void { $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); $this->translatableListener->setLocale(self::LANGUAGE_PL); @@ -323,9 +290,12 @@ public function testTranslatableOrderByWithCustomAndDefaultLocale() $qb->from(Article::class, 'a'); $qb->addTranslatableOrderBy('a', 'title', 'DESC', self::LANGUAGE_DE); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a, CASE WHEN atranslationsde.id IS NOT NULL THEN atranslationsde.title ELSE atranslationsen.title END HIDDEN atitle + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a, CASE + WHEN atranslationsde.id IS NOT NULL THEN atranslationsde.title + ELSE atranslationsen.title + END HIDDEN atitle FROM %s a LEFT JOIN a.translations atranslationsde WITH atranslationsde.locale = :atranslationsdeloc LEFT JOIN a.translations atranslationsen WITH atranslationsen.locale = :atranslationsenloc @@ -335,20 +305,13 @@ public function testTranslatableOrderByWithCustomAndDefaultLocale() $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_DE, - $qb->getParameter('atranslationsdeloc')->getValue() - ); - - $this->assertEquals( - self::LANGUAGE_EN, - $qb->getParameter('atranslationsenloc')->getValue() - ); + self::assertEquals(self::LANGUAGE_DE, $qb->getParameter('atranslationsdeloc')->getValue()); + self::assertEquals(self::LANGUAGE_EN, $qb->getParameter('atranslationsenloc')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableOrderByWithSameCurrentAndDefaultLocale() + public function testTranslatableOrderByWithSameCurrentAndDefaultLocale(): void { $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); $this->translatableListener->setLocale(self::LANGUAGE_EN); @@ -357,9 +320,9 @@ public function testTranslatableOrderByWithSameCurrentAndDefaultLocale() $qb->from(Article::class, 'a'); $qb->addTranslatableOrderBy('a', 'title', 'DESC'); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.translations atranslationsen WITH atranslationsen.locale = :atranslationsenloc ORDER BY atranslationsen.title DESC', @@ -368,10 +331,7 @@ public function testTranslatableOrderByWithSameCurrentAndDefaultLocale() $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_EN, - $qb->getParameter('atranslationsenloc')->getValue() - ); + self::assertEquals(self::LANGUAGE_EN, $qb->getParameter('atranslationsenloc')->getValue()); $qb->getQuery()->execute(); } @@ -385,9 +345,9 @@ public function testTranslatableWhereOnTranslatableCollectionWithNull() $qb->from(Article::class, 'a'); $qb->addTranslatableWhere('a', 'comments', null); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.translations atranslationspl WITH atranslationspl.locale = :atranslationsplloc WHERE SIZE(atranslationspl.comments) = 0', @@ -396,15 +356,12 @@ public function testTranslatableWhereOnTranslatableCollectionWithNull() $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_PL, - $qb->getParameter('atranslationsplloc')->getValue() - ); + self::assertEquals(self::LANGUAGE_PL, $qb->getParameter('atranslationsplloc')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableWhereOnCollectionWithNull() + public function testTranslatableWhereOnCollectionWithNull(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); @@ -413,9 +370,9 @@ public function testTranslatableWhereOnCollectionWithNull() $qb->from(Article::class, 'a'); $qb->addTranslatableWhere('a', 'categories', null); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a WHERE SIZE(a.categories) = 0', Article::class @@ -438,9 +395,9 @@ public function testTranslatableWhereOnTranslatableCollectionWithObject() $qb->from(Article::class, 'a'); $qb->addTranslatableWhere('a', 'comments', $comment); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.translations atranslationspl WITH atranslationspl.locale = :atranslationsplloc WHERE :acommentsval MEMBER OF atranslationspl.comments', @@ -449,15 +406,8 @@ public function testTranslatableWhereOnTranslatableCollectionWithObject() $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_PL, - $qb->getParameter('atranslationsplloc')->getValue() - ); - - $this->assertEquals( - $comment, - $qb->getParameter('acommentsval')->getValue() - ); + self::assertEquals(self::LANGUAGE_PL, $qb->getParameter('atranslationsplloc')->getValue()); + self::assertEquals($comment, $qb->getParameter('acommentsval')->getValue()); $qb->getQuery()->execute(); } @@ -472,9 +422,9 @@ public function testTranslatableWhereOnCollectionWithObject() $qb->from(Article::class, 'a'); $qb->addTranslatableWhere('a', 'categories', $category); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a WHERE :acategoriesval MEMBER OF a.categories', Article::class @@ -482,15 +432,12 @@ public function testTranslatableWhereOnCollectionWithObject() $qb->getDQL() ); - $this->assertEquals( - $category, - $qb->getParameter('acategoriesval')->getValue() - ); + self::assertEquals($category, $qb->getParameter('acategoriesval')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableWhereOnTranslatableCollectionWithArray() + public function testTranslatableWhereOnTranslatableCollectionWithArray(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); @@ -505,9 +452,9 @@ public function testTranslatableWhereOnTranslatableCollectionWithArray() $qb->from(Article::class, 'a'); $qb->addTranslatableWhere('a', 'comments', $whereComments); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.translations atranslationspl WITH atranslationspl.locale = :atranslationsplloc LEFT JOIN atranslationspl.comments atranslationsplcommentsjoin @@ -517,20 +464,13 @@ public function testTranslatableWhereOnTranslatableCollectionWithArray() $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_PL, - $qb->getParameter('atranslationsplloc')->getValue() - ); - - $this->assertEquals( - $whereComments, - $qb->getParameter('acommentsval')->getValue() - ); + self::assertEquals(self::LANGUAGE_PL, $qb->getParameter('atranslationsplloc')->getValue()); + self::assertEquals($whereComments, $qb->getParameter('acommentsval')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableWhereOnCollectionWithArray() + public function testTranslatableWhereOnCollectionWithArray(): void { $category1 = new Category(); $category1->setId(1); @@ -543,9 +483,9 @@ public function testTranslatableWhereOnCollectionWithArray() $qb->from(Article::class, 'a'); $qb->addTranslatableWhere('a', 'categories', $whereCategories); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.categories acategoriesjoin WHERE acategoriesjoin IN(:acategoriesval)', @@ -554,15 +494,12 @@ public function testTranslatableWhereOnCollectionWithArray() $qb->getDQL() ); - $this->assertEquals( - $whereCategories, - $qb->getParameter('acategoriesval')->getValue() - ); + self::assertEquals($whereCategories, $qb->getParameter('acategoriesval')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableWhereOnTranslatableCollectionWithNullAndSameDefaultLocale() + public function testTranslatableWhereOnTranslatableCollectionWithNullAndSameDefaultLocale(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $this->translatableListener->setDefaultLocale(self::LANGUAGE_PL); @@ -572,9 +509,9 @@ public function testTranslatableWhereOnTranslatableCollectionWithNullAndSameDefa $qb->from(Article::class, 'a'); $qb->addTranslatableWhere('a', 'comments', null); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.translations atranslationspl WITH atranslationspl.locale = :atranslationsplloc WHERE SIZE(atranslationspl.comments) = 0', @@ -583,15 +520,12 @@ public function testTranslatableWhereOnTranslatableCollectionWithNullAndSameDefa $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_PL, - $qb->getParameter('atranslationsplloc')->getValue() - ); + self::assertEquals(self::LANGUAGE_PL, $qb->getParameter('atranslationsplloc')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableWhereOnTranslatableCollectionWithObjectAndSameDefaultLocale() + public function testTranslatableWhereOnTranslatableCollectionWithObjectAndSameDefaultLocale(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $this->translatableListener->setDefaultLocale(self::LANGUAGE_PL); @@ -604,9 +538,9 @@ public function testTranslatableWhereOnTranslatableCollectionWithObjectAndSameDe $qb->from(Article::class, 'a'); $qb->addTranslatableWhere('a', 'comments', $comment); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.translations atranslationspl WITH atranslationspl.locale = :atranslationsplloc WHERE :acommentsval MEMBER OF atranslationspl.comments', @@ -615,20 +549,13 @@ public function testTranslatableWhereOnTranslatableCollectionWithObjectAndSameDe $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_PL, - $qb->getParameter('atranslationsplloc')->getValue() - ); - - $this->assertEquals( - $comment, - $qb->getParameter('acommentsval')->getValue() - ); + self::assertEquals(self::LANGUAGE_PL, $qb->getParameter('atranslationsplloc')->getValue()); + self::assertEquals($comment, $qb->getParameter('acommentsval')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableWhereOnTranslatableCollectionWithArrayAndSameDefaultLocale() + public function testTranslatableWhereOnTranslatableCollectionWithArrayAndSameDefaultLocale(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $this->translatableListener->setDefaultLocale(self::LANGUAGE_PL); @@ -644,9 +571,9 @@ public function testTranslatableWhereOnTranslatableCollectionWithArrayAndSameDef $qb->from(Article::class, 'a'); $qb->addTranslatableWhere('a', 'comments', $whereComments); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.translations atranslationspl WITH atranslationspl.locale = :atranslationsplloc LEFT JOIN atranslationspl.comments atranslationsplcommentsjoin @@ -656,20 +583,13 @@ public function testTranslatableWhereOnTranslatableCollectionWithArrayAndSameDef $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_PL, - $qb->getParameter('atranslationsplloc')->getValue() - ); - - $this->assertEquals( - $whereComments, - $qb->getParameter('acommentsval')->getValue() - ); + self::assertEquals(self::LANGUAGE_PL, $qb->getParameter('atranslationsplloc')->getValue()); + self::assertEquals($whereComments, $qb->getParameter('acommentsval')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableWhereOnTranslatableCollectionWithNullAndDifferentDefaultLocale() + public function testTranslatableWhereOnTranslatableCollectionWithNullAndDifferentDefaultLocale(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); @@ -679,9 +599,9 @@ public function testTranslatableWhereOnTranslatableCollectionWithNullAndDifferen $qb->from(Article::class, 'a'); $qb->addTranslatableWhere('a', 'comments', null); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.translations atranslationspl WITH atranslationspl.locale = :atranslationsplloc LEFT JOIN a.translations atranslationsen WITH atranslationsen.locale = :atranslationsenloc @@ -695,20 +615,13 @@ public function testTranslatableWhereOnTranslatableCollectionWithNullAndDifferen $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_PL, - $qb->getParameter('atranslationsplloc')->getValue() - ); - - $this->assertEquals( - self::LANGUAGE_EN, - $qb->getParameter('atranslationsenloc')->getValue() - ); + self::assertEquals(self::LANGUAGE_PL, $qb->getParameter('atranslationsplloc')->getValue()); + self::assertEquals(self::LANGUAGE_EN, $qb->getParameter('atranslationsenloc')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableWhereOnTranslatableCollectionWithObjectAndDifferentDefaultLocale() + public function testTranslatableWhereOnTranslatableCollectionWithObjectAndDifferentDefaultLocale(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); @@ -721,9 +634,9 @@ public function testTranslatableWhereOnTranslatableCollectionWithObjectAndDiffer $qb->from(Article::class, 'a'); $qb->addTranslatableWhere('a', 'comments', $comment); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.translations atranslationspl WITH atranslationspl.locale = :atranslationsplloc LEFT JOIN a.translations atranslationsen WITH atranslationsen.locale = :atranslationsenloc @@ -737,25 +650,14 @@ public function testTranslatableWhereOnTranslatableCollectionWithObjectAndDiffer $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_PL, - $qb->getParameter('atranslationsplloc')->getValue() - ); - - $this->assertEquals( - self::LANGUAGE_EN, - $qb->getParameter('atranslationsenloc')->getValue() - ); - - $this->assertEquals( - $comment, - $qb->getParameter('acommentsval')->getValue() - ); + self::assertEquals(self::LANGUAGE_PL, $qb->getParameter('atranslationsplloc')->getValue()); + self::assertEquals(self::LANGUAGE_EN, $qb->getParameter('atranslationsenloc')->getValue()); + self::assertEquals($comment, $qb->getParameter('acommentsval')->getValue()); $qb->getQuery()->execute(); } - public function testTranslatableWhereOnTranslatableCollectionWithArrayAndDifferentDefaultLocale() + public function testTranslatableWhereOnTranslatableCollectionWithArrayAndDifferentDefaultLocale(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); @@ -771,9 +673,9 @@ public function testTranslatableWhereOnTranslatableCollectionWithArrayAndDiffere $qb->from(Article::class, 'a'); $qb->addTranslatableWhere('a', 'comments', $whereComments); - $this->assertEquals( - $this->normalizeDql(sprintf(' - SELECT a + self::assertEquals( + $this->normalizeDql(sprintf( + 'SELECT a FROM %s a LEFT JOIN a.translations atranslationspl WITH atranslationspl.locale = :atranslationsplloc LEFT JOIN a.translations atranslationsen WITH atranslationsen.locale = :atranslationsenloc @@ -789,20 +691,9 @@ public function testTranslatableWhereOnTranslatableCollectionWithArrayAndDiffere $qb->getDQL() ); - $this->assertEquals( - self::LANGUAGE_PL, - $qb->getParameter('atranslationsplloc')->getValue() - ); - - $this->assertEquals( - self::LANGUAGE_EN, - $qb->getParameter('atranslationsenloc')->getValue() - ); - - $this->assertEquals( - $whereComments, - $qb->getParameter('acommentsval')->getValue() - ); + self::assertEquals(self::LANGUAGE_PL, $qb->getParameter('atranslationsplloc')->getValue()); + self::assertEquals(self::LANGUAGE_EN, $qb->getParameter('atranslationsenloc')->getValue()); + self::assertEquals($whereComments, $qb->getParameter('acommentsval')->getValue()); $qb->getQuery()->execute(); } @@ -819,7 +710,7 @@ protected function getUsedEntityFixtures(): array ]; } - private function normalizeDql($dql) + private function normalizeDql(string $dql): string { return preg_replace('/\s+/', ' ', trim($dql)); } diff --git a/tests/FSi/DoctrineExtensions/Tests/Translatable/RepositoryTest.php b/tests/FSi/DoctrineExtensions/Tests/Translatable/RepositoryTest.php index b5dc740..2db97fe 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Translatable/RepositoryTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Translatable/RepositoryTest.php @@ -26,7 +26,7 @@ class RepositoryTest extends BaseTranslatableTest /** * Test if call to getTranslation creates non existent translations */ - public function testCreatingNonExistentTranslationThroughRepository() + public function testCreatingNonExistentTranslationThroughRepository(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $repository = $this->entityManager->getRepository(Article::class); @@ -36,21 +36,21 @@ public function testCreatingNonExistentTranslationThroughRepository() $this->entityManager->flush(); $translationEn = $repository->getTranslation($article, self::LANGUAGE_EN); - $this->assertTrue($article->getTranslations()->contains($translationEn)); + self::assertTrue($article->getTranslations()->contains($translationEn)); $translationPl = $repository->getTranslation($article, self::LANGUAGE_PL); - $this->assertTrue($article->getTranslations()->contains($translationPl)); + self::assertTrue($article->getTranslations()->contains($translationPl)); - $this->assertSame($translationEn, $article->getTranslations()->get(self::LANGUAGE_EN)); - $this->assertSame($translationPl, $article->getTranslations()->get(self::LANGUAGE_PL)); - $this->assertSame($translationPl, $repository->getTranslation($article, self::LANGUAGE_PL)); + self::assertSame($translationEn, $article->getTranslations()->get(self::LANGUAGE_EN)); + self::assertSame($translationPl, $article->getTranslations()->get(self::LANGUAGE_PL)); + self::assertSame($translationPl, $repository->getTranslation($article, self::LANGUAGE_PL)); } /** * Test if call to hasTranslation returns true for existing translations * and false otherwise */ - public function testCheckingIfTranslationExistsThroughRepository() + public function testCheckingIfTranslationExistsThroughRepository(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $repository = $this->entityManager->getRepository(Article::class); @@ -65,11 +65,11 @@ public function testCheckingIfTranslationExistsThroughRepository() $this->entityManager->clear(); $article = $repository->find($article->getId()); - $this->assertTrue($repository->hasTranslation($article, self::LANGUAGE_EN)); - $this->assertFalse($repository->hasTranslation($article, self::LANGUAGE_PL)); + self::assertTrue($repository->hasTranslation($article, self::LANGUAGE_EN)); + self::assertFalse($repository->hasTranslation($article, self::LANGUAGE_PL)); } - public function testNotOverwritingTranslationForNewObject() + public function testNotOverwritingTranslationForNewObject(): void { $this->translatableListener->setLocale(self::LANGUAGE_EN); $repository = $this->entityManager->getRepository(Article::class); @@ -90,43 +90,38 @@ public function testNotOverwritingTranslationForNewObject() $this->entityManager->refresh($article); - $this->assertEquals( - 2, - count($article->getTranslations()), - 'Number of translations is not valid' - ); - - $this->assertAttributeEquals(self::ENGLISH_TITLE_1, 'title', $article); - $this->assertAttributeEquals(self::ENGLISH_CONTENTS_1, 'contents', $article); + self::assertCount(2, $article->getTranslations(), 'Number of translations is not valid'); + self::assertEquals(self::ENGLISH_TITLE_1, $article->getTitle()); + self::assertEquals(self::ENGLISH_CONTENTS_1, $article->getContents()); } /** * Test if query builder returned by translatable repository has join to translation entity * and is constrained to current locale */ - public function testTranslatableRepositoryCreateQueryBuilder() + public function testTranslatableRepositoryCreateQueryBuilder(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); $qb = $this->entityManager->getRepository(Article::class)->createTranslatableQueryBuilder('a', 't'); - $this->assertEquals( + self::assertEquals( sprintf( 'SELECT a, t, dt FROM %s a LEFT JOIN a.translations t WITH t.locale = :locale' - . ' LEFT JOIN a.translations dt WITH dt.locale = :deflocale', + . ' LEFT JOIN a.translations dt WITH dt.locale = :deflocale', Article::class ), $qb->getQuery()->getDql(), 'Wrong DQL returned from QueryBuilder' ); - $this->assertEquals( + self::assertEquals( self::LANGUAGE_PL, $qb->getParameter('locale')->getValue(), 'Parameter :locale has wrong value' ); - $this->assertEquals( + self::assertEquals( self::LANGUAGE_EN, $qb->getParameter('deflocale')->getValue(), 'Parameter :deflocale has wrong value' @@ -137,13 +132,13 @@ public function testTranslatableRepositoryCreateQueryBuilder() * Test if query builder returned by translatable repository has join to translation entity * and is constrained to current locale */ - public function testTranslatableRepositoryCreateQueryBuilderWithLocaleSameAsDefaultLocale() + public function testTranslatableRepositoryCreateQueryBuilderWithLocaleSameAsDefaultLocale(): void { $this->translatableListener->setLocale(self::LANGUAGE_EN); $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); $qb = $this->entityManager->getRepository(Article::class)->createTranslatableQueryBuilder('a', 't'); - $this->assertEquals( + self::assertEquals( sprintf( 'SELECT a, t FROM %s a LEFT JOIN a.translations t WITH t.locale = :locale', Article::class @@ -152,14 +147,14 @@ public function testTranslatableRepositoryCreateQueryBuilderWithLocaleSameAsDefa 'Wrong DQL returned from QueryBuilder' ); - $this->assertEquals( + self::assertEquals( self::LANGUAGE_EN, $qb->getParameter('locale')->getValue(), 'Parameter :locale has wrong value' ); } - public function testPostHydrateWithTranslatableQueryBuilder() + public function testPostHydrateWithTranslatableQueryBuilder(): void { $this->translatableListener->setLocale(self::LANGUAGE_EN); $repository = $this->entityManager->getRepository(Article::class); @@ -184,21 +179,17 @@ public function testPostHydrateWithTranslatableQueryBuilder() $articles = $query->execute(); foreach ($articles as $article) { - $this->assertAttributeEquals(self::ENGLISH_TITLE_1, 'title', $article); - $this->assertAttributeEquals(self::ENGLISH_CONTENTS_1, 'contents', $article); + self::assertEquals(self::ENGLISH_TITLE_1, $article->getTitle()); + self::assertEquals(self::ENGLISH_CONTENTS_1, $article->getContents()); } - $this->assertEquals( - 4, - count($this->logger->queries), - 'Reloading executed wrong number of queries' - ); + self::assertCount(4, $this->logger->queries, 'Reloading executed wrong number of queries'); } /** * tests that findTranslatableBy will return correct entity */ - public function testFindTranslatableByFields() + public function testFindTranslatableByFields(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); @@ -222,18 +213,18 @@ public function testFindTranslatableByFields() 'comments' => $comment, //translatable property in Article - one to many association ], ['date' => 'ASC', 'title' => 'DESC']); - $this->assertCount(1, $articles); - $this->assertEquals(self::LANGUAGE_PL, $articles[0]->getLocale()); - $this->assertEquals(self::POLISH_TITLE_1, $articles[0]->getTitle()); - $this->assertEquals(self::POLISH_TEASER, $articles[0]->getTeaser()); - $this->assertEquals(self::POLISH_CONTENTS_1, $articles[0]->getContents()); + self::assertCount(1, $articles); + self::assertEquals(self::LANGUAGE_PL, $articles[0]->getLocale()); + self::assertEquals(self::POLISH_TITLE_1, $articles[0]->getTitle()); + self::assertEquals(self::POLISH_TEASER, $articles[0]->getTeaser()); + self::assertEquals(self::POLISH_CONTENTS_1, $articles[0]->getContents()); } /** * test that findTranslatableBy will return fields from default translation * if translation in current locale was not found */ - public function testFindTranslatableByLocaleFallback() + public function testFindTranslatableByLocaleFallback(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); @@ -246,15 +237,15 @@ public function testFindTranslatableByLocaleFallback() /** @var Article $article */ $articles = $repository->findTranslatableBy(['date' => '2014-01-01 00:00:00']); - $this->assertEquals(self::ENGLISH_TITLE_1, $articles[0]->getTitle()); - $this->assertEquals(self::ENGLISH_TEASER, $articles[0]->getTeaser()); - $this->assertEquals(self::ENGLISH_CONTENTS_1, $articles[0]->getContents()); + self::assertEquals(self::ENGLISH_TITLE_1, $articles[0]->getTitle()); + self::assertEquals(self::ENGLISH_TEASER, $articles[0]->getTeaser()); + self::assertEquals(self::ENGLISH_CONTENTS_1, $articles[0]->getContents()); } /** * test that findTranslatableBy will return fields from translation in specified locale */ - public function testFindTranslatableByCustomLocale() + public function testFindTranslatableByCustomLocale(): void { $this->translatableListener->setLocale(self::LANGUAGE_DE); $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); @@ -273,15 +264,15 @@ public function testFindTranslatableByCustomLocale() self::LANGUAGE_PL ); - $this->assertEquals(self::ENGLISH_TITLE_1, $articles[0]->getTitle()); - $this->assertEquals(self::ENGLISH_TEASER, $articles[0]->getTeaser()); - $this->assertEquals(self::ENGLISH_CONTENTS_1, $articles[0]->getContents()); + self::assertEquals(self::ENGLISH_TITLE_1, $articles[0]->getTitle()); + self::assertEquals(self::ENGLISH_TEASER, $articles[0]->getTeaser()); + self::assertEquals(self::ENGLISH_CONTENTS_1, $articles[0]->getContents()); } /** * tests that findTranslatableOneBy will return correct entity and if not found throw exception */ - public function testFindTranslatableOneByFields() + public function testFindTranslatableOneByFields(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); @@ -305,14 +296,13 @@ public function testFindTranslatableOneByFields() 'comments' => [$comment1, $comment2], //translatable property in Article - one to many association ]); - $this->assertEquals(self::LANGUAGE_PL, $article->getLocale()); - $this->assertEquals(self::POLISH_TITLE_1, $article->getTitle()); - $this->assertEquals(self::POLISH_TEASER, $article->getTeaser()); - $this->assertEquals(self::POLISH_CONTENTS_1, $article->getContents()); + self::assertEquals(self::LANGUAGE_PL, $article->getLocale()); + self::assertEquals(self::POLISH_TITLE_1, $article->getTitle()); + self::assertEquals(self::POLISH_TEASER, $article->getTeaser()); + self::assertEquals(self::POLISH_CONTENTS_1, $article->getContents()); $this->expectException(NoResultException::class); - - //value that not exists + // value that not exists $repository->findTranslatableOneBy(['date' => '2014-01-01 00:00:01']); } @@ -320,7 +310,7 @@ public function testFindTranslatableOneByFields() * test that findTranslatableOneBy will return fields from default translation * if translation in current locale was not found */ - public function testFindTranslatableOneByLocaleFallback() + public function testFindTranslatableOneByLocaleFallback(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); @@ -332,15 +322,15 @@ public function testFindTranslatableOneByLocaleFallback() /** @var Article $article */ $article = $repository->findTranslatableOneBy(['date' => '2014-01-01 00:00:00']); - $this->assertEquals(self::ENGLISH_TITLE_1, $article->getTitle()); - $this->assertEquals(self::ENGLISH_TEASER, $article->getTeaser()); - $this->assertEquals(self::ENGLISH_CONTENTS_1, $article->getContents()); + self::assertEquals(self::ENGLISH_TITLE_1, $article->getTitle()); + self::assertEquals(self::ENGLISH_TEASER, $article->getTeaser()); + self::assertEquals(self::ENGLISH_CONTENTS_1, $article->getContents()); } /** * test that findTranslatableOneBy will return fields from translation in specified locale */ - public function testFindTranslatableOneByWithCustomLocale() + public function testFindTranslatableOneByWithCustomLocale(): void { $this->translatableListener->setLocale(self::LANGUAGE_DE); $this->translatableListener->setDefaultLocale(self::LANGUAGE_EN); @@ -357,9 +347,9 @@ public function testFindTranslatableOneByWithCustomLocale() self::LANGUAGE_PL ); - $this->assertEquals(self::ENGLISH_TITLE_1, $article->getTitle()); - $this->assertEquals(self::ENGLISH_TEASER, $article->getTeaser()); - $this->assertEquals(self::ENGLISH_CONTENTS_1, $article->getContents()); + self::assertEquals(self::ENGLISH_TITLE_1, $article->getTitle()); + self::assertEquals(self::ENGLISH_TEASER, $article->getTeaser()); + self::assertEquals(self::ENGLISH_CONTENTS_1, $article->getContents()); } protected function getUsedEntityFixtures(): array @@ -374,7 +364,7 @@ protected function getUsedEntityFixtures(): array ]; } - private function fillDataForFindTranslatable() + private function fillDataForFindTranslatable(): void { /** @var TranslatableRepository $repository */ $repository = $this->entityManager->getRepository(Article::class); diff --git a/tests/FSi/DoctrineExtensions/Tests/Translatable/TranslatableCollectionsTest.php b/tests/FSi/DoctrineExtensions/Tests/Translatable/TranslatableCollectionsTest.php index c5bc997..329bb55 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Translatable/TranslatableCollectionsTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Translatable/TranslatableCollectionsTest.php @@ -15,13 +15,15 @@ use FSi\DoctrineExtensions\Tests\Translatable\Fixture\ArticlePage; use FSi\DoctrineExtensions\Tests\Translatable\Fixture\ArticleTranslation; use FSi\DoctrineExtensions\Tests\Translatable\Fixture\Comment; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\ORM\PersistentCollection; class TranslatableCollectionsTest extends BaseTranslatableTest { public const POLISH_ARTICLE_PAGE_TITLE_1 = 'Tytuł strony artykułu 1'; public const POLISH_ARTICLE_PAGE_TITLE_2 = 'Tytuł strony artykułu 2'; - public function testTranslatedOneToManyCollection() + public function testTranslatedOneToManyCollection(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $this->logger->enabled = true; @@ -31,38 +33,30 @@ public function testTranslatedOneToManyCollection() $article->addComment(new Comment(self::POLISH_COMMENT_2)); $this->persistAndFlush($article); - $this->assertEquals( - 6, - count($this->logger->queries), - 'Incorrect number of performed insert queries' - ); + self::assertCount(6, $this->logger->queries, 'Incorrect number of performed insert queries'); $this->logger->queries = []; /* @var $article Article */ $article = $this->entityManager->find(Article::class, $article->getId()); - $this->assertEquals( - 5, - count($this->logger->queries), - 'Reloading executed wrong number of queries' - ); + self::assertCount(5, $this->logger->queries, 'Reloading executed wrong number of queries'); $translation = $article->getTranslations()[self::LANGUAGE_PL]; - $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $article->getComments()); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $translation->getComments()); - $this->assertEquals( - $article->getComments()->count(), + self::assertInstanceOf(ArrayCollection::class, $article->getComments()); + self::assertInstanceOf(PersistentCollection::class, $translation->getComments()); + self::assertEquals( 2, + $article->getComments()->count(), 'The number of translated object comments is incorrect' ); - $this->assertEquals( - $translation->getComments()->count(), + self::assertEquals( 2, + $translation->getComments()->count(), 'The number of translation comments is incorrect' ); } - public function testTranslatedOneToManyRemoval() + public function testTranslatedOneToManyRemoval(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); @@ -71,14 +65,14 @@ public function testTranslatedOneToManyRemoval() $this->persistAndFlush($article); $article = $this->entityManager->find(Article::class, $article->getId()); - $this->assertEquals( - $article->getComments()->count(), + self::assertEquals( 1, + $article->getComments()->count(), 'The number of translated object comments is incorrect' ); - $this->assertEquals( - $article->getTranslations()[self::LANGUAGE_PL]->getComments()->count(), + self::assertEquals( 1, + $article->getTranslations()[self::LANGUAGE_PL]->getComments()->count(), 'The number of translation comments is incorrect' ); @@ -89,19 +83,19 @@ public function testTranslatedOneToManyRemoval() $this->entityManager->clear(); $article = $this->entityManager->find(Article::class, $article->getId()); - $this->assertEquals( - $article->getComments()->count(), + self::assertEquals( 0, + $article->getComments()->count(), 'The number of translated object comments is incorrect' ); - $this->assertEquals( - $article->getTranslations()[self::LANGUAGE_PL]->getComments()->count(), + self::assertEquals( 0, + $article->getTranslations()[self::LANGUAGE_PL]->getComments()->count(), 'The number of translation comments is incorrect' ); } - public function testTranslatedManyToManyCollection() + public function testTranslatedManyToManyCollection(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $this->logger->enabled = true; @@ -111,38 +105,22 @@ public function testTranslatedManyToManyCollection() $article->addPage(new ArticlePage(self::POLISH_ARTICLE_PAGE_TITLE_2)); $this->persistAndFlush($article); - $this->assertEquals( - 8, - count($this->logger->queries), - 'Incorrect number of performed insert queries' - ); + self::assertCount(8, $this->logger->queries, 'Incorrect number of performed insert queries'); $this->logger->queries = []; /* @var $article Article */ $article = $this->entityManager->find(Article::class, $article->getId()); - $this->assertEquals( - 5, - count($this->logger->queries), - 'Reloading executed wrong number of queries' - ); + self::assertCount(5, $this->logger->queries, 'Reloading executed wrong number of queries'); $translation = $article->getTranslations()[self::LANGUAGE_PL]; - $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $article->getPages()); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $translation->getPages()); - $this->assertEquals( - 2, - $article->getPages()->count(), - 'The number of translated object pages is incorrect' - ); - $this->assertEquals( - 2, - $translation->getPages()->count(), - 'The number of translation pages is incorrect' - ); + self::assertInstanceOf(ArrayCollection::class, $article->getPages()); + self::assertInstanceOf(PersistentCollection::class, $translation->getPages()); + self::assertEquals(2, $article->getPages()->count(), 'The number of translated object pages is incorrect'); + self::assertEquals(2, $translation->getPages()->count(), 'The number of translation pages is incorrect'); } - public function testTranslatedManyToManyRemoval() + public function testTranslatedManyToManyRemoval(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); @@ -151,14 +129,14 @@ public function testTranslatedManyToManyRemoval() $this->persistAndFlush($article); $article = $this->entityManager->find(Article::class, $article->getId()); - $this->assertEquals( - $article->getPages()->count(), + self::assertEquals( 1, + $article->getPages()->count(), 'The number of translated object comments is incorrect' ); - $this->assertEquals( - $article->getTranslations()[self::LANGUAGE_PL]->getPages()->count(), + self::assertEquals( 1, + $article->getTranslations()[self::LANGUAGE_PL]->getPages()->count(), 'The number of translation comments is incorrect' ); @@ -169,19 +147,19 @@ public function testTranslatedManyToManyRemoval() $this->entityManager->clear(); $article = $this->entityManager->find(Article::class, $article->getId()); - $this->assertEquals( + self::assertEquals( 0, $article->getPages()->count(), 'The number of translated object pages is incorrect' ); - $this->assertEquals( + self::assertEquals( 0, $article->getTranslations()[self::LANGUAGE_PL]->getPages()->count(), 'The number of translation pages is incorrect' ); } - public function testTranslatedUnidirectionalOneToManyCollection() + public function testTranslatedUnidirectionalOneToManyCollection(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $this->logger->enabled = true; @@ -191,38 +169,30 @@ public function testTranslatedUnidirectionalOneToManyCollection() $article->addSpecialComment(new Comment(self::POLISH_COMMENT_2)); $this->persistAndFlush($article); - $this->assertEquals( - 8, - count($this->logger->queries), - 'Incorrect number of performed insert queries' - ); + self::assertCount(8, $this->logger->queries, 'Incorrect number of performed insert queries'); $this->logger->queries = []; /* @var $article Article */ $article = $this->entityManager->find(Article::class, $article->getId()); - $this->assertEquals( - 5, - count($this->logger->queries), - 'Reloading executed wrong number of queries' - ); + self::assertCount(5, $this->logger->queries, 'Reloading executed wrong number of queries'); $translation = $article->getTranslations()[self::LANGUAGE_PL]; - $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $article->getSpecialComments()); - $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $translation->getSpecialComments()); - $this->assertEquals( + self::assertInstanceOf(ArrayCollection::class, $article->getSpecialComments()); + self::assertInstanceOf(PersistentCollection::class, $translation->getSpecialComments()); + self::assertEquals( 2, $article->getSpecialComments()->count(), 'The number of translated object pages is incorrect' ); - $this->assertEquals( + self::assertEquals( 2, $translation->getSpecialComments()->count(), 'The number of translation pages is incorrect' ); } - public function testTranslatedUnidirectionalOneToManyRemoval() + public function testTranslatedUnidirectionalOneToManyRemoval(): void { $this->translatableListener->setLocale(self::LANGUAGE_PL); $article = $this->createArticle(); @@ -230,14 +200,14 @@ public function testTranslatedUnidirectionalOneToManyRemoval() $this->persistAndFlush($article); $article = $this->entityManager->find(Article::class, $article->getId()); - $this->assertEquals( - $article->getSpecialComments()->count(), + self::assertEquals( 1, + $article->getSpecialComments()->count(), 'The number of translated object comments is incorrect' ); - $this->assertEquals( - $article->getTranslations()[self::LANGUAGE_PL]->getSpecialComments()->count(), + self::assertEquals( 1, + $article->getTranslations()[self::LANGUAGE_PL]->getSpecialComments()->count(), 'The number of translation comments is incorrect' ); @@ -248,12 +218,12 @@ public function testTranslatedUnidirectionalOneToManyRemoval() $this->entityManager->clear(); $article = $this->entityManager->find(Article::class, $article->getId()); - $this->assertEquals( + self::assertEquals( 0, $article->getSpecialComments()->count(), 'The number of translated object pages is incorrect' ); - $this->assertEquals( + self::assertEquals( 0, $article->getTranslations()[self::LANGUAGE_PL]->getSpecialComments()->count(), 'The number of translation pages is incorrect' diff --git a/tests/FSi/DoctrineExtensions/Tests/Translatable/XMLTest.php b/tests/FSi/DoctrineExtensions/Tests/Translatable/XMLTest.php index d8209e5..3907754 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Translatable/XMLTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Translatable/XMLTest.php @@ -11,14 +11,14 @@ namespace FSi\DoctrineExtensions\Tests\Translatable; -use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; use Doctrine\ORM\Mapping\Driver\XmlDriver; +use Doctrine\Persistence\Mapping\Driver\MappingDriver; use FSi\DoctrineExtensions\Tests\Translatable\Fixture\Common\Page; use FSi\DoctrineExtensions\Tests\Translatable\Fixture\Common\PageTranslation; class XMLTest extends BaseTranslatableTest { - public function testXMLMapping() + public function testXMLMapping(): void { $this->logger->enabled = true; @@ -35,30 +35,10 @@ public function testXMLMapping() $this->entityManager->flush(); $this->entityManager->refresh($page); - $this->assertEquals( - 9, - count($this->logger->queries), - 'Flushing executed wrong number of queries' - ); - - $translationCount = count($page->getTranslations()); - $this->assertEquals( - 2, - $translationCount, - 'Number of translations is not valid' - ); - - $this->assertAttributeEquals( - self::POLISH_CONTENTS_1, - 'content', - $page->getTranslation(self::LANGUAGE_PL) - ); - - $this->assertAttributeEquals( - self::ENGLISH_CONTENTS_1, - 'content', - $page->getTranslation(self::LANGUAGE_EN) - ); + self::assertCount(9, $this->logger->queries, 'Flushing executed wrong number of queries'); + self::assertCount(2, $page->getTranslations(), 'Number of translations is not valid'); + self::assertEquals(self::POLISH_CONTENTS_1, $page->getTranslation(self::LANGUAGE_PL)->getContent()); + self::assertEquals(self::ENGLISH_CONTENTS_1, $page->getTranslation(self::LANGUAGE_EN)->getContent()); } protected function getMetadataDriverImplementation(): MappingDriver diff --git a/tests/FSi/DoctrineExtensions/Tests/Translatable/YAMLTest.php b/tests/FSi/DoctrineExtensions/Tests/Translatable/YAMLTest.php index e116c11..4f08763 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Translatable/YAMLTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Translatable/YAMLTest.php @@ -11,14 +11,14 @@ namespace FSi\DoctrineExtensions\Tests\Translatable; -use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; +use Doctrine\Persistence\Mapping\Driver\MappingDriver; use FSi\DoctrineExtensions\Tests\Translatable\Fixture\Common\Page; use FSi\DoctrineExtensions\Tests\Translatable\Fixture\Common\PageTranslation; class YAMLTest extends BaseTranslatableTest { - public function testYAMLMapping() + public function testYAMLMapping(): void { $this->logger->enabled = true; @@ -35,30 +35,10 @@ public function testYAMLMapping() $this->entityManager->flush(); $this->entityManager->refresh($page); - $this->assertEquals( - 9, - count($this->logger->queries), - 'Flushing executed wrong number of queries' - ); - - $translationCount = count($page->getTranslations()); - $this->assertEquals( - 2, - $translationCount, - 'Number of translations is not valid' - ); - - $this->assertAttributeEquals( - self::POLISH_CONTENTS_1, - 'content', - $page->getTranslation(self::LANGUAGE_PL) - ); - - $this->assertAttributeEquals( - self::ENGLISH_CONTENTS_1, - 'content', - $page->getTranslation(self::LANGUAGE_EN) - ); + self::assertCount(9, $this->logger->queries, 'Flushing executed wrong number of queries'); + self::assertCount(2, $page->getTranslations(), 'Number of translations is not valid'); + self::assertEquals(self::POLISH_CONTENTS_1, $page->getTranslation(self::LANGUAGE_PL)->getContent()); + self::assertEquals(self::ENGLISH_CONTENTS_1, $page->getTranslation(self::LANGUAGE_EN)->getContent()); } protected function getMetadataDriverImplementation(): MappingDriver diff --git a/tests/FSi/DoctrineExtensions/Tests/Uploadable/DriversTest.php b/tests/FSi/DoctrineExtensions/Tests/Uploadable/DriversTest.php index 4d5ac68..e40d3d6 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Uploadable/DriversTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Uploadable/DriversTest.php @@ -23,12 +23,12 @@ class DriversTest extends TestCase /** * @dataProvider drivers */ - public function testDrivers(string $class) + public function testDrivers(string $class): void { - $this->assertTrue(class_exists($class)); + self::assertTrue(class_exists($class)); } - public static function drivers() + public static function drivers(): array { return [ [Xml::class], diff --git a/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileHandler/BaseHandlerTest.php b/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileHandler/BaseHandlerTest.php index 86b9a47..385295e 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileHandler/BaseHandlerTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileHandler/BaseHandlerTest.php @@ -26,27 +26,27 @@ abstract class BaseHandlerTest extends TestCase */ protected $handler; - public function testImplementation() + public function testImplementation(): void { - $this->assertTrue($this->handler instanceof FileHandlerInterface); + self::assertInstanceOf(FileHandlerInterface::class, $this->handler); } /** * @dataProvider wrongInputs */ - public function testGetContentForWrongInputs($input) + public function testGetContentForWrongInputs($input): void { $this->expectException(RuntimeException::class); - $this->assertNull($this->handler->getContent($input)); + self::assertNull($this->handler->getContent($input)); } /** * @dataProvider wrongInputs */ - public function testGetNameForWrongInput($input) + public function testGetNameForWrongInput($input): void { $this->expectException(RuntimeException::class); - $this->assertNull($this->handler->getName($input)); + self::assertNull($this->handler->getName($input)); } /** @@ -54,16 +54,16 @@ public function testGetNameForWrongInput($input) */ public function testNotSupports($input) { - $this->assertFalse($this->handler->supports($input)); + self::assertFalse($this->handler->supports($input)); } - protected function tearDown() + protected function tearDown(): void { Utils::deleteRecursive(FILESYSTEM1); Utils::deleteRecursive(FILESYSTEM2); } - public static function wrongInputs() + public static function wrongInputs(): array { return [ ['not file'], diff --git a/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileHandler/ChainHandlerTest.php b/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileHandler/ChainHandlerTest.php index 4dd3895..a46739b 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileHandler/ChainHandlerTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileHandler/ChainHandlerTest.php @@ -14,42 +14,42 @@ use FSi\DoctrineExtensions\Uploadable\Exception\RuntimeException; use FSi\DoctrineExtensions\Uploadable\FileHandler\ChainHandler; use FSi\DoctrineExtensions\Uploadable\FileHandler\FileHandlerInterface; +use PHPUnit\Framework\MockObject\MockObject; class ChainHandlerTest extends BaseHandlerTest { - protected function setUp() + protected function setUp(): void { $this->handler = new ChainHandler(); } - public function testImplementation() + public function testImplementation(): void { $handler = new ChainHandler(); - $this->assertTrue($handler instanceof FileHandlerInterface); + self::assertInstanceOf(FileHandlerInterface::class, $handler); } - public function testInitializableWithoutHandlers() + public function testInitializableWithoutHandlers(): void { $handler = new ChainHandler(); - $this->assertInstanceof(ChainHandler::class, $handler); + self::assertInstanceof(ChainHandler::class, $handler); $handler = new ChainHandler([]); - $this->assertInstanceof(ChainHandler::class, $handler); - + self::assertInstanceof(ChainHandler::class, $handler); } - public function testIsNotInitializableWithWrongHandlers2() + public function testIsNotInitializableWithWrongHandlers2(): void { $this->expectException(RuntimeException::class); new ChainHandler(['not a handler']); } - public function testIsInitializableWithHandlers() + public function testIsInitializableWithHandlers(): void { $handler = new ChainHandler([$this->getHandlerMock()]); - $this->assertInstanceof(ChainHandler::class, $handler); + self::assertInstanceof(ChainHandler::class, $handler); } - public function testPassesCallToHandlersInProperOrder() + public function testPassesCallToHandlersInProperOrder(): void { $one = $this->getHandlerMock(); $two = $this->getHandlerMock(); @@ -63,75 +63,79 @@ public function testPassesCallToHandlersInProperOrder() $counter = 0; $nameCounter = 0; $contentCounter = 0; - $that = $this; - $one->expects($this->any()) - ->method('supports') + $one->method('supports') ->with($input) - ->will($this->returnCallback( - function() use (&$counter, $that) { + ->willReturnCallback( + static function () use (&$counter) { $counter++; - $that->assertEquals(1, $counter % 3); + self::assertEquals(1, $counter % 3); + return false; } - )) + ) ; - $two->expects($this->any()) - ->method('supports') + $two->method('supports') ->with($input) - ->will($this->returnCallback( - function() use (&$counter, $that) { + ->willReturnCallback( + static function () use (&$counter) { $counter++; - $that->assertEquals(2, $counter % 3); + self::assertEquals(2, $counter % 3); + return false; } - )) + ) ; - $three->expects($this->any()) - ->method('supports') + $three->method('supports') ->with($input) - ->will($this->returnCallback( - function() use (&$counter, $that, $result) { + ->willReturnCallback( + static function () use (&$counter) { $counter++; - $that->assertEquals(0, $counter % 3); + self::assertEquals(0, $counter % 3); + return true; } - )) + ) ; - $three->expects($this->once()) + $three->expects(self::once()) ->method('getName') ->with($input) - ->will($this->returnCallback( - function() use (&$nameCounter, $that, &$name) { + ->willReturnCallback( + static function () use (&$nameCounter, &$name) { $nameCounter++; - $that->assertEquals(1, $nameCounter); + self::assertEquals(1, $nameCounter); + return $name; } - )) + ) ; - $three->expects($this->once()) + $three->expects(self::once()) ->method('getContent') ->with($input) - ->will($this->returnCallback( - function() use (&$contentCounter, $that, &$result) { + ->willReturnCallback( + static function () use (&$contentCounter, &$result) { $contentCounter++; - $that->assertEquals(1, $contentCounter); + self::assertEquals(1, $contentCounter); + return $result; } - )) + ) ; // Fourth handler should never be reached, since third supports input. - $four->expects($this->never())->method($this->anything()); + $four->expects(self::never())->method(self::anything()); $handler = new ChainHandler([$one, $two, $three, $four]); - $this->assertTrue($handler->supports($input)); - $this->assertEquals($name, $handler->getName($input)); - $this->assertEquals($result, $handler->getContent($input)); + self::assertTrue($handler->supports($input)); + self::assertEquals($name, $handler->getName($input)); + self::assertEquals($result, $handler->getContent($input)); } + /** + * @return FileHandlerInterface&MockObject + */ protected function getHandlerMock(): FileHandlerInterface { return $this->createMock(FileHandlerInterface::class); diff --git a/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileHandler/GaufretteHandlerTest.php b/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileHandler/GaufretteHandlerTest.php index 90ba973..465626f 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileHandler/GaufretteHandlerTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileHandler/GaufretteHandlerTest.php @@ -19,7 +19,7 @@ class GaufretteHandlerTest extends BaseHandlerTest { - protected function setUp() + protected function setUp(): void { $this->handler = new GaufretteHandler(); } @@ -27,30 +27,30 @@ protected function setUp() /** * @dataProvider goodInputs */ - public function testSupports($input) + public function testSupports($input): void { - $this->assertTrue($this->handler->supports($input)); + self::assertTrue($this->handler->supports($input)); } /** * @dataProvider goodInputs */ - public function testGetContent($input) + public function testGetContent($input): void { $content = $this->handler->getContent($input); - $this->assertEquals(self::CONTENT, $content); + self::assertEquals(self::CONTENT, $content); } /** * @dataProvider goodInputs */ - public function testGetName($input) + public function testGetName($input): void { $name = $this->handler->getName($input); - $this->assertEquals($input->getName(), $name); + self::assertEquals($input->getName(), $name); } - public static function goodInputs() + public static function goodInputs(): array { $filesystem1 = new Filesystem(new Local(FILESYSTEM1)); diff --git a/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileHandler/SplFileInfoHandlerTest.php b/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileHandler/SplFileInfoHandlerTest.php index 47a28f5..118db4b 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileHandler/SplFileInfoHandlerTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileHandler/SplFileInfoHandlerTest.php @@ -23,69 +23,69 @@ class SplFileInfoHandlerTest extends BaseHandlerTest public const KEY = '/someKey'; public const TEMP_FILENAME = 'tempfile'; - protected function setUp() + protected function setUp(): void { $this->handler = new SplFileInfoHandler(self::TEMP_FILENAME); } - public function testSupports() + public function testSupports(): void { - $this->assertTrue($this->handler->supports($this->getInput())); + self::assertTrue($this->handler->supports($this->getInput())); } - public function testGetContent() + public function testGetContent(): void { $input = $this->getInput(); $content = $this->handler->getContent($input); - $this->assertEquals(self::CONTENT, $content); + self::assertEquals(self::CONTENT, $content); } - public function testGetContentOnEmptyFile() + public function testGetContentOnEmptyFile(): void { $emptyFile = new SplTempFileObject(); $content = $this->handler->getContent($emptyFile); - $this->assertEquals('', $content); + self::assertEquals('', $content); } - public function testGetContentOnTempFile() + public function testGetContentOnTempFile(): void { $input = new SplTempFileObject(); $input->fwrite(self::CONTENT); $position = $input->ftell(); $content = $this->handler->getContent($input); - $this->assertEquals(self::CONTENT, $content); - $this->assertEquals($position, $input->ftell()); + self::assertEquals(self::CONTENT, $content); + self::assertEquals($position, $input->ftell()); } - public function testGetContentOnOpenFile() + public function testGetContentOnOpenFile(): void { $input = $this->getInput()->openFile(); $content = $this->handler->getContent($input); - $this->assertEquals(self::CONTENT, $content); + self::assertEquals(self::CONTENT, $content); } - public function testGetName() + public function testGetName(): void { $input = $this->getInput(); $name = $this->handler->getName($input); - $this->assertEquals(basename(FILESYSTEM1 . self::KEY), $name); + self::assertEquals(basename(FILESYSTEM1 . self::KEY), $name); } - public function testGetNameOnTempFile() + public function testGetNameOnTempFile(): void { $input = new SplTempFileObject(); $input->fwrite(self::CONTENT); $name = $this->handler->getName($input); - $this->assertEquals(self::TEMP_FILENAME, $name); + self::assertEquals(self::TEMP_FILENAME, $name); } - public function testException() + public function testException(): void { $filesystem = new Filesystem(new Local(FILESYSTEM1)); $input = new SplFileInfo(FILESYSTEM1 . self::KEY); @@ -95,11 +95,12 @@ public function testException() $this->handler->getContent($input, $key, $filesystem); } - protected function getInput() + protected function getInput(): SplFileInfo { $input = new SplFileInfo(FILESYSTEM1 . self::KEY); $fileObj = $input->openFile('a'); $fileObj->fwrite(self::CONTENT); + return $input; } } diff --git a/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileTest.php b/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileTest.php index 035feb9..74a6824 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Uploadable/FileTest.php @@ -14,25 +14,29 @@ use FSi\DoctrineExtensions\Uploadable\File; use Gaufrette\File as GaufretteFile; use Gaufrette\Filesystem; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class FileTest extends TestCase { - public function testIsInstanceOfGaufretteFile() + public function testIsInstanceOfGaufretteFile(): void { $file = new File('key', $this->getFilesystemMock()); - $this->assertTrue($file instanceof GaufretteFile); + self::assertInstanceOf(GaufretteFile::class, $file); } - public function testFileIsAbleToReturnItsFilesystem() + public function testFileIsAbleToReturnItsFilesystem(): void { $filesystem = $this->getFilesystemMock(); $file = new File('key', $filesystem); - $this->assertSame($filesystem, $file->getFilesystem()); + self::assertSame($filesystem, $file->getFilesystem()); } - protected function getFilesystemMock() + /** + * @return Filesystem&MockObject + */ + protected function getFilesystemMock(): Filesystem { return $this->getMockBuilder(Filesystem::class)->disableOriginalConstructor()->getMock(); } diff --git a/tests/FSi/DoctrineExtensions/Tests/Uploadable/GeneralAnnotationTest.php b/tests/FSi/DoctrineExtensions/Tests/Uploadable/GeneralAnnotationTest.php index 0f87b54..d9df0d0 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Uploadable/GeneralAnnotationTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Uploadable/GeneralAnnotationTest.php @@ -29,7 +29,7 @@ class GeneralAnnotationTest extends GeneralTest /** * @dataProvider wrongAnnotations() */ - public function testWrongAnnotations(string $class) + public function testWrongAnnotations(string $class): void { $this->expectException(MappingException::class); $this->uploadableListener->getExtendedMetadata($this->entityManager, $class); @@ -38,13 +38,13 @@ public function testWrongAnnotations(string $class) /** * @dataProvider wrongTypes() */ - public function testWrongTypes(string $class) + public function testWrongTypes(string $class): void { $this->expectException(TypeError::class); $this->uploadableListener->getExtendedMetadata($this->entityManager, $class); } - public function wrongAnnotations() + public function wrongAnnotations(): array { return [ [User2::class], @@ -55,14 +55,13 @@ public function wrongAnnotations() ]; } - public function wrongTypes() + public function wrongTypes(): array { return [ [User1::class], [User8::class], [User9::class], [User10::class], - [User11::class], ]; } @@ -71,7 +70,7 @@ protected function getUser(): User return new User(); } - protected function getUsedEntityFixtures() + protected function getUsedEntityFixtures(): array { return [User::class]; } diff --git a/tests/FSi/DoctrineExtensions/Tests/Uploadable/GeneralTest.php b/tests/FSi/DoctrineExtensions/Tests/Uploadable/GeneralTest.php index 0f5a049..2886475 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Uploadable/GeneralTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Uploadable/GeneralTest.php @@ -11,6 +11,7 @@ namespace FSi\DoctrineExtensions\Tests\Uploadable; +use FSi\DoctrineExtensions\Tests\Uploadable\Fixture\User; use FSi\DoctrineExtensions\Uploadable\Exception\RuntimeException; use FSi\DoctrineExtensions\Tests\Tool\BaseORMTest; use FSi\DoctrineExtensions\Uploadable\File; @@ -26,9 +27,9 @@ abstract class GeneralTest extends BaseORMTest /** * Return instance of entity to use in test. */ - abstract protected function getUser(); + abstract protected function getUser(): User; - public function testInsertSplFileInfo() + public function testInsertSplFileInfo(): void { $user = $this->getUser(); $file = new SplFileInfo(TESTS_PATH . self::TEST_FILE1); @@ -40,13 +41,13 @@ public function testInsertSplFileInfo() $this->entityManager->refresh($user); $path = FILESYSTEM1 . $user->getFileKey(); - $this->assertNotEquals($path, FILESYSTEM1); - $this->assertTrue(file_exists($path)); - $this->assertTrue($user->getFile() instanceof File); - $this->assertEquals(basename($user->getFile()->getKey()), $originalFilename); + self::assertNotEquals($path, FILESYSTEM1); + self::assertFileExists($path); + self::assertInstanceOf(File::class, $user->getFile()); + self::assertEquals(basename($user->getFile()->getKey()), $originalFilename); } - public function testInsertFileWithNumericSuffix() + public function testInsertFileWithNumericSuffix(): void { $user = $this->getUser(); $file = new SplFileInfo(TESTS_PATH . self::TEST_FILE3); @@ -58,13 +59,13 @@ public function testInsertFileWithNumericSuffix() $this->entityManager->refresh($user); $path = FILESYSTEM1 . $user->getFileKey(); - $this->assertNotEquals($path, FILESYSTEM1); - $this->assertTrue(file_exists($path)); - $this->assertTrue($user->getFile() instanceof File); - $this->assertEquals(basename($user->getFile()->getKey()), $originalFilename); + self::assertNotEquals($path, FILESYSTEM1); + self::assertFileExists($path); + self::assertInstanceOf(File::class, $user->getFile()); + self::assertEquals(basename($user->getFile()->getKey()), $originalFilename); } - public function testInsertFileWithDuplicatedNumericSuffix() + public function testInsertFileWithDuplicatedNumericSuffix(): void { $user = $this->getUser(); $file = new SplFileInfo(TESTS_PATH . self::TEST_FILE3); @@ -79,12 +80,12 @@ public function testInsertFileWithDuplicatedNumericSuffix() $this->entityManager->flush(); $this->entityManager->refresh($user); - $this->assertTrue($user->getFile() instanceof File); - $this->assertNotNull($user->getFileKey()); - $this->assertEquals(basename($user->getFile()->getKey()), 'lh_2.jpg'); + self::assertInstanceOf(File::class, $user->getFile()); + self::assertNotNull($user->getFileKey()); + self::assertEquals(basename($user->getFile()->getKey()), 'lh_2.jpg'); } - public function testInsertFile() + public function testInsertFile(): void { $key = 'some/key'; @@ -97,12 +98,12 @@ public function testInsertFile() $this->entityManager->flush(); $this->entityManager->refresh($user); - $this->assertTrue($user->getFile() instanceof File); - $this->assertNotNull($user->getFileKey()); - $this->assertNotSame($file, $user->getFile()); + self::assertInstanceOf(File::class, $user->getFile()); + self::assertNotNull($user->getFileKey()); + self::assertNotSame($file, $user->getFile()); } - public function testUpdate() + public function testUpdate(): void { $user = $this->getUser(); $file1 = new SplFileInfo(TESTS_PATH . self::TEST_FILE1); @@ -113,22 +114,22 @@ public function testUpdate() $this->entityManager->flush(); $key1 = $user->getFileKey(); - $this->assertTrue(file_exists(FILESYSTEM1 . $key1)); + self::assertFileExists(FILESYSTEM1 . $key1); $user->setFile($file2); $this->entityManager->flush(); $this->entityManager->refresh($user); // Old file must be deleted. - $this->assertFalse(file_exists(FILESYSTEM1 . $key1)); + self::assertFileNotExists(FILESYSTEM1 . $key1); $key2 = $user->getFileKey(); - $this->assertTrue($user->getFile() instanceof File); - $this->assertNotNull($user->getFileKey()); - $this->assertTrue(file_exists(FILESYSTEM1 . $key2)); + self::assertInstanceOf(File::class, $user->getFile()); + self::assertNotNull($user->getFileKey()); + self::assertFileExists(FILESYSTEM1 . $key2); } - public function testDelete() + public function testDelete(): void { $user = $this->getUser(); $file1 = new SplFileInfo(TESTS_PATH . self::TEST_FILE1); @@ -138,20 +139,20 @@ public function testDelete() $this->entityManager->flush(); $key1 = $user->getFileKey(); - $this->assertTrue(file_exists(FILESYSTEM1 . $key1)); + self::assertFileExists(FILESYSTEM1 . $key1); $user->deleteFile(); $this->entityManager->flush(); $this->entityManager->refresh($user); // Old file must be deleted. - $this->assertFalse(file_exists(FILESYSTEM1 . $key1)); + self::assertFileNotExists(FILESYSTEM1 . $key1); // Entity fields also need to be cleared - $this->assertNull($user->getFile()); - $this->assertNull($user->getFileKey()); + self::assertNull($user->getFile()); + self::assertNull($user->getFileKey()); } - public function testDeleteWithFailure() + public function testDeleteWithFailure(): void { $user = $this->getUser(); $file1 = new SplFileInfo(TESTS_PATH . self::TEST_FILE1); @@ -161,7 +162,7 @@ public function testDeleteWithFailure() $this->entityManager->flush(); $key1 = $user->getFileKey(); - $this->assertTrue(file_exists(FILESYSTEM1 . $key1)); + self::assertTrue(file_exists(FILESYSTEM1 . $key1)); $user->deleteFile(); @@ -174,12 +175,12 @@ public function testDeleteWithFailure() $exceptionThrown = true; } - $this->assertTrue($exceptionThrown); - $this->assertTrue(file_exists(FILESYSTEM1 . $key1)); + self::assertTrue($exceptionThrown); + self::assertFileExists(FILESYSTEM1 . $key1); // Entity fields should be empty, but the file should still exist. // The fields will be rehydrated post-load - $this->assertNull($user->getFile()); - $this->assertNull($user->getFileKey()); + self::assertNull($user->getFile()); + self::assertNull($user->getFileKey()); } public function testUpdateWithFailure() @@ -193,7 +194,7 @@ public function testUpdateWithFailure() $this->entityManager->flush(); $key1 = $user->getFileKey(); - $this->assertTrue(file_exists(FILESYSTEM1 . $key1)); + self::assertFileExists(FILESYSTEM1 . $key1); $user->setFile($file2); @@ -203,12 +204,12 @@ public function testUpdateWithFailure() $this->entityManager->flush(); // Old file must be preserved. - $this->assertTrue(file_exists(FILESYSTEM1 . $key1)); - $this->assertTrue($user->getFile() instanceof File); - $this->assertNotNull($user->getFileKey()); + self::assertFileExists(FILESYSTEM1 . $key1); + self::assertInstanceOf(File::class, $user->getFile()); + self::assertNotNull($user->getFileKey()); } - public function testDeleteEntity() + public function testDeleteEntity(): void { $user = $this->getUser(); $file1 = new SplFileInfo(TESTS_PATH . self::TEST_FILE1); @@ -218,15 +219,15 @@ public function testDeleteEntity() $this->entityManager->flush(); $key1 = $user->getFileKey(); - $this->assertTrue(file_exists(FILESYSTEM1 . $key1)); + self::assertFileExists(FILESYSTEM1 . $key1); $this->entityManager->remove($user); $this->entityManager->flush(); - $this->assertFalse(file_exists(FILESYSTEM1 . $key1)); + self::assertFileNotExists(FILESYSTEM1 . $key1); } - public function testUpdateWithSameBaseName() + public function testUpdateWithSameBaseName(): void { $content = 'some content'; @@ -238,7 +239,7 @@ public function testUpdateWithSameBaseName() $this->entityManager->flush(); $key1 = $user->getFileKey(); - $this->assertTrue(file_exists(FILESYSTEM1 . $key1)); + self::assertFileExists(FILESYSTEM1 . $key1); $user->getFile()->setContent($content); $user->setFile($file1); @@ -247,13 +248,13 @@ public function testUpdateWithSameBaseName() $this->entityManager->refresh($user); $key2 = $user->getFileKey(); - $this->assertTrue(file_exists(FILESYSTEM1 . $key2)); - $this->assertTrue($user->getFile() instanceof File); - $this->assertNotNull($user->getFileKey()); - $this->assertNotEquals($content, $user->getFile()->getContent()); + self::assertFileExists(FILESYSTEM1 . $key2); + self::assertInstanceOf(File::class, $user->getFile()); + self::assertNotNull($user->getFileKey()); + self::assertNotEquals($content, $user->getFile()->getContent()); } - public function testUpdateWithTheSameBaseNameWithFailure() + public function testUpdateWithTheSameBaseNameWithFailure(): void { $content = 'some content'; @@ -265,7 +266,7 @@ public function testUpdateWithTheSameBaseNameWithFailure() $this->entityManager->flush(); $oldFile = $user->getFile(); - $this->assertTrue($oldFile->exists()); + self::assertTrue($oldFile->exists()); $oldFile->setContent($content); $exceptionThrown = false; @@ -278,16 +279,16 @@ public function testUpdateWithTheSameBaseNameWithFailure() $exceptionThrown = true; } - $this->assertTrue($exceptionThrown); + self::assertTrue($exceptionThrown); // Old file must be preserved. - $this->assertTrue($oldFile->exists()); - $this->assertTrue($user->getFile() instanceof File); - $this->assertNotNull($user->getFileKey()); - $this->assertNotEquals($content, $user->getFile()->getContent()); + self::assertTrue($oldFile->exists()); + self::assertInstanceOf(File::class, $user->getFile()); + self::assertNotNull($user->getFileKey()); + self::assertNotEquals($content, $user->getFile()->getContent()); } - public function testExceptionWhenKeyIsToLong() + public function testExceptionWhenKeyIsToLong(): void { $key = 'some/key' . str_repeat('aaaaa', 50); @@ -301,16 +302,16 @@ public function testExceptionWhenKeyIsToLong() $this->entityManager->flush(); } - public function testFileHandlerReturnBasename() + public function testFileHandlerReturnBasename(): void { $key = 'some/key/blabla'; $file = new File($key, $this->filesystem1); $file->setContent(''); - $this->assertEquals('blabla', $this->uploadableListener->getFileHandler()->getName($file)); + self::assertEquals('blabla', $this->uploadableListener->getFileHandler()->getName($file)); $file = new SplFileInfo(TESTS_PATH . self::TEST_FILE1); - $this->assertEquals('penguins.jpg', $this->uploadableListener->getFileHandler()->getName($file)); + self::assertEquals('penguins.jpg', $this->uploadableListener->getFileHandler()->getName($file)); } public function testLoadingFiles() @@ -327,13 +328,13 @@ public function testLoadingFiles() $user = array_shift($all); $path = FILESYSTEM1 . $user->getFileKey(); - $this->assertNotEquals($path, FILESYSTEM1); - $this->assertTrue(file_exists($path)); - $this->assertTrue($user->getFile() instanceof File); - $this->assertNotNull($user->getFileKey()); + self::assertNotEquals($path, FILESYSTEM1); + self::assertFileExists($path); + self::assertInstanceOf(File::class, $user->getFile()); + self::assertNotNull($user->getFileKey()); } - protected function tearDown() + protected function tearDown(): void { Utils::deleteRecursive(FILESYSTEM1); Utils::deleteRecursive(FILESYSTEM2); diff --git a/tests/FSi/DoctrineExtensions/Tests/Uploadable/GeneralXmlTest.php b/tests/FSi/DoctrineExtensions/Tests/Uploadable/GeneralXmlTest.php index 366c0ee..2c6d090 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Uploadable/GeneralXmlTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Uploadable/GeneralXmlTest.php @@ -11,8 +11,8 @@ namespace FSi\DoctrineExtensions\Tests\Uploadable; -use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; use Doctrine\ORM\Mapping\Driver\XmlDriver; +use Doctrine\Persistence\Mapping\Driver\MappingDriver; use FSi\DoctrineExtensions\Tests\Uploadable\Fixture\Common\User1; use FSi\DoctrineExtensions\Tests\Uploadable\Fixture\Common\User2; use FSi\DoctrineExtensions\Tests\Uploadable\Fixture\Common\User3; @@ -29,7 +29,7 @@ class GeneralXmlTest extends GeneralTest /** * @dataProvider wrongMappings */ - public function testWrongMapping($class) + public function testWrongMapping($class): void { $this->expectException(MappingException::class); $this->uploadableListener->getExtendedMetadata($this->entityManager, $class); @@ -38,13 +38,13 @@ public function testWrongMapping($class) /** * @dataProvider wrongTypes() */ - public function testWrongTypes(string $class) + public function testWrongTypes(string $class): void { $this->expectException(TypeError::class); $this->uploadableListener->getExtendedMetadata($this->entityManager, $class); } - public function wrongMappings() + public function wrongMappings(): array { return [ [User1::class], @@ -55,14 +55,14 @@ public function wrongMappings() ]; } - public function wrongTypes() + public function wrongTypes(): array { return [ [User6::class], ]; } - public function testMappingWithOtherNamespaces() + public function testMappingWithOtherNamespaces(): void { $this->uploadableListener->getExtendedMetadata($this->entityManager, Car::class); } @@ -72,20 +72,12 @@ protected function getMetadataDriverImplementation(): MappingDriver return new XmlDriver(__DIR__.'/Fixture/Xml/config'); } - /** - * {@inheritdoc} - * - * @return User - */ - protected function getUser() + protected function getUser(): User { return new User(); } - /** - * {@inheritdoc} - */ - protected function getUsedEntityFixtures() + protected function getUsedEntityFixtures(): array { return [User::class]; } diff --git a/tests/FSi/DoctrineExtensions/Tests/Uploadable/GeneralYamlTest.php b/tests/FSi/DoctrineExtensions/Tests/Uploadable/GeneralYamlTest.php index d8987d2..0c135a7 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Uploadable/GeneralYamlTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Uploadable/GeneralYamlTest.php @@ -11,8 +11,8 @@ namespace FSi\DoctrineExtensions\Tests\Uploadable; -use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; +use Doctrine\Persistence\Mapping\Driver\MappingDriver; use FSi\DoctrineExtensions\Tests\Uploadable\Fixture\Common\User1; use FSi\DoctrineExtensions\Tests\Uploadable\Fixture\Common\User2; use FSi\DoctrineExtensions\Tests\Uploadable\Fixture\Common\User3; @@ -28,7 +28,7 @@ class GeneralYamlTest extends GeneralTest /** * @dataProvider wrongMappings */ - public function testWrongMapping($class) + public function testWrongMapping($class): void { $this->expectException(MappingException::class); $this->uploadableListener->getExtendedMetadata($this->entityManager, $class); @@ -37,13 +37,13 @@ public function testWrongMapping($class) /** * @dataProvider wrongTypes() */ - public function testWrongTypes(string $class) + public function testWrongTypes(string $class): void { $this->expectException(TypeError::class); $this->uploadableListener->getExtendedMetadata($this->entityManager, $class); } - public function wrongMappings() + public function wrongMappings(): array { return [ [User1::class], @@ -53,32 +53,25 @@ public function wrongMappings() ]; } - public function wrongTypes() + public function wrongTypes(): array { return [ [User2::class], [User3::class], - [User5::class] ]; } - /** - * {@inheritdoc} - */ protected function getMetadataDriverImplementation(): MappingDriver { return new YamlDriver(__DIR__.'/Fixture/Yaml/config'); } - /** - * @return User - */ - protected function getUser() + protected function getUser(): User { return new User(); } - protected function getUsedEntityFixtures() + protected function getUsedEntityFixtures(): array { return [User::class]; } diff --git a/tests/FSi/DoctrineExtensions/Tests/Uploadable/InheritanceTest.php b/tests/FSi/DoctrineExtensions/Tests/Uploadable/InheritanceTest.php index 01f5e8f..b49bc3b 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Uploadable/InheritanceTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Uploadable/InheritanceTest.php @@ -79,13 +79,13 @@ public function testUploadablePropertyInSingleTableInInheritance() $this->assertNotNull($employee->getFile()); } - protected function tearDown() + protected function tearDown(): void { Utils::deleteRecursive(FILESYSTEM1); Utils::deleteRecursive(FILESYSTEM2); } - protected function getUsedEntityFixtures() + protected function getUsedEntityFixtures(): array { return [ CustomContentPage::class, diff --git a/tests/FSi/DoctrineExtensions/Tests/Uploadable/KeymakerTest.php b/tests/FSi/DoctrineExtensions/Tests/Uploadable/KeymakerTest.php index c101819..532e0db 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Uploadable/KeymakerTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Uploadable/KeymakerTest.php @@ -15,6 +15,7 @@ use FSi\DoctrineExtensions\Uploadable\Keymaker\Entity; use FSi\DoctrineExtensions\Uploadable\Keymaker\KeymakerInterface; use PHPUnit\Framework\TestCase; +use function implode; class KeymakerTest extends TestCase { @@ -22,37 +23,49 @@ class KeymakerTest extends TestCase public const ID = 1; public const ORIGINAL_NAME = 'originalName.txt'; - public function testCreation() + public function testCreation(): void { $keyMaker = new Entity(); - $this->assertTrue($keyMaker instanceof KeymakerInterface); + self::assertInstanceOf(KeymakerInterface::class, $keyMaker); } /** * @dataProvider inputs */ - public function testKeyGeneration($pattern, $expected) + public function testKeyGeneration(?string $pattern, string $expected): void { $keyMaker = new Entity(); $user = new User(); - $this->assertEquals( + self::assertEquals( $expected, $keyMaker->createKey($user, self::PROPERTY, self::ID, self::ORIGINAL_NAME, $pattern) ); } - /** - * @return array - */ - public static function inputs() + public static function inputs(): array { return [ - [null, '/FSiDoctrineExtensionsTestsUploadableFixtureUser/' . self::PROPERTY . '/' . self::ID . '/' . self::ORIGINAL_NAME], + [ + null, + implode( + '/', + ['/FSiDoctrineExtensionsTestsUploadableFixtureUser', self::PROPERTY, self::ID, self::ORIGINAL_NAME] + ), + ], ['{fqcn}/{id}/constant', 'FSiDoctrineExtensionsTestsUploadableFixtureUser/' . self::ID . '/constant'], [ '{fqcn}/{property}/{wrong_tag}/{id}/{original_name}', - 'FSiDoctrineExtensionsTestsUploadableFixtureUser/' . self::PROPERTY . '/{wrong_tag}/' . self::ID . '/' . self::ORIGINAL_NAME + implode( + '/', + [ + 'FSiDoctrineExtensionsTestsUploadableFixtureUser', + self::PROPERTY, + '{wrong_tag}', + self::ID, + self::ORIGINAL_NAME, + ] + ) ], ]; } diff --git a/tests/FSi/DoctrineExtensions/Tests/Uploadable/TransliterateKeymakerTest.php b/tests/FSi/DoctrineExtensions/Tests/Uploadable/TransliterateKeymakerTest.php index 8b648a2..ad5895b 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Uploadable/TransliterateKeymakerTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Uploadable/TransliterateKeymakerTest.php @@ -30,16 +30,16 @@ class TransliterateKeymakerTest extends TestCase public const ORIGINAL_NAME_GER = 'örigiünälNÄÜméÖß.txt'; public const PARSED_NAME_GER = 'origiunalnaumeoss.txt'; - public function testCreation() + public function testCreation(): void { $keyMaker = new TransliterateEntity(); - $this->assertTrue($keyMaker instanceof KeymakerInterface); + self::assertInstanceOf(KeymakerInterface::class, $keyMaker); } /** * @dataProvider inputsSpecial */ - public function testSpecialSignKeyGeneration($pattern, $expected) + public function testSpecialSignKeyGeneration(?string $pattern, string $expected): void { $this->assertKeyGeneration($pattern, $expected, self::ORIGINAL_NAME_SPECIAL); } @@ -47,7 +47,7 @@ public function testSpecialSignKeyGeneration($pattern, $expected) /** * @dataProvider inputsPolish */ - public function testPolishKeyGeneration($pattern, $expected) + public function testPolishKeyGeneration(?string $pattern, string $expected): void { $this->assertKeyGeneration($pattern, $expected, self::ORIGINAL_NAME_PL); } @@ -55,41 +55,32 @@ public function testPolishKeyGeneration($pattern, $expected) /** * @dataProvider inputsGerman */ - public function testGermanKeyGeneration($pattern, $expected) + public function testGermanKeyGeneration(?string $pattern, string $expected): void { $this->assertKeyGeneration($pattern, $expected, self::ORIGINAL_NAME_GER); } - /** - * @return array - */ - public static function inputsSpecial() + public static function inputsSpecial(): array { return self::getInputs(self::PARSED_NAME_SPECIAL); } - /** - * @return array - */ - public static function inputsPolish() + public static function inputsPolish(): array { return self::getInputs(self::PARSED_NAME_PL); } - /** - * @return array - */ - public static function inputsGerman() + public static function inputsGerman(): array { return self::getInputs(self::PARSED_NAME_GER); } - private function assertKeyGeneration($pattern, $expected, $original) + private function assertKeyGeneration(?string $pattern, string $expected, string $original): void { $keyMaker = new TransliterateEntity(); $user = new User(); - $this->assertEquals( + self::assertEquals( $expected, $keyMaker->createKey( $user, @@ -101,27 +92,20 @@ private function assertKeyGeneration($pattern, $expected, $original) ); } - /** - * @param string $name - * @return array - */ - public static function getInputs($name) + public static function getInputs(string $name): array { $testSets = [ [ '{fqcn}/{id}/constant', - 'FSiDoctrineExtensionsTestsUploadableFixtureUser/' . self::ID - . '/constant' + 'FSiDoctrineExtensionsTestsUploadableFixtureUser/' . self::ID . '/constant' ], [ null, - '/FSiDoctrineExtensionsTestsUploadableFixtureUser/' - . self::PROPERTY . '/' . self::ID . '/%s' + '/FSiDoctrineExtensionsTestsUploadableFixtureUser/' . self::PROPERTY . '/' . self::ID . '/%s' ], [ '{fqcn}/{property}/{wrong_tag}/{id}/{original_name}', - 'FSiDoctrineExtensionsTestsUploadableFixtureUser/' - . self::PROPERTY . '/{wrong_tag}/' . self::ID . '/%s' + 'FSiDoctrineExtensionsTestsUploadableFixtureUser/' . self::PROPERTY . '/{wrong_tag}/' . self::ID . '/%s' ] ]; $inputs = []; diff --git a/tests/FSi/DoctrineExtensions/Tests/Uploadable/UploadableTest.php b/tests/FSi/DoctrineExtensions/Tests/Uploadable/UploadableTest.php index 1d8aab3..a6352a8 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Uploadable/UploadableTest.php +++ b/tests/FSi/DoctrineExtensions/Tests/Uploadable/UploadableTest.php @@ -12,6 +12,7 @@ namespace FSi\DoctrineExtensions\Tests\Uploadable; use FSi\DoctrineExtensions\Mapping\MappedEventSubscriber; +use FSi\DoctrineExtensions\Tests\Uploadable\Fixture\User; use FSi\DoctrineExtensions\Uploadable\Exception\RuntimeException; use FSi\DoctrineExtensions\Uploadable\FileHandler\FileHandlerInterface; use FSi\DoctrineExtensions\Uploadable\Keymaker\KeymakerInterface; @@ -25,66 +26,66 @@ final class UploadableTest extends TestCase public const TEST_FILE1 = '/FSi/DoctrineExtensions/Tests/Uploadable/Fixture/penguins.jpg'; public const TEST_FILE2 = '/FSi/DoctrineExtensions/Tests/Uploadable/Fixture/lighthouse.jpg'; - public function testIsInitializableWithoutFilesystems1() + public function testIsInitializableWithoutFilesystems1(): void { $listener = new UploadableListener([], $this->getFileHandlerMock()); - $this->assertInstanceof(UploadableListener::class, $listener); + self::assertInstanceof(UploadableListener::class, $listener); } - public function testIsNotInitializableWithoutFilesystems4() + public function testIsNotInitializableWithoutFilesystems4(): void { $this->expectException(RuntimeException::class); $listener = new UploadableListener('definitely not an array', $this->getFileHandlerMock()); - $this->assertInstanceof(UploadableListener::class, $listener); + self::assertInstanceof(UploadableListener::class, $listener); } - public function testIsInitializableWithFilesystems() + public function testIsInitializableWithFilesystems(): void { $listener = new UploadableListener(['one' => $this->getFilesystemMock()], $this->getFileHandlerMock()); - $this->assertInstanceof(UploadableListener::class, $listener); + self::assertInstanceof(UploadableListener::class, $listener); } - public function testAllowsGetFilesystems() + public function testAllowsGetFilesystems(): void { $listener = new UploadableListener( ['one' => $this->getFilesystemMock()], $this->getFileHandlerMock() ); - $this->assertCount(1, $listener->getFilesystems()); + self::assertCount(1, $listener->getFilesystems()); } - public function testIsInitializableWithFilesystemMap() + public function testIsInitializableWithFilesystemMap(): void { $map = new FilesystemMap(); - $map->set('one', $this->getFilesystemMock(), $this->getFileHandlerMock()); + $map->set('one', $this->getFilesystemMock()); $listener = new UploadableListener($map, $this->getFileHandlerMock()); - $this->assertSame($map->all(), $listener->getFilesystems()); + self::assertSame($map->all(), $listener->getFilesystems()); } - public function testIsInitializableWithEmptyFilesystemMap() + public function testIsInitializableWithEmptyFilesystemMap(): void { $map = new FilesystemMap(); $listener = new UploadableListener($map, $this->getFileHandlerMock()); - $this->assertCount(0, $listener->getFilesystems()); + self::assertCount(0, $listener->getFilesystems()); } - public function testIsInstanceOfMappedSubscriber() + public function testIsInstanceOfMappedSubscriber(): void { $listener = new UploadableListener( ['one' => $this->getFilesystemMock()], $this->getFileHandlerMock() ); - $this->assertTrue($listener instanceof MappedEventSubscriber); + self::assertInstanceOf(MappedEventSubscriber::class, $listener); } - public function testAllowsToCheckAndGetFilesystem() + public function testAllowsToCheckAndGetFilesystem(): void { $filesystems = ['one' => $this->getFilesystemMock(), 'two' => $this->getFilesystemMock(),]; $listener = new UploadableListener($filesystems, $this->getFileHandlerMock()); - $this->assertTrue($listener->hasFilesystem('one')); - $this->assertTrue($listener->hasFilesystem('two')); - $this->assertFalse($listener->hasFilesystem('three')); + self::assertTrue($listener->hasFilesystem('one')); + self::assertTrue($listener->hasFilesystem('two')); + self::assertFalse($listener->hasFilesystem('three')); $listener->getFilesystem('one'); $listener->getFilesystem('two'); @@ -92,7 +93,7 @@ public function testAllowsToCheckAndGetFilesystem() $listener->getFilesystem('three'); } - public function testSetZeroKeyLength() + public function testSetZeroKeyLength(): void { $filesystems = ['one' => $this->getFilesystemMock()]; $this->expectException(RuntimeException::class); @@ -100,7 +101,7 @@ public function testSetZeroKeyLength() $listener->setDefaultKeyLength(0); } - public function testSetNegativeKeyLength() + public function testSetNegativeKeyLength(): void { $filesystems = ['one' => $this->getFilesystemMock()]; $this->expectException(RuntimeException::class); @@ -108,42 +109,42 @@ public function testSetNegativeKeyLength() $listener->setDefaultKeyLength(-1); } - public function testGetDefaultKeymakerWhenNotSet() + public function testGetDefaultKeymakerWhenNotSet(): void { $filesystems = ['one' => $this->getFilesystemMock()]; $listener = new UploadableListener($filesystems, $this->getFileHandlerMock()); - $this->assertFalse($listener->hasDefaultKeymaker()); + self::assertFalse($listener->hasDefaultKeymaker()); $this->expectException(RuntimeException::class); $listener->getDefaultKeymaker(); } - public function testSetDefaultKeymaker() + public function testSetDefaultKeymaker(): void { $keymaker = $this->getKeymakerMock(); $filesystems = ['one' => $this->getFilesystemMock()]; $listener = new UploadableListener($filesystems, $this->getFileHandlerMock()); $listener->setDefaultKeymaker($keymaker); - $this->assertSame($keymaker, $listener->getDefaultKeymaker()); - $this->assertTrue($listener->hasDefaultKeymaker()); + self::assertSame($keymaker, $listener->getDefaultKeymaker()); + self::assertTrue($listener->hasDefaultKeymaker()); } - public function testSetFileHandlerInConstructor() + public function testSetFileHandlerInConstructor(): void { $fileHandler = $this->getFileHandlerMock(); $listener = new UploadableListener(['one' => $this->getFilesystemMock()], $fileHandler); - $this->assertSame($fileHandler, $listener->getFileHandler()); + self::assertSame($fileHandler, $listener->getFileHandler()); } - public function testSetFileHandler() + public function testSetFileHandler(): void { $fileHandler1 = $this->getFileHandlerMock(); $fileHandler2 = $this->getFileHandlerMock(); $listener = new UploadableListener(['one' => $this->getFilesystemMock()], $fileHandler1); $listener->setFileHandler($fileHandler2); - $this->assertSame($fileHandler2, $listener->getFileHandler()); + self::assertSame($fileHandler2, $listener->getFileHandler()); } - public function testSettingDefaultFilesystem() + public function testSettingDefaultFilesystem(): void { $f1 = $this->getFilesystemMock(); $f2 = $this->getFilesystemMock(); @@ -152,46 +153,46 @@ public function testSettingDefaultFilesystem() ['one' => $this->getFilesystemMock()], $this->getFileHandlerMock() ); - $this->assertFalse($listener->hasDefaultFilesystem()); + self::assertFalse($listener->hasDefaultFilesystem()); $listener->setDefaultFilesystem($f1); - $this->assertSame($f1, $listener->getDefaultFilesystem()); + self::assertSame($f1, $listener->getDefaultFilesystem()); $listener->setDefaultFilesystem($f2); - $this->assertSame($f2, $listener->getDefaultFilesystem()); + self::assertSame($f2, $listener->getDefaultFilesystem()); } - public function testGettingFilesystemWhenNotSet() + public function testGettingFilesystemWhenNotSet(): void { $listener = new UploadableListener( ['one' => $this->getFilesystemMock()], $this->getFileHandlerMock() ); - $this->assertFalse($listener->hasDefaultFilesystem()); + self::assertFalse($listener->hasDefaultFilesystem()); $this->expectException(RuntimeException::class); $listener->getDefaultFilesystem(); } - public function testSettingFilesystems() + public function testSettingFilesystems(): void { $filesystems = ['one' => $this->getFilesystemMock(), 'two' => $this->getFilesystemMock()]; $listener = new UploadableListener( ['three' => $this->getFilesystemMock()], $this->getFileHandlerMock() ); - $this->assertEquals(1, count($listener->getFilesystems())); + self::assertCount(1, $listener->getFilesystems()); $listener->setFilesystems($filesystems); - $this->assertEquals(2, count($listener->getFilesystems())); + self::assertCount(2, $listener->getFilesystems()); - $this->assertSame($filesystems, $listener->getFilesystems()); + self::assertSame($filesystems, $listener->getFilesystems()); - $this->assertTrue($listener->hasFilesystem('one')); - $this->assertTrue($listener->hasFilesystem('two')); - $this->assertFalse($listener->hasFilesystem('three')); + self::assertTrue($listener->hasFilesystem('one')); + self::assertTrue($listener->hasFilesystem('two')); + self::assertFalse($listener->hasFilesystem('three')); } - public function testSettingAndRemovingSingleFilesystem() + public function testSettingAndRemovingSingleFilesystem(): void { $f1 = $this->getFilesystemMock(); $f2 = $this->getFilesystemMock(); @@ -199,23 +200,23 @@ public function testSettingAndRemovingSingleFilesystem() $listener = new UploadableListener([], $this->getFileHandlerMock()); $listener->setFilesystem('one', $f1); - $this->assertTrue($listener->hasFilesystem('one')); - $this->assertSame($f1, $listener->getFilesystem('one')); + self::assertTrue($listener->hasFilesystem('one')); + self::assertSame($f1, $listener->getFilesystem('one')); $listener->setFilesystem('two', $f2); - $this->assertTrue($listener->hasFilesystem('two')); - $this->assertSame($f2, $listener->getFilesystem('two')); + self::assertTrue($listener->hasFilesystem('two')); + self::assertSame($f2, $listener->getFilesystem('two')); $listener->removeFilesystem('one'); - $this->assertFalse($listener->hasFilesystem('one')); + self::assertFalse($listener->hasFilesystem('one')); $listener->removeFilesystem('two'); - $this->assertFalse($listener->hasFilesystem('two')); + self::assertFalse($listener->hasFilesystem('two')); - $this->assertEquals(0, count($listener->getFilesystems())); + self::assertCount(0, $listener->getFilesystems()); } - protected function tearDown() + protected function tearDown(): void { Utils::deleteRecursive(FILESYSTEM1); Utils::deleteRecursive(FILESYSTEM2); @@ -236,7 +237,7 @@ private function getFileHandlerMock(): FileHandlerInterface return $this->createMock(FileHandlerInterface::class); } - protected function getUsedEntityFixtures() + protected function getUsedEntityFixtures(): array { return [User::class]; } diff --git a/tests/FSi/DoctrineExtensions/Tests/Uploadable/Utils.php b/tests/FSi/DoctrineExtensions/Tests/Uploadable/Utils.php index 61729a0..4dc10ad 100644 --- a/tests/FSi/DoctrineExtensions/Tests/Uploadable/Utils.php +++ b/tests/FSi/DoctrineExtensions/Tests/Uploadable/Utils.php @@ -15,7 +15,7 @@ class Utils { - public static function deleteRecursive(string $path) + public static function deleteRecursive(string $path): void { foreach (new DirectoryIterator($path) as $file) { if ($file->isDot()) { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9138419..a3396da 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,7 +2,7 @@ define('TESTS_PATH', __DIR__); define('TESTS_TEMP_DIR', __DIR__.'/temp'); -define('VENDOR_PATH', realpath(__DIR__ . '/../vendor')); +define('VENDOR_PATH', dirname(__DIR__) . '/vendor'); define('FILESYSTEM1', TESTS_TEMP_DIR . '/filesystem1'); define('FILESYSTEM2', TESTS_TEMP_DIR . '/filesystem2');