From 3c4ff43d6e1c63cda5aaa7a9a0c22f8db6957298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 19 Dec 2021 18:15:24 +0100 Subject: [PATCH 01/11] Add Pure annotations --- fixtures/Bridge/Eloquent/MigratorFactory.php | 2 ++ fixtures/Bridge/Symfony/Entity/Group.php | 2 ++ fixtures/Bridge/Symfony/Entity/User.php | 2 ++ fixtures/Bridge/Symfony/SymfonyApp/InvalidKernel.php | 2 ++ fixtures/Bridge/Symfony/SymfonyApp/NakedKernel.php | 2 ++ .../DependencyInjection/Compiler/RegisterTagServicesPass.php | 2 ++ src/Exception/MaxPassReachedException.php | 2 ++ src/Loader/FileResolverLoader.php | 2 ++ src/Loader/PersisterLoader.php | 2 ++ src/Loader/SimpleLoader.php | 2 ++ 10 files changed, 20 insertions(+) diff --git a/fixtures/Bridge/Eloquent/MigratorFactory.php b/fixtures/Bridge/Eloquent/MigratorFactory.php index 1adeaa67..9fa50046 100644 --- a/fixtures/Bridge/Eloquent/MigratorFactory.php +++ b/fixtures/Bridge/Eloquent/MigratorFactory.php @@ -16,9 +16,11 @@ use Fidry\AliceDataFixtures\Bridge\Eloquent\Migration\FakeMigrationRepository; use Illuminate\Database\Migrations\Migrator; use Illuminate\Filesystem\Filesystem; +use JetBrains\PhpStorm\Pure; class MigratorFactory { + #[Pure] public static function create(): Migrator { return new Migrator( diff --git a/fixtures/Bridge/Symfony/Entity/Group.php b/fixtures/Bridge/Symfony/Entity/Group.php index 2dede259..67cb9235 100644 --- a/fixtures/Bridge/Symfony/Entity/Group.php +++ b/fixtures/Bridge/Symfony/Entity/Group.php @@ -15,6 +15,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use JetBrains\PhpStorm\Pure; class Group { @@ -25,6 +26,7 @@ class Group */ private Collection $users; + #[Pure] public function __construct() { $this->users = new ArrayCollection(); diff --git a/fixtures/Bridge/Symfony/Entity/User.php b/fixtures/Bridge/Symfony/Entity/User.php index 14317730..3c4dac0f 100644 --- a/fixtures/Bridge/Symfony/Entity/User.php +++ b/fixtures/Bridge/Symfony/Entity/User.php @@ -15,6 +15,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use JetBrains\PhpStorm\Pure; class User { @@ -25,6 +26,7 @@ class User */ private Collection $groups; + #[Pure] public function __construct() { $this->groups = new ArrayCollection(); diff --git a/fixtures/Bridge/Symfony/SymfonyApp/InvalidKernel.php b/fixtures/Bridge/Symfony/SymfonyApp/InvalidKernel.php index fc17f4e1..e81808a5 100644 --- a/fixtures/Bridge/Symfony/SymfonyApp/InvalidKernel.php +++ b/fixtures/Bridge/Symfony/SymfonyApp/InvalidKernel.php @@ -14,10 +14,12 @@ namespace Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp; use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle; +use JetBrains\PhpStorm\Pure; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; class InvalidKernel extends IsolatedKernel { + #[Pure] public function registerBundles(): array { return [ diff --git a/fixtures/Bridge/Symfony/SymfonyApp/NakedKernel.php b/fixtures/Bridge/Symfony/SymfonyApp/NakedKernel.php index 9c36a5a1..dff9090f 100644 --- a/fixtures/Bridge/Symfony/SymfonyApp/NakedKernel.php +++ b/fixtures/Bridge/Symfony/SymfonyApp/NakedKernel.php @@ -14,11 +14,13 @@ namespace Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp; use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle; +use JetBrains\PhpStorm\Pure; use Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; class NakedKernel extends IsolatedKernel { + #[Pure] public function registerBundles(): array { return [ diff --git a/src/Bridge/Symfony/DependencyInjection/Compiler/RegisterTagServicesPass.php b/src/Bridge/Symfony/DependencyInjection/Compiler/RegisterTagServicesPass.php index b9bcb15a..35603e25 100644 --- a/src/Bridge/Symfony/DependencyInjection/Compiler/RegisterTagServicesPass.php +++ b/src/Bridge/Symfony/DependencyInjection/Compiler/RegisterTagServicesPass.php @@ -13,6 +13,7 @@ namespace Fidry\AliceDataFixtures\Bridge\Symfony\DependencyInjection\Compiler; +use JetBrains\PhpStorm\Pure; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -25,6 +26,7 @@ final class RegisterTagServicesPass implements CompilerPassInterface private string $tagName; private TaggedDefinitionsLocator $taggedDefinitionsLocator; + #[Pure] public function __construct(string $registry, string $tagName) { $this->registry = $registry; diff --git a/src/Exception/MaxPassReachedException.php b/src/Exception/MaxPassReachedException.php index 104bff83..be977de0 100644 --- a/src/Exception/MaxPassReachedException.php +++ b/src/Exception/MaxPassReachedException.php @@ -15,6 +15,7 @@ use Fidry\AliceDataFixtures\Loader\ErrorTracker; use Fidry\AliceDataFixtures\Loader\FileTracker; +use JetBrains\PhpStorm\Pure; use Nelmio\Alice\Throwable\LoadingThrowable; use RuntimeException; use Throwable; @@ -29,6 +30,7 @@ class MaxPassReachedException extends RuntimeException implements LoadingThrowab */ private array $stack = []; + #[Pure] public function __construct($message, $code = 0, Throwable $previous = null, ErrorTracker $errorTracker = null) { parent::__construct($message, $code, $previous); diff --git a/src/Loader/FileResolverLoader.php b/src/Loader/FileResolverLoader.php index 773f7cbf..93c39275 100644 --- a/src/Loader/FileResolverLoader.php +++ b/src/Loader/FileResolverLoader.php @@ -18,6 +18,7 @@ use Fidry\AliceDataFixtures\Persistence\PersisterAwareInterface; use Fidry\AliceDataFixtures\Persistence\PersisterInterface; use Fidry\AliceDataFixtures\Persistence\PurgeMode; +use JetBrains\PhpStorm\Pure; use Nelmio\Alice\IsAServiceTrait; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; @@ -35,6 +36,7 @@ private FileResolverInterface $fileResolver; private LoggerInterface $logger; + #[Pure] public function __construct( LoaderInterface $decoratedLoader, FileResolverInterface $fileResolver, diff --git a/src/Loader/PersisterLoader.php b/src/Loader/PersisterLoader.php index 4e4bcdfa..a19fa178 100644 --- a/src/Loader/PersisterLoader.php +++ b/src/Loader/PersisterLoader.php @@ -18,6 +18,7 @@ use Fidry\AliceDataFixtures\Persistence\PersisterInterface; use Fidry\AliceDataFixtures\Persistence\PurgeMode; use Fidry\AliceDataFixtures\ProcessorInterface; +use JetBrains\PhpStorm\Pure; use Nelmio\Alice\IsAServiceTrait; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; @@ -42,6 +43,7 @@ /** * @param ProcessorInterface[] $processors */ + #[Pure] public function __construct( LoaderInterface $decoratedLoader, PersisterInterface $persister, diff --git a/src/Loader/SimpleLoader.php b/src/Loader/SimpleLoader.php index 280edb24..9a471d23 100644 --- a/src/Loader/SimpleLoader.php +++ b/src/Loader/SimpleLoader.php @@ -15,6 +15,7 @@ use Fidry\AliceDataFixtures\LoaderInterface; use Fidry\AliceDataFixtures\Persistence\PurgeMode; +use JetBrains\PhpStorm\Pure; use Nelmio\Alice\FilesLoaderInterface; use Nelmio\Alice\IsAServiceTrait; use Psr\Log\LoggerInterface; @@ -35,6 +36,7 @@ private FilesLoaderInterface $filesLoader; private LoggerInterface $logger; + #[Pure] public function __construct(FilesLoaderInterface $fileLoader, LoggerInterface $logger = null) { $this->filesLoader = $fileLoader; From 1b684c45c8775e4eacfc5b8f45c478aa87c704fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 19 Dec 2021 18:19:10 +0100 Subject: [PATCH 02/11] Include bin files for PHP-CS-Fixer --- .php-cs-fixer.dist.php | 4 ++++ bin/console | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index e3f1e6f2..3e6da0fa 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -26,6 +26,10 @@ ) ->append([ __DIR__.'/.php_cs.dist', + __DIR__.'/bin/console', + __DIR__.'/bin/doctrine_purge', + __DIR__.'/bin/eloquent_migrate', + __DIR__.'/bin/eloquent_rollback', ]) ; diff --git a/bin/console b/bin/console index a8f06263..85268fed 100755 --- a/bin/console +++ b/bin/console @@ -23,11 +23,12 @@ use Symfony\Component\HttpKernel\KernelInterface; $serverArgs = &$_SERVER['argv']; $kernelInput = 'NakedKernel'; + foreach ($serverArgs as $index => $arg) { if ('-k' === $arg || '--kernel' === $arg) { $kernelInput = $serverArgs[$index + 1]; - unset($serverArgs[$index]); - unset($serverArgs[$index + 1]); + unset($serverArgs[$index], $serverArgs[$index + 1]); + break; } @@ -43,12 +44,13 @@ foreach ($serverArgs as $index => $arg) { break; } } + $serverArgs = array_values($serverArgs); $kernelClass = 'Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp\\'.$kernelInput; $input = new ArgvInput(); -$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: uniqid()); -$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod'; +$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: uniqid()); +$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod'; if ($debug) { Debug::enable(); From f5d6c01bdd6dfd65c791df52387bdba8a8e0cde5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 19 Dec 2021 18:23:30 +0100 Subject: [PATCH 03/11] Replace qualifiers by an import --- bin/console | 4 ++-- tests/Bridge/Doctrine/Purger/PurgerTest.php | 5 +++-- tests/Bridge/DoctrineMongoDB/Purger/PurgerTest.php | 3 ++- tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php | 3 ++- tests/Bridge/Eloquent/Purger/ModelPurgerTest.php | 5 +++-- .../Doctrine/FidryAliceDataFixturesBundleTest.php | 12 ++++++++---- .../Eloquent/FidryAliceDataFixturesBundleTest.php | 12 ++++++++---- .../Symfony/Eloquent/ORMLoaderIntegrationTest.php | 4 ---- .../Symfony/FidryAliceDataFixturesBundleTest.php | 9 ++++++--- tests/Exception/MaxPassReachedExceptionTest.php | 9 ++++++--- tests/Loader/FileResolverLoaderTest.php | 2 +- tests/Loader/FileTrackerTest.php | 3 ++- tests/Persistence/PurgeModeTest.php | 3 ++- 13 files changed, 45 insertions(+), 29 deletions(-) diff --git a/bin/console b/bin/console index 85268fed..c14ac337 100755 --- a/bin/console +++ b/bin/console @@ -33,13 +33,13 @@ foreach ($serverArgs as $index => $arg) { } if ('-k=' === substr($arg, 0, 3)) { - $kernelInput = substr($serverArgs[$index], 3); + $kernelInput = substr($arg, 3); unset($serverArgs[$index]); break; } if ('--kernel=' === substr($arg, 0, 9)) { - $kernelInput = substr($serverArgs[$index], 9); + $kernelInput = substr($arg, 9); unset($serverArgs[$index]); break; } diff --git a/tests/Bridge/Doctrine/Purger/PurgerTest.php b/tests/Bridge/Doctrine/Purger/PurgerTest.php index 56e90a3f..248934de 100644 --- a/tests/Bridge/Doctrine/Purger/PurgerTest.php +++ b/tests/Bridge/Doctrine/Purger/PurgerTest.php @@ -25,6 +25,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use ReflectionClass; +use ReflectionObject; /** * @covers \Fidry\AliceDataFixtures\Bridge\Doctrine\Purger\Purger @@ -54,7 +55,7 @@ public function testCreatesADoctrineOrmPurgerWithTheAppropriateManagerAndPurgeMo $purgeMode = PurgeMode::createTruncateMode(); $purger = new Purger($manager, $purgeMode); - $decoratedPurgerReflection = (new \ReflectionObject($purger))->getProperty('purger'); + $decoratedPurgerReflection = (new ReflectionObject($purger))->getProperty('purger'); $decoratedPurgerReflection->setAccessible(true); /** @var DoctrineOrmPurger $decoratedPurger */ $decoratedPurger = $decoratedPurgerReflection->getValue($purger); @@ -81,7 +82,7 @@ public function testDisableFKChecksOnDeleteIsPerformed(): void $purgeMode = PurgeMode::createDeleteMode(); $purger = new Purger($manager->reveal(), $purgeMode); - $decoratedPurgerReflection = (new \ReflectionObject($purger))->getProperty('purger'); + $decoratedPurgerReflection = (new ReflectionObject($purger))->getProperty('purger'); $decoratedPurgerReflection->setAccessible(true); $decoratedPurgerReflection->setValue($purger, $purgerORM->reveal()); diff --git a/tests/Bridge/DoctrineMongoDB/Purger/PurgerTest.php b/tests/Bridge/DoctrineMongoDB/Purger/PurgerTest.php index 36abf169..9ba54ad1 100644 --- a/tests/Bridge/DoctrineMongoDB/Purger/PurgerTest.php +++ b/tests/Bridge/DoctrineMongoDB/Purger/PurgerTest.php @@ -19,6 +19,7 @@ use Fidry\AliceDataFixtures\Bridge\Doctrine\Purger\Purger; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; +use ReflectionObject; /** * @covers \Fidry\AliceDataFixtures\Bridge\Doctrine\Purger\Purger @@ -34,7 +35,7 @@ public function testCreatesADoctrineOdmPurgerWithTheAppropriateManager(): void $manager = $this->prophesize(DocumentManager::class)->reveal(); $purger = new Purger($manager); - $decoratedPurgerReflection = (new \ReflectionObject($purger))->getProperty('purger'); + $decoratedPurgerReflection = (new ReflectionObject($purger))->getProperty('purger'); $decoratedPurgerReflection->setAccessible(true); $decoratedPurger = $decoratedPurgerReflection->getValue($purger); diff --git a/tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php b/tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php index 0d1f2d2a..c452ac02 100644 --- a/tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php +++ b/tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php @@ -24,6 +24,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; use ReflectionClass; +use ReflectionObject; /** * @covers \Fidry\AliceDataFixtures\Bridge\Doctrine\Purger\Purger @@ -52,7 +53,7 @@ public function testCreatesADoctrineOrmPurgerWithTheAppropriateManagerAndPurgeMo $manager = $this->prophesize(DocumentManager::class)->reveal(); $purger = new Purger($manager); - $decoratedPurgerReflection = (new \ReflectionObject($purger))->getProperty('purger'); + $decoratedPurgerReflection = (new ReflectionObject($purger))->getProperty('purger'); $decoratedPurgerReflection->setAccessible(true); /** @var DoctrineOrmPurger $decoratedPurger */ $decoratedPurger = $decoratedPurgerReflection->getValue($purger); diff --git a/tests/Bridge/Eloquent/Purger/ModelPurgerTest.php b/tests/Bridge/Eloquent/Purger/ModelPurgerTest.php index 251ed4d9..bbca6d8c 100644 --- a/tests/Bridge/Eloquent/Purger/ModelPurgerTest.php +++ b/tests/Bridge/Eloquent/Purger/ModelPurgerTest.php @@ -20,6 +20,7 @@ use Fidry\AliceDataFixtures\Persistence\PurgerInterface; use Illuminate\Database\Migrations\MigrationRepositoryInterface; use Illuminate\Database\Migrations\Migrator; +use InvalidArgumentException; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; @@ -141,7 +142,7 @@ public function testCannotCreateANewPurgerWithTruncateMode(): void try { $purger->create(PurgeMode::createTruncateMode()); $this->fail('Expected exception to be thrown.'); - } catch (\InvalidArgumentException $exception) { + } catch (InvalidArgumentException $exception) { $this->assertEquals($expectedExceptionMessage, $exception->getMessage()); } @@ -151,7 +152,7 @@ public function testCannotCreateANewPurgerWithTruncateMode(): void new ModelPurger(new FakeMigrationRepository(), 'bar', $migrator) ); $this->fail('Expected exception to be thrown.'); - } catch (\InvalidArgumentException $exception) { + } catch (InvalidArgumentException $exception) { $this->assertEquals($expectedExceptionMessage, $exception->getMessage()); } } diff --git a/tests/Bridge/Symfony/Doctrine/FidryAliceDataFixturesBundleTest.php b/tests/Bridge/Symfony/Doctrine/FidryAliceDataFixturesBundleTest.php index e8c75c33..a36e7566 100644 --- a/tests/Bridge/Symfony/Doctrine/FidryAliceDataFixturesBundleTest.php +++ b/tests/Bridge/Symfony/Doctrine/FidryAliceDataFixturesBundleTest.php @@ -13,8 +13,12 @@ namespace Fidry\AliceDataFixtures\Bridge\Symfony\Doctrine; +use Fidry\AliceDataFixtures\Bridge\Doctrine\Persister\ObjectManagerPersister; +use Fidry\AliceDataFixtures\Bridge\Doctrine\Purger\Purger; use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundleTest as NakedFidryAliceDataFixturesBundleTest; use Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp\DoctrineKernel; +use Fidry\AliceDataFixtures\Loader\PersisterLoader; +use Fidry\AliceDataFixtures\Loader\PurgerLoader; /** * @coversNothing @@ -36,22 +40,22 @@ public function testServiceRegistration(): void parent::testServiceRegistration(); $this->assertServiceIsInstanceOf( - \Fidry\AliceDataFixtures\Bridge\Doctrine\Purger\Purger::class, + Purger::class, 'fidry_alice_data_fixtures.persistence.purger.doctrine.orm_purger' ); $this->assertServiceIsInstanceOf( - \Fidry\AliceDataFixtures\Bridge\Doctrine\Persister\ObjectManagerPersister::class, + ObjectManagerPersister::class, 'fidry_alice_data_fixtures.persistence.persister.doctrine.object_manager_persister' ); $this->assertServiceIsInstanceOf( - \Fidry\AliceDataFixtures\Loader\PersisterLoader::class, + PersisterLoader::class, 'fidry_alice_data_fixtures.doctrine.persister_loader' ); $this->assertServiceIsInstanceOf( - \Fidry\AliceDataFixtures\Loader\PurgerLoader::class, + PurgerLoader::class, 'fidry_alice_data_fixtures.doctrine.purger_loader' ); } diff --git a/tests/Bridge/Symfony/Eloquent/FidryAliceDataFixturesBundleTest.php b/tests/Bridge/Symfony/Eloquent/FidryAliceDataFixturesBundleTest.php index d74dec8d..9d544ee2 100644 --- a/tests/Bridge/Symfony/Eloquent/FidryAliceDataFixturesBundleTest.php +++ b/tests/Bridge/Symfony/Eloquent/FidryAliceDataFixturesBundleTest.php @@ -13,8 +13,12 @@ namespace Fidry\AliceDataFixtures\Bridge\Symfony\Eloquent; +use Fidry\AliceDataFixtures\Bridge\Eloquent\Persister\ModelPersister; +use Fidry\AliceDataFixtures\Bridge\Eloquent\Purger\ModelPurger; use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundleTest as NakedFidryAliceDataFixturesBundleTest; use Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp\EloquentKernel; +use Fidry\AliceDataFixtures\Loader\PersisterLoader; +use Fidry\AliceDataFixtures\Loader\PurgerLoader; use Symfony\Component\HttpKernel\KernelInterface; /** @@ -39,22 +43,22 @@ public function testServiceRegistration(): void parent::testServiceRegistration(); $this->assertServiceIsInstanceOf( - \Fidry\AliceDataFixtures\Bridge\Eloquent\Purger\ModelPurger::class, + ModelPurger::class, 'fidry_alice_data_fixtures.persistence.purger.eloquent.model_purger' ); $this->assertServiceIsInstanceOf( - \Fidry\AliceDataFixtures\Bridge\Eloquent\Persister\ModelPersister::class, + ModelPersister::class, 'fidry_alice_data_fixtures.persistence.persister.eloquent.model_persister' ); $this->assertServiceIsInstanceOf( - \Fidry\AliceDataFixtures\Loader\PersisterLoader::class, + PersisterLoader::class, 'fidry_alice_data_fixtures.eloquent.persister_loader' ); $this->assertServiceIsInstanceOf( - \Fidry\AliceDataFixtures\Loader\PurgerLoader::class, + PurgerLoader::class, 'fidry_alice_data_fixtures.eloquent.purger_loader' ); } diff --git a/tests/Bridge/Symfony/Eloquent/ORMLoaderIntegrationTest.php b/tests/Bridge/Symfony/Eloquent/ORMLoaderIntegrationTest.php index 00eadfa3..88922142 100644 --- a/tests/Bridge/Symfony/Eloquent/ORMLoaderIntegrationTest.php +++ b/tests/Bridge/Symfony/Eloquent/ORMLoaderIntegrationTest.php @@ -17,7 +17,6 @@ use Fidry\AliceDataFixtures\Bridge\Eloquent\Model\Dummy; use Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp\EloquentKernel; use Fidry\AliceDataFixtures\LoaderInterface; -use Illuminate\Database\DatabaseManager; use PHPUnit\Framework\TestCase; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArrayInput; @@ -33,8 +32,6 @@ class ORMLoaderIntegrationTest extends TestCase private LoaderInterface $loader; - private DatabaseManager $databaseManager; - private static string $seed; public static function setUpBeforeClass(): void @@ -50,7 +47,6 @@ public function setUp(): void $this->kernel->boot(); $this->kernel->getContainer()->get('wouterj_eloquent.initializer')->initialize(); $this->kernel->getContainer()->get('wouterj_eloquent')->setAsGlobal(); - $this->databaseManager = $this->kernel->getContainer()->get('wouterj_eloquent.database_manager'); $this->loader = $this->kernel->getContainer()->get('fidry_alice_data_fixtures.eloquent.persister_loader'); $this->execute([ diff --git a/tests/Bridge/Symfony/FidryAliceDataFixturesBundleTest.php b/tests/Bridge/Symfony/FidryAliceDataFixturesBundleTest.php index 31d80cdf..3a1912a9 100644 --- a/tests/Bridge/Symfony/FidryAliceDataFixturesBundleTest.php +++ b/tests/Bridge/Symfony/FidryAliceDataFixturesBundleTest.php @@ -15,6 +15,9 @@ use Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp\InvalidKernel; use Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp\NakedKernel; +use Fidry\AliceDataFixtures\Loader\MultiPassLoader; +use Fidry\AliceDataFixtures\Loader\SimpleLoader; +use LogicException; use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpKernel\KernelInterface; @@ -49,19 +52,19 @@ public function tearDown(): void public function testServiceRegistration(): void { $this->assertServiceIsInstanceOf( - \Fidry\AliceDataFixtures\Loader\MultiPassLoader::class, + MultiPassLoader::class, 'fidry_alice_data_fixtures.loader.multipass_file' ); $this->assertServiceIsInstanceOf( - \Fidry\AliceDataFixtures\Loader\SimpleLoader::class, + SimpleLoader::class, 'fidry_alice_data_fixtures.loader.simple' ); } public function testCannotBootIfNelmioAliceBundleIsNotRegistered(): void { - $this->expectException(\LogicException::class); + $this->expectException(LogicException::class); $this->expectExceptionMessage('Cannot register "Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle" without "Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle".'); $kernel = InvalidKernel::create(); diff --git a/tests/Exception/MaxPassReachedExceptionTest.php b/tests/Exception/MaxPassReachedExceptionTest.php index 1639ebea..37409cf2 100644 --- a/tests/Exception/MaxPassReachedExceptionTest.php +++ b/tests/Exception/MaxPassReachedExceptionTest.php @@ -13,9 +13,12 @@ namespace Fidry\AliceDataFixtures\Exception; +use Error; +use Exception; use Fidry\AliceDataFixtures\Loader\ErrorTracker; use Nelmio\Alice\Throwable\LoadingThrowable; use PHPUnit\Framework\TestCase; +use RuntimeException; /** * @covers \Fidry\AliceDataFixtures\Exception\MaxPassReachedException @@ -24,7 +27,7 @@ class MaxPassReachedExceptionTest extends TestCase { public function testIsARuntimeException(): void { - $this->assertTrue(is_a(MaxPassReachedException::class, \RuntimeException::class, true)); + $this->assertTrue(is_a(MaxPassReachedException::class, RuntimeException::class, true)); } public function testIsALoadingException(): void @@ -42,9 +45,9 @@ public function testInstantiation(): void $code = 100; - $previous = new \Error(); + $previous = new Error(); $tracker = new ErrorTracker(); - $tracker->register('/foo.php', new \Exception('bar')); + $tracker->register('/foo.php', new Exception('bar')); $exception = new MaxPassReachedException('foo', $code, $previous, $tracker); $this->assertEquals('foo', $exception->getMessage()); diff --git a/tests/Loader/FileResolverLoaderTest.php b/tests/Loader/FileResolverLoaderTest.php index 664e5769..b9fe6971 100644 --- a/tests/Loader/FileResolverLoaderTest.php +++ b/tests/Loader/FileResolverLoaderTest.php @@ -106,7 +106,7 @@ public function testParametersAndObjectsInjectedArePassedToTheDecoratedLoader(): $loader = $loaderProphecy->reveal(); $loader = new FileResolverLoader($loader, new DummyResolver()); - $result = $loader->load($files, $parameters, $objects, null); + $result = $loader->load($files, $parameters, $objects); $this->assertEquals( [ diff --git a/tests/Loader/FileTrackerTest.php b/tests/Loader/FileTrackerTest.php index 03b5e70c..7f0d8433 100644 --- a/tests/Loader/FileTrackerTest.php +++ b/tests/Loader/FileTrackerTest.php @@ -13,6 +13,7 @@ namespace Fidry\AliceDataFixtures\Loader; +use InvalidArgumentException; use PHPUnit\Framework\TestCase; /** @@ -37,7 +38,7 @@ public function testCanMarkFilesAsLoaded(): void public function testCannotMarkUntrackedFileAsLoaded(): void { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('The file "foo" is not being tracked. As such, it cannot be marked as "loaded".'); $tracker = new FileTracker(''); diff --git a/tests/Persistence/PurgeModeTest.php b/tests/Persistence/PurgeModeTest.php index fe9ba8bb..ec288dbc 100644 --- a/tests/Persistence/PurgeModeTest.php +++ b/tests/Persistence/PurgeModeTest.php @@ -13,6 +13,7 @@ namespace Fidry\AliceDataFixtures\Persistence; +use InvalidArgumentException; use PHPUnit\Framework\TestCase; /** @@ -22,7 +23,7 @@ class PurgeModeTest extends TestCase { public function testThrowsAnExceptionIfUnknownPurgeModeIsGiven(): void { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Unknown purge mode "3".'); new PurgeMode(3); From f1b6be774c80cdaaba554ca85e825590ab7614a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 19 Dec 2021 18:24:34 +0100 Subject: [PATCH 04/11] Make use of starts_with where possible --- bin/console | 4 ++-- fixtures/Bridge/Symfony/SymfonyApp/IsolatedKernel.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/console b/bin/console index c14ac337..f2d531a7 100755 --- a/bin/console +++ b/bin/console @@ -32,13 +32,13 @@ foreach ($serverArgs as $index => $arg) { break; } - if ('-k=' === substr($arg, 0, 3)) { + if (str_starts_with($arg, '-k=')) { $kernelInput = substr($arg, 3); unset($serverArgs[$index]); break; } - if ('--kernel=' === substr($arg, 0, 9)) { + if (str_starts_with($arg, '--kernel=')) { $kernelInput = substr($arg, 9); unset($serverArgs[$index]); break; diff --git a/fixtures/Bridge/Symfony/SymfonyApp/IsolatedKernel.php b/fixtures/Bridge/Symfony/SymfonyApp/IsolatedKernel.php index 1ce8f2f9..6c71c388 100644 --- a/fixtures/Bridge/Symfony/SymfonyApp/IsolatedKernel.php +++ b/fixtures/Bridge/Symfony/SymfonyApp/IsolatedKernel.php @@ -37,14 +37,14 @@ public function build(ContainerBuilder $container): void public function process(ContainerBuilder $container) { foreach ($container->getDefinitions() as $id => $definition) { - if (strpos($id, 'fidry_alice_data_fixtures') !== 0) { + if (!str_starts_with($id, 'fidry_alice_data_fixtures')) { continue; } $definition->setPublic(true); } foreach ($container->getAliases() as $id => $definition) { - if (strpos($id, 'fidry_alice_data_fixtures') !== 0) { + if (!str_starts_with($id, 'fidry_alice_data_fixtures')) { continue; } From 84dee9b991ef4f766b03c476d0d0802e74be6705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 19 Dec 2021 18:25:31 +0100 Subject: [PATCH 05/11] Remove unused variables --- tests/Loader/ErrorTrackerTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Loader/ErrorTrackerTest.php b/tests/Loader/ErrorTrackerTest.php index c90a85ea..d6e57304 100644 --- a/tests/Loader/ErrorTrackerTest.php +++ b/tests/Loader/ErrorTrackerTest.php @@ -52,13 +52,13 @@ public function testKeepsTrackOfErrors(): void public function testIsDeepClonable(): void { $tracker = new ErrorTracker(); - $tracker->register('foo', new Exception($message0 = 'foo exception')); + $tracker->register('foo', new Exception('foo exception')); $originalTracker = new ErrorTracker(); - $originalTracker->register('foo', new Exception($message0 = 'foo exception')); + $originalTracker->register('foo', new Exception('foo exception')); $newTracker = clone $tracker; - $newTracker->register('bar', new Exception($message1 = 'bar exception')); + $newTracker->register('bar', new Exception('bar exception')); $this->assertEquals($originalTracker->getStack(), $tracker->getStack()); $this->assertNotEquals($tracker->getStack(), $newTracker->getStack()); From 3d605312e55998be146ea8e237ecb67e06f5d970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 19 Dec 2021 18:26:42 +0100 Subject: [PATCH 06/11] Remove redundant @var phpdoc --- tests/Bridge/Eloquent/Purger/ModelPurgerTest.php | 6 ------ tests/Loader/PurgerLoaderTest.php | 9 --------- 2 files changed, 15 deletions(-) diff --git a/tests/Bridge/Eloquent/Purger/ModelPurgerTest.php b/tests/Bridge/Eloquent/Purger/ModelPurgerTest.php index bbca6d8c..d2f77518 100644 --- a/tests/Bridge/Eloquent/Purger/ModelPurgerTest.php +++ b/tests/Bridge/Eloquent/Purger/ModelPurgerTest.php @@ -55,13 +55,11 @@ public function testRollbackAndRunMigrationsForPurgingTheDatabase(): void { $migrationPath = '/path/to/migrations'; - /** @var ObjectProphecy $migrationRepositoryProphecy */ $migrationRepositoryProphecy = $this->prophesize(MigrationRepositoryInterface::class); $migrationRepositoryProphecy->repositoryExists()->willReturn(true); /** @var MigrationRepositoryInterface $migrationRepository */ $migrationRepository = $migrationRepositoryProphecy->reveal(); - /** @var ObjectProphecy $migratorProphecy */ $migratorProphecy = $this->prophesize(Migrator::class); $migratorProphecy->reset([$migrationPath])->shouldBeCalled(); $migratorProphecy->run([$migrationPath])->shouldBeCalled(); @@ -80,14 +78,12 @@ public function testCreatesTheMigrationDatabaseIfItDoesntExist(): void { $migrationPath = '/path/to/migrations'; - /** @var ObjectProphecy $migrationRepositoryProphecy */ $migrationRepositoryProphecy = $this->prophesize(MigrationRepositoryInterface::class); $migrationRepositoryProphecy->repositoryExists()->willReturn(false); $migrationRepositoryProphecy->createRepository()->shouldBeCalled(); /** @var MigrationRepositoryInterface $migrationRepository */ $migrationRepository = $migrationRepositoryProphecy->reveal(); - /** @var ObjectProphecy $migratorProphecy */ $migratorProphecy = $this->prophesize(Migrator::class); $migratorProphecy->reset([$migrationPath])->shouldBeCalled(); $migratorProphecy->run([$migrationPath])->shouldBeCalled(); @@ -105,7 +101,6 @@ public function testCreatesTheMigrationDatabaseIfItDoesntExist(): void public function testCanCreateANewPurger(): void { - /** @var ObjectProphecy $migratorProphecy */ $migratorProphecy = $this->prophesize(Migrator::class); $migratorProphecy->reset(Argument::cetera())->shouldNotBeCalled(); /** @var Migrator $migrator */ @@ -132,7 +127,6 @@ public function testCannotCreateANewPurgerWithTruncateMode(): void .'"Fidry\AliceDataFixtures\Bridge\Eloquent\Purger\ModelPurger" (not supported).' ; - /** @var ObjectProphecy $migratorProphecy */ $migratorProphecy = $this->prophesize(Migrator::class); $migratorProphecy->reset(Argument::cetera())->shouldNotBeCalled(); /** @var Migrator $migrator */ diff --git a/tests/Loader/PurgerLoaderTest.php b/tests/Loader/PurgerLoaderTest.php index 7d8c2be2..0b1a1f07 100644 --- a/tests/Loader/PurgerLoaderTest.php +++ b/tests/Loader/PurgerLoaderTest.php @@ -65,13 +65,11 @@ public function testPurgesTheDatabaseBeforeLoadingTheFixturesAndReturningTheResu /** @var LoaderInterface $decoratedLoader */ $decoratedLoader = $decoratedLoaderProphecy->reveal(); - /** @var ObjectProphecy $purgerProphecy */ $purgerProphecy = $this->prophesize(PurgerInterface::class); $purgerProphecy->purge()->shouldBeCalled(); /** @var PurgerInterface $purger */ $purger = $purgerProphecy->reveal(); - /** @var ObjectProphecy $purgerFactoryProphecy */ $purgerFactoryProphecy = $this->prophesize(PurgerFactoryInterface::class); $purgerFactoryProphecy->create($purgeMode)->willReturn($purger); /** @var PurgerFactoryInterface $purgerFactory */ @@ -109,13 +107,11 @@ public function testIfNoPurgeModeIsGivenThenUseDefaultPurgeModeWithDelete(): voi /** @var LoaderInterface $decoratedLoader */ $decoratedLoader = $decoratedLoaderProphecy->reveal(); - /** @var ObjectProphecy $purgerProphecy */ $purgerProphecy = $this->prophesize(PurgerInterface::class); $purgerProphecy->purge()->shouldBeCalled(); /** @var PurgerInterface $purger */ $purger = $purgerProphecy->reveal(); - /** @var ObjectProphecy $purgerFactoryProphecy */ $purgerFactoryProphecy = $this->prophesize(PurgerFactoryInterface::class); $purgerFactoryProphecy->create(PurgeMode::createDeleteMode())->willReturn($purger); /** @var PurgerFactoryInterface $purgerFactory */ @@ -153,13 +149,11 @@ public function testIfNoPurgeModeIsGivenThenUseDefaultPurgeModeWithTruncate(): v /** @var LoaderInterface $decoratedLoader */ $decoratedLoader = $decoratedLoaderProphecy->reveal(); - /** @var ObjectProphecy $purgerProphecy */ $purgerProphecy = $this->prophesize(PurgerInterface::class); $purgerProphecy->purge()->shouldBeCalled(); /** @var PurgerInterface $purger */ $purger = $purgerProphecy->reveal(); - /** @var ObjectProphecy $purgerFactoryProphecy */ $purgerFactoryProphecy = $this->prophesize(PurgerFactoryInterface::class); $purgerFactoryProphecy->create(PurgeMode::createTruncateMode())->willReturn($purger); /** @var PurgerFactoryInterface $purgerFactory */ @@ -197,13 +191,11 @@ public function testIfNoPurgeModeIsGivenThenUseDefaultPurgeModeWithNoPurge(): vo /** @var LoaderInterface $decoratedLoader */ $decoratedLoader = $decoratedLoaderProphecy->reveal(); - /** @var ObjectProphecy $purgerProphecy */ $purgerProphecy = $this->prophesize(PurgerInterface::class); $purgerProphecy->purge()->shouldNotBeenCalled(); /** @var PurgerInterface $purger */ $purger = $purgerProphecy->reveal(); - /** @var ObjectProphecy $purgerFactoryProphecy */ $purgerFactoryProphecy = $this->prophesize(PurgerFactoryInterface::class); $purgerFactoryProphecy->create(PurgeMode::createNoPurgeMode())->willReturn($purger); /** @var PurgerFactoryInterface $purgerFactory */ @@ -241,7 +233,6 @@ public function testDoesNotPurgeOnNoPurgeModeGiven(): void /** @var LoaderInterface $decoratedLoader */ $decoratedLoader = $decoratedLoaderProphecy->reveal(); - /** @var ObjectProphecy $purgerFactoryProphecy */ $purgerFactoryProphecy = $this->prophesize(PurgerFactoryInterface::class); $purgerFactoryProphecy->create(Argument::cetera())->shouldNotBeCalled(); /** @var PurgerFactoryInterface $purgerFactory */ From 8b1ff032c6cbb37ca8a4dfbca63e426e1a6b1a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 19 Dec 2021 18:27:25 +0100 Subject: [PATCH 07/11] Make use of asserCount when possible --- .../Persister/ObjectManagerPersisterTest.php | 2 +- tests/Bridge/Doctrine/Purger/PurgerTest.php | 6 +++--- .../Persister/ObjectManagerPersisterTest.php | 2 +- .../Bridge/DoctrineMongoDB/Purger/PurgerTest.php | 6 +++--- .../Persister/ObjectManagerPersisterTest.php | 2 +- tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php | 6 +++--- tests/Bridge/Eloquent/Purger/ModelPurgerTest.php | 1 - .../Doctrine/MongodbLoaderIntegrationTest.php | 4 ++-- .../Doctrine/ORMLoaderIntegrationTest.php | 16 ++++++++-------- .../Doctrine/PhpcrLoaderIntegrationTest.php | 4 ++-- tests/Loader/PurgerLoaderTest.php | 1 - 11 files changed, 24 insertions(+), 26 deletions(-) diff --git a/tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php b/tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php index 420f5618..261e8126 100644 --- a/tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php +++ b/tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php @@ -75,7 +75,7 @@ public function testCanPersistAnEntity($entity, bool $exact = false): void $result = $this->entityManager->getRepository(get_class($entity))->findAll(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); if ($exact) { $this->assertEquals($originalEntity, $result[0]); diff --git a/tests/Bridge/Doctrine/Purger/PurgerTest.php b/tests/Bridge/Doctrine/Purger/PurgerTest.php index 248934de..ab7798b5 100644 --- a/tests/Bridge/Doctrine/Purger/PurgerTest.php +++ b/tests/Bridge/Doctrine/Purger/PurgerTest.php @@ -98,17 +98,17 @@ public function testEmptyDatabase(): void $manager->persist($dummy); $manager->flush(); - $this->assertEquals(1, count($manager->getRepository(Dummy::class)->findAll())); + $this->assertCount(1, $manager->getRepository(Dummy::class)->findAll()); $purger = new Purger($manager, PurgeMode::createDeleteMode()); $purger->purge(); - $this->assertEquals(0, count($manager->getRepository(Dummy::class)->findAll())); + $this->assertCount(0, $manager->getRepository(Dummy::class)->findAll()); // Ensures the schema has been restored $dummy = new Dummy(); $manager->persist($dummy); $manager->flush(); - $this->assertEquals(1, count($manager->getRepository(Dummy::class)->findAll())); + $this->assertCount(1, $manager->getRepository(Dummy::class)->findAll()); } } diff --git a/tests/Bridge/DoctrineMongoDB/Persister/ObjectManagerPersisterTest.php b/tests/Bridge/DoctrineMongoDB/Persister/ObjectManagerPersisterTest.php index 8b131705..2b7dd1a7 100644 --- a/tests/Bridge/DoctrineMongoDB/Persister/ObjectManagerPersisterTest.php +++ b/tests/Bridge/DoctrineMongoDB/Persister/ObjectManagerPersisterTest.php @@ -75,7 +75,7 @@ public function testCanPersistADocument($document, bool $exact = false): void $result = $this->documentManager->getRepository(get_class($document))->findAll(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); } catch (InvalidArgumentException $exception) { if ($exact) { // Do nothing: expected result as unsupported at the moment diff --git a/tests/Bridge/DoctrineMongoDB/Purger/PurgerTest.php b/tests/Bridge/DoctrineMongoDB/Purger/PurgerTest.php index 9ba54ad1..ef440efd 100644 --- a/tests/Bridge/DoctrineMongoDB/Purger/PurgerTest.php +++ b/tests/Bridge/DoctrineMongoDB/Purger/PurgerTest.php @@ -52,17 +52,17 @@ public function testEmptyDatabase(): void $manager->persist($dummy); $manager->flush(); - $this->assertEquals(1, count($manager->getRepository(Dummy::class)->findAll())); + $this->assertCount(1, $manager->getRepository(Dummy::class)->findAll()); $purger = new Purger($manager); $purger->purge(); - $this->assertEquals(0, count($manager->getRepository(Dummy::class)->findAll())); + $this->assertCount(0, $manager->getRepository(Dummy::class)->findAll()); // Ensures the schema has been restored $dummy = new Dummy(); $manager->persist($dummy); $manager->flush(); - $this->assertEquals(1, count($manager->getRepository(Dummy::class)->findAll())); + $this->assertCount(1, $manager->getRepository(Dummy::class)->findAll()); } } diff --git a/tests/Bridge/DoctrinePhpCr/Persister/ObjectManagerPersisterTest.php b/tests/Bridge/DoctrinePhpCr/Persister/ObjectManagerPersisterTest.php index 1153d4e0..f3619d87 100644 --- a/tests/Bridge/DoctrinePhpCr/Persister/ObjectManagerPersisterTest.php +++ b/tests/Bridge/DoctrinePhpCr/Persister/ObjectManagerPersisterTest.php @@ -67,7 +67,7 @@ public function testCanPersistADocument($document): void $result = $this->documentManager->getRepository(get_class($document))->findAll(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); } /** diff --git a/tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php b/tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php index c452ac02..210501c7 100644 --- a/tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php +++ b/tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php @@ -72,18 +72,18 @@ public function testEmptyDatabase(): void $manager->persist($dummy); $manager->flush(); - $this->assertEquals(1, count($manager->getRepository(Dummy::class)->findAll())); + $this->assertCount(1, $manager->getRepository(Dummy::class)->findAll()); $purger = new Purger($manager, PurgeMode::createDeleteMode()); $purger->purge(); - $this->assertEquals(0, count($manager->getRepository(Dummy::class)->findAll())); + $this->assertCount(0, $manager->getRepository(Dummy::class)->findAll()); // Ensures the schema has been restored $dummy = new Dummy(); $dummy->id = '/dummy_'.uniqid(); $manager->persist($dummy); $manager->flush(); - $this->assertEquals(1, count($manager->getRepository(Dummy::class)->findAll())); + $this->assertCount(1, $manager->getRepository(Dummy::class)->findAll()); } } diff --git a/tests/Bridge/Eloquent/Purger/ModelPurgerTest.php b/tests/Bridge/Eloquent/Purger/ModelPurgerTest.php index d2f77518..92fa15c4 100644 --- a/tests/Bridge/Eloquent/Purger/ModelPurgerTest.php +++ b/tests/Bridge/Eloquent/Purger/ModelPurgerTest.php @@ -24,7 +24,6 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use ReflectionClass; /** diff --git a/tests/Bridge/Symfony/Doctrine/MongodbLoaderIntegrationTest.php b/tests/Bridge/Symfony/Doctrine/MongodbLoaderIntegrationTest.php index e225b571..15a63080 100644 --- a/tests/Bridge/Symfony/Doctrine/MongodbLoaderIntegrationTest.php +++ b/tests/Bridge/Symfony/Doctrine/MongodbLoaderIntegrationTest.php @@ -69,7 +69,7 @@ public function testLoadAFile(): void $result = $this->doctrine->getRepository(Dummy::class)->findAll(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); } public function testLoadAFileWithPurger(): void @@ -87,6 +87,6 @@ public function testLoadAFileWithPurger(): void $result = $this->doctrine->getRepository(Dummy::class)->findAll(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); } } diff --git a/tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php b/tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php index 96e65415..e1e8b5f7 100644 --- a/tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php +++ b/tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php @@ -72,7 +72,7 @@ public function testLoadAFile(): void $result = $this->doctrine->getRepository(Dummy::class)->findAll(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); } public function testLoadAFileWithPurger(): void @@ -97,7 +97,7 @@ public function testLoadAFileWithPurger(): void $result = $this->doctrine->getRepository(Dummy::class)->findAll(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); } public function testBidirectionalRelationships(): void @@ -109,8 +109,8 @@ public function testBidirectionalRelationships(): void $users = $this->doctrine->getRepository(User::class)->findAll(); $groups = $this->doctrine->getRepository(Group::class)->findAll(); - $this->assertEquals(5, count($users)); - $this->assertEquals(5, count($groups)); + $this->assertCount(5, $users); + $this->assertCount(5, $groups); } public function testBidirectionalRelationshipsDeclaredInDifferentFiles(): void @@ -123,8 +123,8 @@ public function testBidirectionalRelationshipsDeclaredInDifferentFiles(): void $users = $this->doctrine->getRepository(User::class)->findAll(); $groups = $this->doctrine->getRepository(Group::class)->findAll(); - $this->assertEquals(5, count($users)); - $this->assertEquals(5, count($groups)); + $this->assertCount(5, $users); + $this->assertCount(5, $groups); } public function testBidirectionalRelationshipsDeclaredInDifferentFilesWithCyclingDependence(): void @@ -137,7 +137,7 @@ public function testBidirectionalRelationshipsDeclaredInDifferentFilesWithCyclin $users = $this->doctrine->getRepository(User::class)->findAll(); $groups = $this->doctrine->getRepository(Group::class)->findAll(); - $this->assertEquals(5, count($users)); - $this->assertEquals(5, count($groups)); + $this->assertCount(5, $users); + $this->assertCount(5, $groups); } } diff --git a/tests/Bridge/Symfony/Doctrine/PhpcrLoaderIntegrationTest.php b/tests/Bridge/Symfony/Doctrine/PhpcrLoaderIntegrationTest.php index 0a328e55..12ad663f 100644 --- a/tests/Bridge/Symfony/Doctrine/PhpcrLoaderIntegrationTest.php +++ b/tests/Bridge/Symfony/Doctrine/PhpcrLoaderIntegrationTest.php @@ -67,7 +67,7 @@ public function testLoadAFile(): void $result = $this->doctrine->getRepository(Dummy::class)->findAll(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); } public function testLoadAFileWithPurger(): void @@ -86,6 +86,6 @@ public function testLoadAFileWithPurger(): void $result = $this->doctrine->getRepository(Dummy::class)->findAll(); - $this->assertEquals(1, count($result)); + $this->assertCount(1, $result); } } diff --git a/tests/Loader/PurgerLoaderTest.php b/tests/Loader/PurgerLoaderTest.php index 0b1a1f07..1c81c124 100644 --- a/tests/Loader/PurgerLoaderTest.php +++ b/tests/Loader/PurgerLoaderTest.php @@ -20,7 +20,6 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use ReflectionClass; use stdClass; From 7c55e2c266a716df7347ad6beb87e49144988269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 19 Dec 2021 18:29:36 +0100 Subject: [PATCH 08/11] Use PHPUnit assertion methods as static methods --- .../Persister/ObjectManagerPersisterTest.php | 28 +++++++++---------- .../Bridge/Doctrine/Purger/PurgeModeTest.php | 4 +-- tests/Bridge/Doctrine/Purger/PurgerTest.php | 18 ++++++------ .../Persister/ObjectManagerPersisterTest.php | 6 ++-- .../DoctrineMongoDB/Purger/PurgerTest.php | 10 +++---- .../Persister/ObjectManagerPersisterTest.php | 6 ++-- .../DoctrinePhpCr/Purger/PurgerTest.php | 16 +++++------ .../Eloquent/Persister/ModelPersisterTest.php | 20 ++++++------- .../Eloquent/Purger/ModelPurgerTest.php | 20 ++++++------- .../DependencyInjection/ConfigurationTest.php | 4 +-- .../FidryAliceDataFixturesBundleTest.php | 8 +++--- .../Doctrine/MongodbLoaderIntegrationTest.php | 4 +-- .../Doctrine/ORMLoaderIntegrationTest.php | 16 +++++------ .../Doctrine/PhpcrLoaderIntegrationTest.php | 4 +-- .../FidryAliceDataFixturesBundleTest.php | 8 +++--- .../Eloquent/ORMLoaderIntegrationTest.php | 12 ++++---- .../FidryAliceDataFixturesBundleTest.php | 6 ++-- .../FidryAliceDataFixturesBundleTest.php | 8 +++--- .../FidryAliceDataFixturesBundleTest.php | 8 +++--- .../Exception/MaxPassReachedExceptionTest.php | 20 ++++++------- tests/Loader/ErrorTrackerTest.php | 8 +++--- tests/Loader/FileResolverLoaderTest.php | 8 +++--- tests/Loader/FileTrackerTest.php | 14 +++++----- tests/Loader/MultiPassFileLoaderTest.php | 18 ++++++------ tests/Loader/PersisterLoaderTest.php | 14 +++++----- tests/Loader/ProcessorIndexTest.php | 4 +-- tests/Loader/PurgerLoaderTest.php | 14 +++++----- tests/Loader/SimpleLoaderTest.php | 6 ++-- .../Persister/NullPersisterTest.php | 4 +-- tests/Persistence/PurgeModeTest.php | 8 +++--- 30 files changed, 162 insertions(+), 162 deletions(-) diff --git a/tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php b/tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php index 261e8126..ed341539 100644 --- a/tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php +++ b/tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php @@ -53,12 +53,12 @@ public function tearDown(): void public function testIsAPersister(): void { - $this->assertTrue(is_a(ObjectManagerPersister::class, PersisterInterface::class, true)); + self::assertTrue(is_a(ObjectManagerPersister::class, PersisterInterface::class, true)); } public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(ObjectManagerPersister::class))->isCloneable()); + self::assertFalse((new ReflectionClass(ObjectManagerPersister::class))->isCloneable()); } /** @@ -75,10 +75,10 @@ public function testCanPersistAnEntity($entity, bool $exact = false): void $result = $this->entityManager->getRepository(get_class($entity))->findAll(); - $this->assertCount(1, $result); + self::assertCount(1, $result); if ($exact) { - $this->assertEquals($originalEntity, $result[0]); + self::assertEquals($originalEntity, $result[0]); } } @@ -98,12 +98,12 @@ public function testCanPersistAnEntityWithRelationsAndExplicitIds(): void $this->entityManager->clear(); $result = $this->entityManager->getRepository(DummyWithIdentifier::class)->findOneBy(['id' => 100]); - $this->assertInstanceOf(DummyWithIdentifier::class, $result); - $this->assertEquals($result->id, $dummy->id); + self::assertInstanceOf(DummyWithIdentifier::class, $result); + self::assertEquals($result->id, $dummy->id); $result = $this->entityManager->getRepository(DummyWithRelation::class)->findOneBy(['id' => 200]); - $this->assertInstanceOf(DummyWithRelation::class, $result); - $this->assertEquals($result->id, $dummyWithRelation->id); + self::assertInstanceOf(DummyWithRelation::class, $result); + self::assertEquals($result->id, $dummyWithRelation->id); } public function testCanPersistMultipleEntitiesWithExplicitIdentifierSet(): void @@ -118,7 +118,7 @@ public function testCanPersistMultipleEntitiesWithExplicitIdentifierSet(): void $classMetadata = $this->entityManager->getClassMetadata(DummyWithIdentifier::class); - $this->assertEquals( + self::assertEquals( IdGenerator::class, get_class($classMetadata->idGenerator), 'ID generator should be changed.' @@ -128,14 +128,14 @@ public function testCanPersistMultipleEntitiesWithExplicitIdentifierSet(): void $classMetadata = $this->entityManager->getClassMetadata(DummyWithIdentifier::class); - $this->assertNotEquals( + self::assertNotEquals( IdGenerator::class, get_class($classMetadata->idGenerator), 'ID generator should be restored after flush.' ); $entity = $this->entityManager->getRepository(DummyWithIdentifier::class)->find(200); - $this->assertInstanceOf(DummyWithIdentifier::class, $entity); + self::assertInstanceOf(DummyWithIdentifier::class, $entity); } public function testCanPersistEntitiesWithoutExplicitIdentifierSetEvenWhenExistingEntitiesHaveOne(): void @@ -171,10 +171,10 @@ public function testCanPersistEntitiesWithoutExplicitIdentifierSetEvenWhenExisti $this->persister->flush(); $entity = $this->entityManager->getRepository(Dummy::class)->find($dummy1->id); - $this->assertInstanceOf(Dummy::class, $entity); + self::assertInstanceOf(Dummy::class, $entity); $entity = $this->entityManager->getRepository(Dummy::class)->find($dummy2->id); - $this->assertInstanceOf(Dummy::class, $entity); + self::assertInstanceOf(Dummy::class, $entity); } public function testPersistingMultipleEntitiesWithAndWithoutExplicitIdentifierSetWillNotThrowORMException(): void @@ -210,7 +210,7 @@ public function testDoesNotPersistEmbeddables($dummy): void $this->persister->persist($dummy); $this->persister->flush(); - $this->assertTrue(true, 'Everything is fine.'); + self::assertTrue(true, 'Everything is fine.'); } public static function provideEntities(): iterable diff --git a/tests/Bridge/Doctrine/Purger/PurgeModeTest.php b/tests/Bridge/Doctrine/Purger/PurgeModeTest.php index c654bf41..baa72130 100644 --- a/tests/Bridge/Doctrine/Purger/PurgeModeTest.php +++ b/tests/Bridge/Doctrine/Purger/PurgeModeTest.php @@ -25,9 +25,9 @@ class PurgeModeTest extends TestCase public function testThePurgerModesValueIsSynchronizedWithDoctrinePurgerMode(): void { $mode = PurgeMode::createDeleteMode(); - $this->assertEquals(ORMPurger::PURGE_MODE_DELETE, $mode->getValue()); + self::assertEquals(ORMPurger::PURGE_MODE_DELETE, $mode->getValue()); $mode = PurgeMode::createTruncateMode(); - $this->assertEquals(ORMPurger::PURGE_MODE_TRUNCATE, $mode->getValue()); + self::assertEquals(ORMPurger::PURGE_MODE_TRUNCATE, $mode->getValue()); } } diff --git a/tests/Bridge/Doctrine/Purger/PurgerTest.php b/tests/Bridge/Doctrine/Purger/PurgerTest.php index ab7798b5..331a270b 100644 --- a/tests/Bridge/Doctrine/Purger/PurgerTest.php +++ b/tests/Bridge/Doctrine/Purger/PurgerTest.php @@ -36,17 +36,17 @@ class PurgerTest extends TestCase public function testIsAPurger(): void { - $this->assertTrue(is_a(Purger::class, PurgerInterface::class, true)); + self::assertTrue(is_a(Purger::class, PurgerInterface::class, true)); } public function testIsAPurgerFactory(): void { - $this->assertTrue(is_a(Purger::class, PurgerFactoryInterface::class, true)); + self::assertTrue(is_a(Purger::class, PurgerFactoryInterface::class, true)); } public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(Purger::class))->isCloneable()); + self::assertFalse((new ReflectionClass(Purger::class))->isCloneable()); } public function testCreatesADoctrineOrmPurgerWithTheAppropriateManagerAndPurgeMode(): void @@ -60,9 +60,9 @@ public function testCreatesADoctrineOrmPurgerWithTheAppropriateManagerAndPurgeMo /** @var DoctrineOrmPurger $decoratedPurger */ $decoratedPurger = $decoratedPurgerReflection->getValue($purger); - $this->assertInstanceOf(DoctrineOrmPurger::class, $decoratedPurger); - $this->assertEquals($manager, $decoratedPurger->getObjectManager()); - $this->assertEquals(DoctrineOrmPurger::PURGE_MODE_TRUNCATE, $decoratedPurger->getPurgeMode()); + self::assertInstanceOf(DoctrineOrmPurger::class, $decoratedPurger); + self::assertEquals($manager, $decoratedPurger->getObjectManager()); + self::assertEquals(DoctrineOrmPurger::PURGE_MODE_TRUNCATE, $decoratedPurger->getPurgeMode()); } public function testDisableFKChecksOnDeleteIsPerformed(): void @@ -98,17 +98,17 @@ public function testEmptyDatabase(): void $manager->persist($dummy); $manager->flush(); - $this->assertCount(1, $manager->getRepository(Dummy::class)->findAll()); + self::assertCount(1, $manager->getRepository(Dummy::class)->findAll()); $purger = new Purger($manager, PurgeMode::createDeleteMode()); $purger->purge(); - $this->assertCount(0, $manager->getRepository(Dummy::class)->findAll()); + self::assertCount(0, $manager->getRepository(Dummy::class)->findAll()); // Ensures the schema has been restored $dummy = new Dummy(); $manager->persist($dummy); $manager->flush(); - $this->assertCount(1, $manager->getRepository(Dummy::class)->findAll()); + self::assertCount(1, $manager->getRepository(Dummy::class)->findAll()); } } diff --git a/tests/Bridge/DoctrineMongoDB/Persister/ObjectManagerPersisterTest.php b/tests/Bridge/DoctrineMongoDB/Persister/ObjectManagerPersisterTest.php index 2b7dd1a7..4e704a77 100644 --- a/tests/Bridge/DoctrineMongoDB/Persister/ObjectManagerPersisterTest.php +++ b/tests/Bridge/DoctrineMongoDB/Persister/ObjectManagerPersisterTest.php @@ -54,12 +54,12 @@ public function tearDown(): void public function testIsAPersister(): void { - $this->assertTrue(is_a(ObjectManagerPersister::class, PersisterInterface::class, true)); + self::assertTrue(is_a(ObjectManagerPersister::class, PersisterInterface::class, true)); } public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(ObjectManagerPersister::class))->isCloneable()); + self::assertFalse((new ReflectionClass(ObjectManagerPersister::class))->isCloneable()); } /** @@ -75,7 +75,7 @@ public function testCanPersistADocument($document, bool $exact = false): void $result = $this->documentManager->getRepository(get_class($document))->findAll(); - $this->assertCount(1, $result); + self::assertCount(1, $result); } catch (InvalidArgumentException $exception) { if ($exact) { // Do nothing: expected result as unsupported at the moment diff --git a/tests/Bridge/DoctrineMongoDB/Purger/PurgerTest.php b/tests/Bridge/DoctrineMongoDB/Purger/PurgerTest.php index ef440efd..a3c3a563 100644 --- a/tests/Bridge/DoctrineMongoDB/Purger/PurgerTest.php +++ b/tests/Bridge/DoctrineMongoDB/Purger/PurgerTest.php @@ -39,8 +39,8 @@ public function testCreatesADoctrineOdmPurgerWithTheAppropriateManager(): void $decoratedPurgerReflection->setAccessible(true); $decoratedPurger = $decoratedPurgerReflection->getValue($purger); - $this->assertInstanceOf(MongoDBPurger::class, $decoratedPurger); - $this->assertEquals($manager, $decoratedPurger->getObjectManager()); + self::assertInstanceOf(MongoDBPurger::class, $decoratedPurger); + self::assertEquals($manager, $decoratedPurger->getObjectManager()); } public function testEmptyDatabase(): void @@ -52,17 +52,17 @@ public function testEmptyDatabase(): void $manager->persist($dummy); $manager->flush(); - $this->assertCount(1, $manager->getRepository(Dummy::class)->findAll()); + self::assertCount(1, $manager->getRepository(Dummy::class)->findAll()); $purger = new Purger($manager); $purger->purge(); - $this->assertCount(0, $manager->getRepository(Dummy::class)->findAll()); + self::assertCount(0, $manager->getRepository(Dummy::class)->findAll()); // Ensures the schema has been restored $dummy = new Dummy(); $manager->persist($dummy); $manager->flush(); - $this->assertCount(1, $manager->getRepository(Dummy::class)->findAll()); + self::assertCount(1, $manager->getRepository(Dummy::class)->findAll()); } } diff --git a/tests/Bridge/DoctrinePhpCr/Persister/ObjectManagerPersisterTest.php b/tests/Bridge/DoctrinePhpCr/Persister/ObjectManagerPersisterTest.php index f3619d87..5d335bd7 100644 --- a/tests/Bridge/DoctrinePhpCr/Persister/ObjectManagerPersisterTest.php +++ b/tests/Bridge/DoctrinePhpCr/Persister/ObjectManagerPersisterTest.php @@ -49,12 +49,12 @@ public function tearDown(): void public function testIsAPersister(): void { - $this->assertTrue(is_a(ObjectManagerPersister::class, PersisterInterface::class, true)); + self::assertTrue(is_a(ObjectManagerPersister::class, PersisterInterface::class, true)); } public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(ObjectManagerPersister::class))->isCloneable()); + self::assertFalse((new ReflectionClass(ObjectManagerPersister::class))->isCloneable()); } /** @@ -67,7 +67,7 @@ public function testCanPersistADocument($document): void $result = $this->documentManager->getRepository(get_class($document))->findAll(); - $this->assertCount(1, $result); + self::assertCount(1, $result); } /** diff --git a/tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php b/tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php index 210501c7..8a330f51 100644 --- a/tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php +++ b/tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php @@ -35,17 +35,17 @@ class PurgerTest extends TestCase public function testIsAPurger(): void { - $this->assertTrue(is_a(Purger::class, PurgerInterface::class, true)); + self::assertTrue(is_a(Purger::class, PurgerInterface::class, true)); } public function testIsAPurgerFactory(): void { - $this->assertTrue(is_a(Purger::class, PurgerFactoryInterface::class, true)); + self::assertTrue(is_a(Purger::class, PurgerFactoryInterface::class, true)); } public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(Purger::class))->isCloneable()); + self::assertFalse((new ReflectionClass(Purger::class))->isCloneable()); } public function testCreatesADoctrineOrmPurgerWithTheAppropriateManagerAndPurgeMode(): void @@ -58,8 +58,8 @@ public function testCreatesADoctrineOrmPurgerWithTheAppropriateManagerAndPurgeMo /** @var DoctrineOrmPurger $decoratedPurger */ $decoratedPurger = $decoratedPurgerReflection->getValue($purger); - $this->assertInstanceOf(PHPCRPurger::class, $decoratedPurger); - $this->assertEquals($manager, $decoratedPurger->getObjectManager()); + self::assertInstanceOf(PHPCRPurger::class, $decoratedPurger); + self::assertEquals($manager, $decoratedPurger->getObjectManager()); } public function testEmptyDatabase(): void @@ -72,18 +72,18 @@ public function testEmptyDatabase(): void $manager->persist($dummy); $manager->flush(); - $this->assertCount(1, $manager->getRepository(Dummy::class)->findAll()); + self::assertCount(1, $manager->getRepository(Dummy::class)->findAll()); $purger = new Purger($manager, PurgeMode::createDeleteMode()); $purger->purge(); - $this->assertCount(0, $manager->getRepository(Dummy::class)->findAll()); + self::assertCount(0, $manager->getRepository(Dummy::class)->findAll()); // Ensures the schema has been restored $dummy = new Dummy(); $dummy->id = '/dummy_'.uniqid(); $manager->persist($dummy); $manager->flush(); - $this->assertCount(1, $manager->getRepository(Dummy::class)->findAll()); + self::assertCount(1, $manager->getRepository(Dummy::class)->findAll()); } } diff --git a/tests/Bridge/Eloquent/Persister/ModelPersisterTest.php b/tests/Bridge/Eloquent/Persister/ModelPersisterTest.php index 907ec7d2..7a947dc6 100644 --- a/tests/Bridge/Eloquent/Persister/ModelPersisterTest.php +++ b/tests/Bridge/Eloquent/Persister/ModelPersisterTest.php @@ -49,12 +49,12 @@ public function tearDown(): void public function testIsAPersister(): void { - $this->assertTrue(is_a(ModelPersister::class, PersisterInterface::class, true)); + self::assertTrue(is_a(ModelPersister::class, PersisterInterface::class, true)); } public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(ModelPersister::class))->isCloneable()); + self::assertFalse((new ReflectionClass(ModelPersister::class))->isCloneable()); } public function testCanPersistAModel(): void @@ -62,15 +62,15 @@ public function testCanPersistAModel(): void $model = new AnotherDummy([ 'address' => 'Wonderlands', ]); - $this->assertNull($model->id); + self::assertNull($model->id); $this->persister->persist($model); - $this->assertNull($model->id); + self::assertNull($model->id); $this->persister->flush(); - $this->assertNotNull($model->id); + self::assertNotNull($model->id); - $this->assertEquals(1, AnotherDummy::all()->count()); + self::assertEquals(1, AnotherDummy::all()->count()); } public function testCanPersistAModelWithARelationship(): void @@ -86,13 +86,13 @@ public function testCanPersistAModelWithARelationship(): void $dummy->anotherDummy()->associate($anotherDummy); $this->persister->persist($dummy); - $this->assertNull($dummy->id); + self::assertNull($dummy->id); $this->persister->flush(); - $this->assertNotNull($dummy->id); + self::assertNotNull($dummy->id); - $this->assertEquals(1, Dummy::all()->count()); - $this->assertEquals(1, AnotherDummy::all()->count()); + self::assertEquals(1, Dummy::all()->count()); + self::assertEquals(1, AnotherDummy::all()->count()); } public function testCannotPersistANonModelObject(): void diff --git a/tests/Bridge/Eloquent/Purger/ModelPurgerTest.php b/tests/Bridge/Eloquent/Purger/ModelPurgerTest.php index 92fa15c4..cadfc54e 100644 --- a/tests/Bridge/Eloquent/Purger/ModelPurgerTest.php +++ b/tests/Bridge/Eloquent/Purger/ModelPurgerTest.php @@ -37,17 +37,17 @@ class ModelPurgerTest extends TestCase public function testIsAPurger(): void { - $this->assertTrue(is_a(ModelPurger::class, PurgerInterface::class, true)); + self::assertTrue(is_a(ModelPurger::class, PurgerInterface::class, true)); } public function testIsAPurgerFactory(): void { - $this->assertTrue(is_a(ModelPurger::class, PurgerFactoryInterface::class, true)); + self::assertTrue(is_a(ModelPurger::class, PurgerFactoryInterface::class, true)); } public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(ModelPurger::class))->isCloneable()); + self::assertFalse((new ReflectionClass(ModelPurger::class))->isCloneable()); } public function testRollbackAndRunMigrationsForPurgingTheDatabase(): void @@ -115,8 +115,8 @@ public function testCanCreateANewPurger(): void ]; foreach ($newPurgers as $newPurger) { - $this->assertEquals($newPurger, $purger); - $this->assertNotSame($newPurger, $purger); + self::assertEquals($newPurger, $purger); + self::assertNotSame($newPurger, $purger); } } @@ -136,7 +136,7 @@ public function testCannotCreateANewPurgerWithTruncateMode(): void $purger->create(PurgeMode::createTruncateMode()); $this->fail('Expected exception to be thrown.'); } catch (InvalidArgumentException $exception) { - $this->assertEquals($expectedExceptionMessage, $exception->getMessage()); + self::assertEquals($expectedExceptionMessage, $exception->getMessage()); } try { @@ -146,7 +146,7 @@ public function testCannotCreateANewPurgerWithTruncateMode(): void ); $this->fail('Expected exception to be thrown.'); } catch (InvalidArgumentException $exception) { - $this->assertEquals($expectedExceptionMessage, $exception->getMessage()); + self::assertEquals($expectedExceptionMessage, $exception->getMessage()); } } @@ -163,17 +163,17 @@ public function testEmptyDatabase(): void AnotherDummy::create([ 'address' => 'Wonderlands', ]); - $this->assertEquals(1, AnotherDummy::all()->count()); + self::assertEquals(1, AnotherDummy::all()->count()); $purger = new ModelPurger($GLOBALS['repository'], 'migrations', $GLOBALS['migrator']); $purger->purge(); - $this->assertEquals(0, AnotherDummy::all()->count()); + self::assertEquals(0, AnotherDummy::all()->count()); // Ensures the schema has been restored AnotherDummy::create([ 'address' => 'Wonderlands' ]); - $this->assertEquals(1, AnotherDummy::all()->count()); + self::assertEquals(1, AnotherDummy::all()->count()); } } diff --git a/tests/Bridge/Symfony/DependencyInjection/ConfigurationTest.php b/tests/Bridge/Symfony/DependencyInjection/ConfigurationTest.php index e0f742c9..e5c412a6 100644 --- a/tests/Bridge/Symfony/DependencyInjection/ConfigurationTest.php +++ b/tests/Bridge/Symfony/DependencyInjection/ConfigurationTest.php @@ -38,7 +38,7 @@ public function testDefaultValues(): void $actual = $processor->processConfiguration($configuration, []); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); } public function testDefaultValuesCanBeOverridden(): void @@ -71,6 +71,6 @@ public function testDefaultValuesCanBeOverridden(): void ] ); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); } } diff --git a/tests/Bridge/Symfony/Doctrine/FidryAliceDataFixturesBundleTest.php b/tests/Bridge/Symfony/Doctrine/FidryAliceDataFixturesBundleTest.php index a36e7566..da2403b7 100644 --- a/tests/Bridge/Symfony/Doctrine/FidryAliceDataFixturesBundleTest.php +++ b/tests/Bridge/Symfony/Doctrine/FidryAliceDataFixturesBundleTest.php @@ -39,22 +39,22 @@ public function testServiceRegistration(): void { parent::testServiceRegistration(); - $this->assertServiceIsInstanceOf( + self::assertServiceIsInstanceOf( Purger::class, 'fidry_alice_data_fixtures.persistence.purger.doctrine.orm_purger' ); - $this->assertServiceIsInstanceOf( + self::assertServiceIsInstanceOf( ObjectManagerPersister::class, 'fidry_alice_data_fixtures.persistence.persister.doctrine.object_manager_persister' ); - $this->assertServiceIsInstanceOf( + self::assertServiceIsInstanceOf( PersisterLoader::class, 'fidry_alice_data_fixtures.doctrine.persister_loader' ); - $this->assertServiceIsInstanceOf( + self::assertServiceIsInstanceOf( PurgerLoader::class, 'fidry_alice_data_fixtures.doctrine.purger_loader' ); diff --git a/tests/Bridge/Symfony/Doctrine/MongodbLoaderIntegrationTest.php b/tests/Bridge/Symfony/Doctrine/MongodbLoaderIntegrationTest.php index 15a63080..84bb6c97 100644 --- a/tests/Bridge/Symfony/Doctrine/MongodbLoaderIntegrationTest.php +++ b/tests/Bridge/Symfony/Doctrine/MongodbLoaderIntegrationTest.php @@ -69,7 +69,7 @@ public function testLoadAFile(): void $result = $this->doctrine->getRepository(Dummy::class)->findAll(); - $this->assertCount(1, $result); + self::assertCount(1, $result); } public function testLoadAFileWithPurger(): void @@ -87,6 +87,6 @@ public function testLoadAFileWithPurger(): void $result = $this->doctrine->getRepository(Dummy::class)->findAll(); - $this->assertCount(1, $result); + self::assertCount(1, $result); } } diff --git a/tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php b/tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php index e1e8b5f7..df3d5914 100644 --- a/tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php +++ b/tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php @@ -72,7 +72,7 @@ public function testLoadAFile(): void $result = $this->doctrine->getRepository(Dummy::class)->findAll(); - $this->assertCount(1, $result); + self::assertCount(1, $result); } public function testLoadAFileWithPurger(): void @@ -97,7 +97,7 @@ public function testLoadAFileWithPurger(): void $result = $this->doctrine->getRepository(Dummy::class)->findAll(); - $this->assertCount(1, $result); + self::assertCount(1, $result); } public function testBidirectionalRelationships(): void @@ -109,8 +109,8 @@ public function testBidirectionalRelationships(): void $users = $this->doctrine->getRepository(User::class)->findAll(); $groups = $this->doctrine->getRepository(Group::class)->findAll(); - $this->assertCount(5, $users); - $this->assertCount(5, $groups); + self::assertCount(5, $users); + self::assertCount(5, $groups); } public function testBidirectionalRelationshipsDeclaredInDifferentFiles(): void @@ -123,8 +123,8 @@ public function testBidirectionalRelationshipsDeclaredInDifferentFiles(): void $users = $this->doctrine->getRepository(User::class)->findAll(); $groups = $this->doctrine->getRepository(Group::class)->findAll(); - $this->assertCount(5, $users); - $this->assertCount(5, $groups); + self::assertCount(5, $users); + self::assertCount(5, $groups); } public function testBidirectionalRelationshipsDeclaredInDifferentFilesWithCyclingDependence(): void @@ -137,7 +137,7 @@ public function testBidirectionalRelationshipsDeclaredInDifferentFilesWithCyclin $users = $this->doctrine->getRepository(User::class)->findAll(); $groups = $this->doctrine->getRepository(Group::class)->findAll(); - $this->assertCount(5, $users); - $this->assertCount(5, $groups); + self::assertCount(5, $users); + self::assertCount(5, $groups); } } diff --git a/tests/Bridge/Symfony/Doctrine/PhpcrLoaderIntegrationTest.php b/tests/Bridge/Symfony/Doctrine/PhpcrLoaderIntegrationTest.php index 12ad663f..99be2646 100644 --- a/tests/Bridge/Symfony/Doctrine/PhpcrLoaderIntegrationTest.php +++ b/tests/Bridge/Symfony/Doctrine/PhpcrLoaderIntegrationTest.php @@ -67,7 +67,7 @@ public function testLoadAFile(): void $result = $this->doctrine->getRepository(Dummy::class)->findAll(); - $this->assertCount(1, $result); + self::assertCount(1, $result); } public function testLoadAFileWithPurger(): void @@ -86,6 +86,6 @@ public function testLoadAFileWithPurger(): void $result = $this->doctrine->getRepository(Dummy::class)->findAll(); - $this->assertCount(1, $result); + self::assertCount(1, $result); } } diff --git a/tests/Bridge/Symfony/Eloquent/FidryAliceDataFixturesBundleTest.php b/tests/Bridge/Symfony/Eloquent/FidryAliceDataFixturesBundleTest.php index 9d544ee2..cfc85c07 100644 --- a/tests/Bridge/Symfony/Eloquent/FidryAliceDataFixturesBundleTest.php +++ b/tests/Bridge/Symfony/Eloquent/FidryAliceDataFixturesBundleTest.php @@ -42,22 +42,22 @@ public function testServiceRegistration(): void { parent::testServiceRegistration(); - $this->assertServiceIsInstanceOf( + self::assertServiceIsInstanceOf( ModelPurger::class, 'fidry_alice_data_fixtures.persistence.purger.eloquent.model_purger' ); - $this->assertServiceIsInstanceOf( + self::assertServiceIsInstanceOf( ModelPersister::class, 'fidry_alice_data_fixtures.persistence.persister.eloquent.model_persister' ); - $this->assertServiceIsInstanceOf( + self::assertServiceIsInstanceOf( PersisterLoader::class, 'fidry_alice_data_fixtures.eloquent.persister_loader' ); - $this->assertServiceIsInstanceOf( + self::assertServiceIsInstanceOf( PurgerLoader::class, 'fidry_alice_data_fixtures.eloquent.purger_loader' ); diff --git a/tests/Bridge/Symfony/Eloquent/ORMLoaderIntegrationTest.php b/tests/Bridge/Symfony/Eloquent/ORMLoaderIntegrationTest.php index 88922142..4cbb698c 100644 --- a/tests/Bridge/Symfony/Eloquent/ORMLoaderIntegrationTest.php +++ b/tests/Bridge/Symfony/Eloquent/ORMLoaderIntegrationTest.php @@ -76,7 +76,7 @@ public function testLoadAFile(): void __DIR__.'/../../../../fixtures/fixture_files/eloquent_another_dummy.yml', ]); - $this->assertEquals(1, AnotherDummy::all()->count()); + self::assertEquals(1, AnotherDummy::all()->count()); } public function testLoadAFileWithPurger(): void @@ -90,7 +90,7 @@ public function testLoadAFileWithPurger(): void __DIR__.'/../../../../fixtures/fixture_files/eloquent_another_dummy.yml', ]); - $this->assertEquals(1, AnotherDummy::all()->count()); + self::assertEquals(1, AnotherDummy::all()->count()); } public function testBidirectionalRelationships(): void @@ -99,8 +99,8 @@ public function testBidirectionalRelationships(): void __DIR__.'/../../../../fixtures/fixture_files/eloquent_relationship_dummies.yml', ]); - $this->assertEquals(10, Dummy::all()->count()); - $this->assertEquals(10, AnotherDummy::all()->count()); + self::assertEquals(10, Dummy::all()->count()); + self::assertEquals(10, AnotherDummy::all()->count()); } public function testBidirectionalRelationshipsDeclaredInDifferentFiles(): void @@ -110,8 +110,8 @@ public function testBidirectionalRelationshipsDeclaredInDifferentFiles(): void __DIR__.'/../../../../fixtures/fixture_files/eloquent_dummies.yml', ]); - $this->assertEquals(10, Dummy::all()->count()); - $this->assertEquals(1, AnotherDummy::all()->count()); + self::assertEquals(10, Dummy::all()->count()); + self::assertEquals(1, AnotherDummy::all()->count()); } private function execute(array $input): void diff --git a/tests/Bridge/Symfony/FidryAliceDataFixturesBundleTest.php b/tests/Bridge/Symfony/FidryAliceDataFixturesBundleTest.php index 3a1912a9..d857c8e9 100644 --- a/tests/Bridge/Symfony/FidryAliceDataFixturesBundleTest.php +++ b/tests/Bridge/Symfony/FidryAliceDataFixturesBundleTest.php @@ -51,12 +51,12 @@ public function tearDown(): void */ public function testServiceRegistration(): void { - $this->assertServiceIsInstanceOf( + self::assertServiceIsInstanceOf( MultiPassLoader::class, 'fidry_alice_data_fixtures.loader.multipass_file' ); - $this->assertServiceIsInstanceOf( + self::assertServiceIsInstanceOf( SimpleLoader::class, 'fidry_alice_data_fixtures.loader.simple' ); @@ -74,7 +74,7 @@ public function testCannotBootIfNelmioAliceBundleIsNotRegistered(): void final protected function assertServiceIsInstanceOf(string $serviceClass, string $serviceId): void { - $this->assertInstanceOf( + self::assertInstanceOf( $serviceClass, $this->kernel->getContainer()->get($serviceId) ); diff --git a/tests/Bridge/Symfony/ProxyManager/Doctrine/FidryAliceDataFixturesBundleTest.php b/tests/Bridge/Symfony/ProxyManager/Doctrine/FidryAliceDataFixturesBundleTest.php index b68bbc22..9fb4b81e 100644 --- a/tests/Bridge/Symfony/ProxyManager/Doctrine/FidryAliceDataFixturesBundleTest.php +++ b/tests/Bridge/Symfony/ProxyManager/Doctrine/FidryAliceDataFixturesBundleTest.php @@ -42,22 +42,22 @@ public function testServiceRegistration(): void { parent::testServiceRegistration(); - $this->assertInstanceOf( + self::assertInstanceOf( Purger::class, $this->kernel->getContainer()->get('fidry_alice_data_fixtures.persistence.purger.doctrine.orm_purger') ); - $this->assertInstanceOf( + self::assertInstanceOf( ObjectManagerPersister::class, $this->kernel->getContainer()->get('fidry_alice_data_fixtures.persistence.persister.doctrine.object_manager_persister') ); - $this->assertInstanceOf( + self::assertInstanceOf( PersisterLoader::class, $this->kernel->getContainer()->get('fidry_alice_data_fixtures.doctrine.persister_loader') ); - $this->assertInstanceOf( + self::assertInstanceOf( PurgerLoader::class, $this->kernel->getContainer()->get('fidry_alice_data_fixtures.doctrine.purger_loader') ); diff --git a/tests/Bridge/Symfony/ProxyManager/Eloquent/FidryAliceDataFixturesBundleTest.php b/tests/Bridge/Symfony/ProxyManager/Eloquent/FidryAliceDataFixturesBundleTest.php index d7f4dd7d..2ef6bb19 100644 --- a/tests/Bridge/Symfony/ProxyManager/Eloquent/FidryAliceDataFixturesBundleTest.php +++ b/tests/Bridge/Symfony/ProxyManager/Eloquent/FidryAliceDataFixturesBundleTest.php @@ -42,22 +42,22 @@ public function testServiceRegistration(): void { parent::testServiceRegistration(); - $this->assertInstanceOf( + self::assertInstanceOf( ModelPurger::class, $this->kernel->getContainer()->get('fidry_alice_data_fixtures.persistence.purger.eloquent.model_purger') ); - $this->assertInstanceOf( + self::assertInstanceOf( ModelPersister::class, $this->kernel->getContainer()->get('fidry_alice_data_fixtures.persistence.persister.eloquent.model_persister') ); - $this->assertInstanceOf( + self::assertInstanceOf( PersisterLoader::class, $this->kernel->getContainer()->get('fidry_alice_data_fixtures.eloquent.persister_loader') ); - $this->assertInstanceOf( + self::assertInstanceOf( PurgerLoader::class, $this->kernel->getContainer()->get('fidry_alice_data_fixtures.eloquent.purger_loader') ); diff --git a/tests/Exception/MaxPassReachedExceptionTest.php b/tests/Exception/MaxPassReachedExceptionTest.php index 37409cf2..63b6e5f9 100644 --- a/tests/Exception/MaxPassReachedExceptionTest.php +++ b/tests/Exception/MaxPassReachedExceptionTest.php @@ -27,21 +27,21 @@ class MaxPassReachedExceptionTest extends TestCase { public function testIsARuntimeException(): void { - $this->assertTrue(is_a(MaxPassReachedException::class, RuntimeException::class, true)); + self::assertTrue(is_a(MaxPassReachedException::class, RuntimeException::class, true)); } public function testIsALoadingException(): void { - $this->assertTrue(is_a(MaxPassReachedException::class, LoadingThrowable::class, true)); + self::assertTrue(is_a(MaxPassReachedException::class, LoadingThrowable::class, true)); } public function testInstantiation(): void { $exception = new MaxPassReachedException('foo'); - $this->assertEquals('foo', $exception->getMessage()); - $this->assertEquals(0, $exception->getCode()); - $this->assertNull($exception->getPrevious()); - $this->assertCount(0, $exception->getStack()); + self::assertEquals('foo', $exception->getMessage()); + self::assertEquals(0, $exception->getCode()); + self::assertNull($exception->getPrevious()); + self::assertCount(0, $exception->getStack()); $code = 100; @@ -50,9 +50,9 @@ public function testInstantiation(): void $tracker->register('/foo.php', new Exception('bar')); $exception = new MaxPassReachedException('foo', $code, $previous, $tracker); - $this->assertEquals('foo', $exception->getMessage()); - $this->assertEquals($code, $exception->getCode()); - $this->assertSame($previous, $exception->getPrevious()); - $this->assertEquals($tracker->getStack(), $exception->getStack()); + self::assertEquals('foo', $exception->getMessage()); + self::assertEquals($code, $exception->getCode()); + self::assertSame($previous, $exception->getPrevious()); + self::assertEquals($tracker->getStack(), $exception->getStack()); } } diff --git a/tests/Loader/ErrorTrackerTest.php b/tests/Loader/ErrorTrackerTest.php index d6e57304..20188991 100644 --- a/tests/Loader/ErrorTrackerTest.php +++ b/tests/Loader/ErrorTrackerTest.php @@ -25,7 +25,7 @@ public function testCanGetStackOfATrackerEvenIfNoErrorHasBeenRegistered(): void { $tracker = new ErrorTracker(); - $this->assertSame([], $tracker->getStack()); + self::assertSame([], $tracker->getStack()); } public function testKeepsTrackOfErrors(): void @@ -35,7 +35,7 @@ public function testKeepsTrackOfErrors(): void $tracker->register('bar', $exception1 = new Exception('bar exception 0')); $tracker->register('bar', $exception2 = new Exception('bar exception 1')); - $this->assertEquals( + self::assertEquals( [ 'foo' => [ $exception0, @@ -60,7 +60,7 @@ public function testIsDeepClonable(): void $newTracker = clone $tracker; $newTracker->register('bar', new Exception('bar exception')); - $this->assertEquals($originalTracker->getStack(), $tracker->getStack()); - $this->assertNotEquals($tracker->getStack(), $newTracker->getStack()); + self::assertEquals($originalTracker->getStack(), $tracker->getStack()); + self::assertNotEquals($tracker->getStack(), $newTracker->getStack()); } } diff --git a/tests/Loader/FileResolverLoaderTest.php b/tests/Loader/FileResolverLoaderTest.php index b9fe6971..40530889 100644 --- a/tests/Loader/FileResolverLoaderTest.php +++ b/tests/Loader/FileResolverLoaderTest.php @@ -31,12 +31,12 @@ class FileResolverLoaderTest extends TestCase public function testIsALoader(): void { - $this->assertTrue(is_a(FileResolverLoader::class, LoaderInterface::class, true)); + self::assertTrue(is_a(FileResolverLoader::class, LoaderInterface::class, true)); } public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(FileResolverLoader::class))->isCloneable()); + self::assertFalse((new ReflectionClass(FileResolverLoader::class))->isCloneable()); } public function testResolvesTheFilesBeforePassingThemToTheDecoratedLoader(): void @@ -70,7 +70,7 @@ public function testResolvesTheFilesBeforePassingThemToTheDecoratedLoader(): voi $loader = new FileResolverLoader($loader, $fileResolver); $result = $loader->load($files); - $this->assertEquals( + self::assertEquals( [ 'dummy' => new stdClass(), ], @@ -108,7 +108,7 @@ public function testParametersAndObjectsInjectedArePassedToTheDecoratedLoader(): $loader = new FileResolverLoader($loader, new DummyResolver()); $result = $loader->load($files, $parameters, $objects); - $this->assertEquals( + self::assertEquals( [ 'dummy' => new stdClass(), ], diff --git a/tests/Loader/FileTrackerTest.php b/tests/Loader/FileTrackerTest.php index 7f0d8433..076c3535 100644 --- a/tests/Loader/FileTrackerTest.php +++ b/tests/Loader/FileTrackerTest.php @@ -25,7 +25,7 @@ public function testReturnsAllUnloadedFiles(): void { $tracker = new FileTracker('foo'); - $this->assertSame(['foo'], $tracker->getUnloadedFiles()); + self::assertSame(['foo'], $tracker->getUnloadedFiles()); } public function testCanMarkFilesAsLoaded(): void @@ -33,7 +33,7 @@ public function testCanMarkFilesAsLoaded(): void $tracker = new FileTracker('foo'); $tracker->markAsLoaded('foo'); - $this->assertSame([], $tracker->getUnloadedFiles()); + self::assertSame([], $tracker->getUnloadedFiles()); } public function testCannotMarkUntrackedFileAsLoaded(): void @@ -48,13 +48,13 @@ public function testCannotMarkUntrackedFileAsLoaded(): void public function testCanTellWhenAllFilesHaveBeenLoaded(): void { $tracker = new FileTracker('foo', 'bar'); - $this->assertFalse($tracker->allFilesHaveBeenLoaded()); + self::assertFalse($tracker->allFilesHaveBeenLoaded()); $tracker->markAsLoaded('foo'); - $this->assertFalse($tracker->allFilesHaveBeenLoaded()); + self::assertFalse($tracker->allFilesHaveBeenLoaded()); $tracker->markAsLoaded('bar'); - $this->assertTrue($tracker->allFilesHaveBeenLoaded()); + self::assertTrue($tracker->allFilesHaveBeenLoaded()); } public function testIsDeepClonable(): void @@ -64,7 +64,7 @@ public function testIsDeepClonable(): void $clone->markAsLoaded('foo'); - $this->assertFalse($tracker->allFilesHaveBeenLoaded()); - $this->assertTrue($clone->allFilesHaveBeenLoaded()); + self::assertFalse($tracker->allFilesHaveBeenLoaded()); + self::assertTrue($clone->allFilesHaveBeenLoaded()); } } diff --git a/tests/Loader/MultiPassFileLoaderTest.php b/tests/Loader/MultiPassFileLoaderTest.php index d5ae6401..cbaa30f8 100644 --- a/tests/Loader/MultiPassFileLoaderTest.php +++ b/tests/Loader/MultiPassFileLoaderTest.php @@ -42,12 +42,12 @@ class MultiPassFileLoaderTest extends TestCase public function testIsALoader(): void { - $this->assertTrue(is_a(MultiPassLoader::class, LoaderInterface::class, true)); + self::assertTrue(is_a(MultiPassLoader::class, LoaderInterface::class, true)); } public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(MultiPassLoader::class))->isCloneable()); + self::assertFalse((new ReflectionClass(MultiPassLoader::class))->isCloneable()); } /** @@ -66,10 +66,10 @@ public function testMaxPassGivenMustBeAStrictlyPositiveInteger(int $maxPass, str $this->fail('Did not except exception to be thrown.'); } - $this->assertEquals($expectedExceptionMessage, $exception->getMessage()); + self::assertEquals($expectedExceptionMessage, $exception->getMessage()); } - $this->assertTrue(true, 'Everything is fine.'); + self::assertTrue(true, 'Everything is fine.'); } public function testReturnsAnEmptySetIfNoFileGiven(): void @@ -79,7 +79,7 @@ public function testReturnsAnEmptySetIfNoFileGiven(): void $loader = new MultiPassLoader(new FakeFileLoader()); $actual = $loader->load([]); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); } public function testReturnsInjectedObjectsAndObjectsIfNoFileGiven(): void @@ -90,7 +90,7 @@ public function testReturnsInjectedObjectsAndObjectsIfNoFileGiven(): void $loader = new MultiPassLoader(new FakeFileLoader()); $actual = $loader->load([], $parameters, $objects); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); } public function testDecoratesTheFileLoaderToReturnTheObjectsLoaded(): void @@ -112,7 +112,7 @@ public function testDecoratesTheFileLoaderToReturnTheObjectsLoaded(): void $loader = new MultiPassLoader($fileLoader); $actual = $loader->load($files); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); $fileLoaderProphecy->loadFile(Argument::cetera())->shouldHaveBeenCalledTimes(1); } @@ -224,7 +224,7 @@ public function testLoadedFilesInSeveralPassesUntilAllFilesAreLoaded(): void $loader = new MultiPassLoader($fileLoader); $actual = $loader->load($files, $parameters, $objects); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); $fileLoaderProphecy->loadFile(Argument::cetera())->shouldHaveBeenCalledTimes(5); } @@ -263,7 +263,7 @@ public function testIfFilesCannotBeReloadedTheLoadingStopsWhenTheLimitIsReached( $loader->load($files); $this->fail('Expected exception to be thrown.'); } catch (MaxPassReachedException $exception) { - $this->assertStringContainsString( + self::assertStringContainsString( <<assertTrue(is_a(PersisterLoader::class, LoaderInterface::class, true)); + self::assertTrue(is_a(PersisterLoader::class, LoaderInterface::class, true)); } public function testIsPersisterAware(): void { - $this->assertTrue(is_a(PersisterLoader::class, PersisterAwareInterface::class, true)); + self::assertTrue(is_a(PersisterLoader::class, PersisterAwareInterface::class, true)); } public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(PersisterLoader::class))->isCloneable()); + self::assertFalse((new ReflectionClass(PersisterLoader::class))->isCloneable()); } public function testNamedConstructorIsImmutable(): void @@ -54,11 +54,11 @@ public function testNamedConstructorIsImmutable(): void $loader = new PersisterLoader(new FakeLoader(), new FakePersister(), null, []); $newLoader = $loader->withPersister($persister); - $this->assertEquals( + self::assertEquals( new PersisterLoader(new FakeLoader(), new FakePersister(), null, []), $loader ); - $this->assertEquals( + self::assertEquals( new PersisterLoader(new FakeLoader(), $persister, null, []), $newLoader ); @@ -103,7 +103,7 @@ public function testDecoratesALoaderAndProcessAndPersistEachLoadedObjectBeforeRe $loader = new PersisterLoader($loader, $persister, null, [$firstProcessor, $secondProcessor]); $result = $loader->load($files); - $this->assertEquals( + self::assertEquals( [ 'dummy' => new stdClass(), ], @@ -150,7 +150,7 @@ public function testParametersAndObjectsInjectedArePassedToTheDecoratedLoader(): $loader = new PersisterLoader($loader, $persister, null, []); $result = $loader->load($files, $parameters, $objects); - $this->assertEquals( + self::assertEquals( [ 'dummy' => new stdClass(), ], diff --git a/tests/Loader/ProcessorIndexTest.php b/tests/Loader/ProcessorIndexTest.php index 8b522f93..2d1276f4 100644 --- a/tests/Loader/ProcessorIndexTest.php +++ b/tests/Loader/ProcessorIndexTest.php @@ -37,8 +37,8 @@ public function testIndexesArePreserved(): void $loader->load([__DIR__.'/../../fixtures/fixture_files/dummy.yml']); - $this->assertSame(['dummy0'], $processor->preIds); - $this->assertSame(['dummy0'], $processor->postIds); + self::assertSame(['dummy0'], $processor->preIds); + self::assertSame(['dummy0'], $processor->postIds); } } diff --git a/tests/Loader/PurgerLoaderTest.php b/tests/Loader/PurgerLoaderTest.php index 1c81c124..f6994c2a 100644 --- a/tests/Loader/PurgerLoaderTest.php +++ b/tests/Loader/PurgerLoaderTest.php @@ -34,12 +34,12 @@ class PurgerLoaderTest extends TestCase public function testIsALoader(): void { - $this->assertTrue(is_a(PurgerLoader::class, LoaderInterface::class, true)); + self::assertTrue(is_a(PurgerLoader::class, LoaderInterface::class, true)); } public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(PurgerLoader::class))->isCloneable()); + self::assertFalse((new ReflectionClass(PurgerLoader::class))->isCloneable()); } public function testPurgesTheDatabaseBeforeLoadingTheFixturesAndReturningTheResult(): void @@ -77,7 +77,7 @@ public function testPurgesTheDatabaseBeforeLoadingTheFixturesAndReturningTheResu $loader = new PurgerLoader($decoratedLoader, $purgerFactory, 'delete', null); $actual = $loader->load($files, $parameters, $objects, $purgeMode); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); $decoratedLoaderProphecy->load(Argument::cetera())->shouldHaveBeenCalledTimes(1); $purgerFactoryProphecy->create(Argument::cetera())->shouldHaveBeenCalledTimes(1); @@ -119,7 +119,7 @@ public function testIfNoPurgeModeIsGivenThenUseDefaultPurgeModeWithDelete(): voi $loader = new PurgerLoader($decoratedLoader, $purgerFactory, 'delete'); $actual = $loader->load($files, $parameters, $objects, $purgeMode); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); $decoratedLoaderProphecy->load(Argument::cetera())->shouldHaveBeenCalledTimes(1); $purgerFactoryProphecy->create(Argument::cetera())->shouldHaveBeenCalledTimes(1); @@ -161,7 +161,7 @@ public function testIfNoPurgeModeIsGivenThenUseDefaultPurgeModeWithTruncate(): v $loader = new PurgerLoader($decoratedLoader, $purgerFactory, 'truncate'); $actual = $loader->load($files, $parameters, $objects, $purgeMode); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); $decoratedLoaderProphecy->load(Argument::cetera())->shouldHaveBeenCalledTimes(1); $purgerFactoryProphecy->create(Argument::cetera())->shouldHaveBeenCalledTimes(1); @@ -203,7 +203,7 @@ public function testIfNoPurgeModeIsGivenThenUseDefaultPurgeModeWithNoPurge(): vo $loader = new PurgerLoader($decoratedLoader, $purgerFactory, 'no_purge'); $actual = $loader->load($files, $parameters, $objects, $purgeMode); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); $decoratedLoaderProphecy->load(Argument::cetera())->shouldHaveBeenCalledTimes(1); $purgerFactoryProphecy->create(Argument::cetera())->shouldNotBeenCalled(); @@ -240,7 +240,7 @@ public function testDoesNotPurgeOnNoPurgeModeGiven(): void $loader = new PurgerLoader($decoratedLoader, $purgerFactory, 'delete'); $actual = $loader->load($files, $parameters, $objects, $purgeMode); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); $decoratedLoaderProphecy->load(Argument::cetera())->shouldHaveBeenCalledTimes(1); } diff --git a/tests/Loader/SimpleLoaderTest.php b/tests/Loader/SimpleLoaderTest.php index c730586e..8ff741ac 100644 --- a/tests/Loader/SimpleLoaderTest.php +++ b/tests/Loader/SimpleLoaderTest.php @@ -33,12 +33,12 @@ class SimpleLoaderTest extends TestCase public function testIsALoader(): void { - $this->assertTrue(is_a(SimpleLoader::class, LoaderInterface::class, true)); + self::assertTrue(is_a(SimpleLoader::class, LoaderInterface::class, true)); } public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(SimpleLoader::class))->isCloneable()); + self::assertFalse((new ReflectionClass(SimpleLoader::class))->isCloneable()); } public function testDecoratesAliceLoaderToLoadEachFileGivenAndReturnsTheObjectsLoaded(): void @@ -65,7 +65,7 @@ public function testDecoratesAliceLoaderToLoadEachFileGivenAndReturnsTheObjectsL $loader = new SimpleLoader($filesLoader); $result = $loader->load($files); - $this->assertEquals( + self::assertEquals( [ 'dummy' => new stdClass(), ], diff --git a/tests/Persistence/Persister/NullPersisterTest.php b/tests/Persistence/Persister/NullPersisterTest.php index cef9637c..c77dec8c 100644 --- a/tests/Persistence/Persister/NullPersisterTest.php +++ b/tests/Persistence/Persister/NullPersisterTest.php @@ -24,11 +24,11 @@ class NullPersisterTest extends TestCase { public function testIsAPersister(): void { - $this->assertTrue(is_a(NullPersister::class, PersisterInterface::class, true)); + self::assertTrue(is_a(NullPersister::class, PersisterInterface::class, true)); } public function testIsNotClonable(): void { - $this->assertFalse((new ReflectionClass(NullPersister::class))->isCloneable()); + self::assertFalse((new ReflectionClass(NullPersister::class))->isCloneable()); } } diff --git a/tests/Persistence/PurgeModeTest.php b/tests/Persistence/PurgeModeTest.php index ec288dbc..43084e07 100644 --- a/tests/Persistence/PurgeModeTest.php +++ b/tests/Persistence/PurgeModeTest.php @@ -32,18 +32,18 @@ public function testThrowsAnExceptionIfUnknownPurgeModeIsGiven(): void public function testCanCreateDeleteMode(): void { $mode = PurgeMode::createDeleteMode(); - $this->assertEquals(1, $mode->getValue()); + self::assertEquals(1, $mode->getValue()); $mode = new PurgeMode(1); - $this->assertEquals(1, $mode->getValue()); + self::assertEquals(1, $mode->getValue()); } public function testCanCreateTruncateMode(): void { $mode = PurgeMode::createTruncateMode(); - $this->assertEquals(2, $mode->getValue()); + self::assertEquals(2, $mode->getValue()); $mode = new PurgeMode(2); - $this->assertEquals(2, $mode->getValue()); + self::assertEquals(2, $mode->getValue()); } } From 2bb48e766303c221644470144ba7228224e0accf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 19 Dec 2021 18:32:54 +0100 Subject: [PATCH 09/11] Remove unnecessary usages of @inheritdoc --- fixtures/Bridge/Eloquent/Model/AnotherDummy.php | 13 ++----------- .../Symfony/SymfonyApp/Bundle/DoctrineBundle.php | 2 +- .../Bundle/DoctrineConnectionlessPass.php | 5 +---- .../Bridge/Symfony/SymfonyApp/IsolatedKernel.php | 2 +- src/Bridge/Symfony/FidryAliceDataFixturesBundle.php | 3 --- .../Persister/ObjectManagerPersisterTest.php | 2 +- .../Symfony/Doctrine/ORMLoaderIntegrationTest.php | 3 --- tests/Loader/ProcessorIndexTest.php | 6 ------ 8 files changed, 6 insertions(+), 30 deletions(-) diff --git a/fixtures/Bridge/Eloquent/Model/AnotherDummy.php b/fixtures/Bridge/Eloquent/Model/AnotherDummy.php index 822d6218..3fed649b 100644 --- a/fixtures/Bridge/Eloquent/Model/AnotherDummy.php +++ b/fixtures/Bridge/Eloquent/Model/AnotherDummy.php @@ -18,24 +18,15 @@ class AnotherDummy extends Model { - /** - * @inheritdoc - */ protected $table = 'another_dummies'; - /** - * @inheritdoc - */ - protected $fillable = [ + protected array $fillable = [ 'id', 'address', 'dummy', ]; - /** - * @inheritdoc - */ - public $timestamps = false; + public bool $timestamps = false; public function dummy(): BelongsTo { diff --git a/fixtures/Bridge/Symfony/SymfonyApp/Bundle/DoctrineBundle.php b/fixtures/Bridge/Symfony/SymfonyApp/Bundle/DoctrineBundle.php index d804b967..a27793af 100644 --- a/fixtures/Bridge/Symfony/SymfonyApp/Bundle/DoctrineBundle.php +++ b/fixtures/Bridge/Symfony/SymfonyApp/Bundle/DoctrineBundle.php @@ -18,7 +18,7 @@ class DoctrineBundle extends Bundle { - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { parent::build($container); diff --git a/fixtures/Bridge/Symfony/SymfonyApp/Bundle/DoctrineConnectionlessPass.php b/fixtures/Bridge/Symfony/SymfonyApp/Bundle/DoctrineConnectionlessPass.php index dcedaef7..5916d7fd 100644 --- a/fixtures/Bridge/Symfony/SymfonyApp/Bundle/DoctrineConnectionlessPass.php +++ b/fixtures/Bridge/Symfony/SymfonyApp/Bundle/DoctrineConnectionlessPass.php @@ -19,10 +19,7 @@ class DoctrineConnectionlessPass implements CompilerPassInterface { - /** - * @inheritdoc - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { try { $proxyCacheWarmerDefinition = $container->findDefinition('doctrine.orm.proxy_cache_warmer'); diff --git a/fixtures/Bridge/Symfony/SymfonyApp/IsolatedKernel.php b/fixtures/Bridge/Symfony/SymfonyApp/IsolatedKernel.php index 6c71c388..e0b023aa 100644 --- a/fixtures/Bridge/Symfony/SymfonyApp/IsolatedKernel.php +++ b/fixtures/Bridge/Symfony/SymfonyApp/IsolatedKernel.php @@ -34,7 +34,7 @@ public function build(ContainerBuilder $container): void { $container->addCompilerPass( new class() implements CompilerPassInterface { - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { foreach ($container->getDefinitions() as $id => $definition) { if (!str_starts_with($id, 'fidry_alice_data_fixtures')) { diff --git a/src/Bridge/Symfony/FidryAliceDataFixturesBundle.php b/src/Bridge/Symfony/FidryAliceDataFixturesBundle.php index 3fb168d8..3cd19ec3 100644 --- a/src/Bridge/Symfony/FidryAliceDataFixturesBundle.php +++ b/src/Bridge/Symfony/FidryAliceDataFixturesBundle.php @@ -20,9 +20,6 @@ final class FidryAliceDataFixturesBundle extends Bundle { - /** - * @inheritdoc - */ public function build(ContainerBuilder $container): void { parent::build($container); diff --git a/tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php b/tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php index ed341539..26a7e8b5 100644 --- a/tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php +++ b/tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php @@ -238,7 +238,7 @@ public static function provideEntities(): iterable ]; yield 'entity with explicit ID' => [ - (function () { + (static function () { $dummy = new DummyWithIdentifier(); $dummy->id = 300; diff --git a/tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php b/tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php index df3d5914..2677aaf4 100644 --- a/tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php +++ b/tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php @@ -36,9 +36,6 @@ class ORMLoaderIntegrationTest extends TestCase private static string $seed; - /** - * @inheritdoc - */ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); diff --git a/tests/Loader/ProcessorIndexTest.php b/tests/Loader/ProcessorIndexTest.php index 2d1276f4..59f58807 100644 --- a/tests/Loader/ProcessorIndexTest.php +++ b/tests/Loader/ProcessorIndexTest.php @@ -47,17 +47,11 @@ class DummyProcessor implements ProcessorInterface public array $preIds = []; public array $postIds = []; - /** - * @inheritdoc - */ public function preProcess(string $id, object $object): void { $this->preIds[] = $id; } - /** - * @inheritdoc - */ public function postProcess(string $id, object $object): void { $this->postIds[] = $id; From 39a588ade6f3d9269c7c4ec8fe88d8e8f83cda1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 19 Dec 2021 18:35:44 +0100 Subject: [PATCH 10/11] Use bin2hex in favour of uniqid --- bin/console | 2 +- fixtures/Bridge/Symfony/SymfonyApp/IsolatedKernel.php | 4 +++- .../DoctrinePhpCr/Persister/ObjectManagerPersisterTest.php | 6 ++++-- tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php | 6 ++++-- .../Symfony/Doctrine/MongodbLoaderIntegrationTest.php | 4 +++- tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php | 4 +++- .../Bridge/Symfony/Doctrine/PhpcrLoaderIntegrationTest.php | 6 ++++-- tests/Bridge/Symfony/Eloquent/ORMLoaderIntegrationTest.php | 4 +++- 8 files changed, 25 insertions(+), 11 deletions(-) diff --git a/bin/console b/bin/console index f2d531a7..930e04b1 100755 --- a/bin/console +++ b/bin/console @@ -49,7 +49,7 @@ $serverArgs = array_values($serverArgs); $kernelClass = 'Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp\\'.$kernelInput; $input = new ArgvInput(); -$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: uniqid()); +$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: bin2hex(random_bytes(6))); $debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod'; if ($debug) { diff --git a/fixtures/Bridge/Symfony/SymfonyApp/IsolatedKernel.php b/fixtures/Bridge/Symfony/SymfonyApp/IsolatedKernel.php index e0b023aa..843eac47 100644 --- a/fixtures/Bridge/Symfony/SymfonyApp/IsolatedKernel.php +++ b/fixtures/Bridge/Symfony/SymfonyApp/IsolatedKernel.php @@ -13,6 +13,8 @@ namespace Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp; +use function bin2hex; +use function random_bytes; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\PassConfig; @@ -27,7 +29,7 @@ abstract class IsolatedKernel extends Kernel */ public static function create() { - return new static(uniqid(), true); + return new static(bin2hex(random_bytes(6)), true); } public function build(ContainerBuilder $container): void diff --git a/tests/Bridge/DoctrinePhpCr/Persister/ObjectManagerPersisterTest.php b/tests/Bridge/DoctrinePhpCr/Persister/ObjectManagerPersisterTest.php index 5d335bd7..43b82336 100644 --- a/tests/Bridge/DoctrinePhpCr/Persister/ObjectManagerPersisterTest.php +++ b/tests/Bridge/DoctrinePhpCr/Persister/ObjectManagerPersisterTest.php @@ -13,6 +13,7 @@ namespace Fidry\AliceDataFixtures\Bridge\DoctrinePhpCr\Persister; +use function bin2hex; use Doctrine\Common\DataFixtures\Purger\PHPCRPurger; use Doctrine\ODM\PHPCR\DocumentManager; use Doctrine\ODM\PHPCR\Exception\InvalidArgumentException; @@ -22,6 +23,7 @@ use Fidry\AliceDataFixtures\Bridge\Doctrine\PhpCrDocument\MappedSuperclassDummy; use Fidry\AliceDataFixtures\Persistence\PersisterInterface; use PHPUnit\Framework\TestCase; +use function random_bytes; use ReflectionClass; /** @@ -93,7 +95,7 @@ public static function provideDocuments(): iterable yield 'simple entity' => [ (static function () { $dummy = new Dummy(); - $dummy->id = '/dummy_'.uniqid(); + $dummy->id = '/dummy_'.bin2hex(random_bytes(6)); return $dummy; })() @@ -102,7 +104,7 @@ public static function provideDocuments(): iterable yield 'sub class entity' => [ (static function () { $dummy = new DummySubClass(); - $dummy->id = '/subdummy_'.uniqid(); + $dummy->id = '/subdummy_'.bin2hex(random_bytes(6)); $dummy->status = '200'; return $dummy; diff --git a/tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php b/tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php index 8a330f51..67fb2fdc 100644 --- a/tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php +++ b/tests/Bridge/DoctrinePhpCr/Purger/PurgerTest.php @@ -13,6 +13,7 @@ namespace Fidry\AliceDataFixtures\Bridge\DoctrinePhpCr\Purger; +use function bin2hex; use Doctrine\Common\DataFixtures\Purger\ORMPurger as DoctrineOrmPurger; use Doctrine\Common\DataFixtures\Purger\PHPCRPurger; use Doctrine\ODM\PHPCR\DocumentManager; @@ -23,6 +24,7 @@ use Fidry\AliceDataFixtures\Persistence\PurgerInterface; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; +use function random_bytes; use ReflectionClass; use ReflectionObject; @@ -68,7 +70,7 @@ public function testEmptyDatabase(): void $manager = $GLOBALS['document_manager']; $dummy = new Dummy(); - $dummy->id = '/dummy_'.uniqid(); + $dummy->id = '/dummy_'.bin2hex(random_bytes(6)); $manager->persist($dummy); $manager->flush(); @@ -81,7 +83,7 @@ public function testEmptyDatabase(): void // Ensures the schema has been restored $dummy = new Dummy(); - $dummy->id = '/dummy_'.uniqid(); + $dummy->id = '/dummy_'.bin2hex(random_bytes(6)); $manager->persist($dummy); $manager->flush(); self::assertCount(1, $manager->getRepository(Dummy::class)->findAll()); diff --git a/tests/Bridge/Symfony/Doctrine/MongodbLoaderIntegrationTest.php b/tests/Bridge/Symfony/Doctrine/MongodbLoaderIntegrationTest.php index 84bb6c97..4583e7c6 100644 --- a/tests/Bridge/Symfony/Doctrine/MongodbLoaderIntegrationTest.php +++ b/tests/Bridge/Symfony/Doctrine/MongodbLoaderIntegrationTest.php @@ -13,12 +13,14 @@ namespace Fidry\AlicePersistence\Bridge\Symfony\Doctrine; +use function bin2hex; use Doctrine\Common\DataFixtures\Purger\MongoDBPurger; use Doctrine\Persistence\ManagerRegistry; use Fidry\AliceDataFixtures\Bridge\Symfony\MongoDocument\Dummy; use Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp\DoctrineMongodbKernel; use Fidry\AliceDataFixtures\LoaderInterface; use PHPUnit\Framework\TestCase; +use function random_bytes; use Symfony\Component\HttpKernel\KernelInterface; /** @@ -40,7 +42,7 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - static::$seed = uniqid(); + static::$seed = bin2hex(random_bytes(6)); } public function setUp(): void diff --git a/tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php b/tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php index 2677aaf4..a6cc572d 100644 --- a/tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php +++ b/tests/Bridge/Symfony/Doctrine/ORMLoaderIntegrationTest.php @@ -13,6 +13,7 @@ namespace Fidry\AlicePersistence\Bridge\Symfony\Doctrine; +use function bin2hex; use Doctrine\Bundle\DoctrineBundle\Registry; use Doctrine\Common\DataFixtures\Purger\ORMPurger as DoctrineOrmPurger; use Fidry\AliceDataFixtures\Bridge\Symfony\Entity\Dummy; @@ -21,6 +22,7 @@ use Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp\DoctrineKernel; use Fidry\AliceDataFixtures\LoaderInterface; use PHPUnit\Framework\TestCase; +use function random_bytes; use Symfony\Component\HttpKernel\KernelInterface; /** @@ -40,7 +42,7 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - static::$seed = uniqid(); + static::$seed = bin2hex(random_bytes(6)); } public function setUp(): void diff --git a/tests/Bridge/Symfony/Doctrine/PhpcrLoaderIntegrationTest.php b/tests/Bridge/Symfony/Doctrine/PhpcrLoaderIntegrationTest.php index 99be2646..40882777 100644 --- a/tests/Bridge/Symfony/Doctrine/PhpcrLoaderIntegrationTest.php +++ b/tests/Bridge/Symfony/Doctrine/PhpcrLoaderIntegrationTest.php @@ -13,12 +13,14 @@ namespace Fidry\AlicePersistence\Bridge\Symfony\Doctrine; +use function bin2hex; use Doctrine\Common\DataFixtures\Purger\PHPCRPurger; use Doctrine\Persistence\ManagerRegistry; use Fidry\AliceDataFixtures\Bridge\Symfony\PhpCrDocument\Dummy; use Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp\DoctrinePhpcrKernel; use Fidry\AliceDataFixtures\LoaderInterface; use PHPUnit\Framework\TestCase; +use function random_bytes; use Symfony\Component\HttpKernel\KernelInterface; /** @@ -38,7 +40,7 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - static::$seed = uniqid(); + static::$seed = bin2hex(random_bytes(6)); } public function setUp(): void @@ -73,7 +75,7 @@ public function testLoadAFile(): void public function testLoadAFileWithPurger(): void { $dummy = new Dummy(); - $dummy->id = '/dummy_'.uniqid(); + $dummy->id = '/dummy_'.bin2hex(random_bytes(6)); $dummyManager = $this->doctrine->getManager(); $dummyManager->persist($dummy); $dummyManager->flush(); diff --git a/tests/Bridge/Symfony/Eloquent/ORMLoaderIntegrationTest.php b/tests/Bridge/Symfony/Eloquent/ORMLoaderIntegrationTest.php index 4cbb698c..a5b50641 100644 --- a/tests/Bridge/Symfony/Eloquent/ORMLoaderIntegrationTest.php +++ b/tests/Bridge/Symfony/Eloquent/ORMLoaderIntegrationTest.php @@ -13,11 +13,13 @@ namespace Fidry\AlicePersistence\Bridge\Symfony\Eloquent; +use function bin2hex; use Fidry\AliceDataFixtures\Bridge\Eloquent\Model\AnotherDummy; use Fidry\AliceDataFixtures\Bridge\Eloquent\Model\Dummy; use Fidry\AliceDataFixtures\Bridge\Symfony\SymfonyApp\EloquentKernel; use Fidry\AliceDataFixtures\LoaderInterface; use PHPUnit\Framework\TestCase; +use function random_bytes; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; @@ -38,7 +40,7 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - static::$seed = uniqid(); + static::$seed = bin2hex(random_bytes(6)); } public function setUp(): void From 2a74a4423d6bbb09e325de90c7288fde984ac648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 19 Dec 2021 18:40:20 +0100 Subject: [PATCH 11/11] Fix tests --- fixtures/Bridge/Eloquent/Model/AnotherDummy.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fixtures/Bridge/Eloquent/Model/AnotherDummy.php b/fixtures/Bridge/Eloquent/Model/AnotherDummy.php index 3fed649b..caaf42aa 100644 --- a/fixtures/Bridge/Eloquent/Model/AnotherDummy.php +++ b/fixtures/Bridge/Eloquent/Model/AnotherDummy.php @@ -20,13 +20,13 @@ class AnotherDummy extends Model { protected $table = 'another_dummies'; - protected array $fillable = [ + protected $fillable = [ 'id', 'address', 'dummy', ]; - public bool $timestamps = false; + public $timestamps = false; public function dummy(): BelongsTo {