diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d4df5435..0940f11b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,6 +6,7 @@ xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" colors="true" beStrictAboutOutputDuringTests="true" + processIsolation="true" > @@ -18,11 +19,4 @@ tests/Test - - - - mysql - pgsql - - diff --git a/tests/App/Entity/User.php b/tests/App/Entity/User.php index 2e328824..a2cf2296 100644 --- a/tests/App/Entity/User.php +++ b/tests/App/Entity/User.php @@ -16,48 +16,24 @@ use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - * - * @ORM\Table(name="liip_user") - */ #[ORM\Entity] #[ORM\Table(name: 'liip_user')] class User { - /** - * @ORM\Id - * - * @ORM\Column(type="integer") - * - * @ORM\GeneratedValue(strategy="AUTO") - */ #[ORM\Id] #[ORM\Column(type: Types::INTEGER)] #[ORM\GeneratedValue(strategy: 'AUTO')] private ?int $id = null; - /** - * @ORM\Column - */ #[ORM\Column] private string $name; - /** - * @ORM\Column - */ #[ORM\Column] private string $salt; - /** - * @ORM\Column - */ #[ORM\Column] private string $email; - /** - * @ORM\Column(nullable=true) - */ #[ORM\Column(nullable: true)] private ?string $dummyText = null; diff --git a/tests/Test/ConfigEventsTest.php b/tests/Test/ConfigEventsTest.php index 8bb064c5..d4677eb0 100644 --- a/tests/Test/ConfigEventsTest.php +++ b/tests/Test/ConfigEventsTest.php @@ -13,7 +13,6 @@ namespace Liip\Acme\Tests\Test; -use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation; use Liip\Acme\Tests\AppConfigEvents\AppConfigEventsKernel; use Liip\Acme\Tests\AppConfigEvents\EventListener\FixturesSubscriber; use Liip\Acme\Tests\Traits\ContainerProvider; @@ -21,6 +20,8 @@ use Liip\TestFixturesBundle\Services\DatabaseToolCollection; use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool; use Liip\TestFixturesBundle\Services\DatabaseTools\ORMSqliteDatabaseTool; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\PreserveGlobalState; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; /** @@ -30,14 +31,9 @@ * Tests/App/AppKernel.php. * So it must be loaded in a separate process. * - * @runTestsInSeparateProcesses - * - * @preserveGlobalState disabled - * - * @IgnoreAnnotation("dataProvider") - * * @internal */ +#[PreserveGlobalState(false)] class ConfigEventsTest extends KernelTestCase { use ContainerProvider; @@ -88,10 +84,9 @@ public function testLoadEmptyFixturesAndCheckEvents(): void * Check that events are called. * * We disable the cache to ensure that all the code is executed. - * - * @dataProvider fixturesEventsProvider */ - public function testLoadEmptyFixturesAndCheckEventsAreCalled(string $eventName, string $methodName, int $numberOfInvocations, bool $withCache = true): void + #[DataProvider('fixturesEventsProvider')] + public function testLoadEmptyFixturesAndCheckEventsAreCalled(string $eventName, string $methodName, int $numberOfInvocations, ?bool $withCache = true): void { /** @var AbstractDatabaseTool $databaseTool */ $databaseTool = $this->getTestContainer()->get(DatabaseToolCollection::class)->get(); @@ -127,9 +122,8 @@ public function testLoadEmptyFixturesAndCheckEventsAreCalled(string $eventName, /** * We disable the cache to ensure that other events are called. - * - * @dataProvider fixturesEventsProvider */ + #[DataProvider('fixturesEventsProvider')] public function testLoadEmptyFixturesAndCheckEventsAreCalledWithoutCache(string $eventName, string $methodName, int $numberOfInvocations): void { // Swap 0 → 1 and 1 → 0 @@ -138,15 +132,13 @@ public function testLoadEmptyFixturesAndCheckEventsAreCalledWithoutCache(string $this->testLoadEmptyFixturesAndCheckEventsAreCalled($eventName, $methodName, $numberOfInvocations, false); } - public static function fixturesEventsProvider(): array + public static function fixturesEventsProvider(): iterable { - return [ - [LiipTestFixturesEvents::PRE_FIXTURE_BACKUP_RESTORE, 'preFixtureBackupRestore', 1], - [LiipTestFixturesEvents::POST_FIXTURE_SETUP, 'postFixtureSetup', 0], - [LiipTestFixturesEvents::POST_FIXTURE_BACKUP_RESTORE, 'postFixtureBackupRestore', 1], - [LiipTestFixturesEvents::PRE_REFERENCE_SAVE, 'preReferenceSave', 0], - [LiipTestFixturesEvents::POST_REFERENCE_SAVE, 'postReferenceSave', 0], - ]; + yield 'preFixtureBackupRestore' => [LiipTestFixturesEvents::PRE_FIXTURE_BACKUP_RESTORE, 'preFixtureBackupRestore', 1]; + yield 'postFixtureSetup' => [LiipTestFixturesEvents::POST_FIXTURE_SETUP, 'postFixtureSetup', 0]; + yield 'postFixtureBackupRestore' => [LiipTestFixturesEvents::POST_FIXTURE_BACKUP_RESTORE, 'postFixtureBackupRestore', 1]; + yield 'preReferenceSave' => [LiipTestFixturesEvents::PRE_REFERENCE_SAVE, 'preReferenceSave', 0]; + yield 'postReferenceSave' => [LiipTestFixturesEvents::POST_REFERENCE_SAVE, 'postReferenceSave', 0]; } protected static function getKernelClass(): string diff --git a/tests/Test/ConfigMongodbTest.php b/tests/Test/ConfigMongodbTest.php index 1155ea6a..f43de942 100755 --- a/tests/Test/ConfigMongodbTest.php +++ b/tests/Test/ConfigMongodbTest.php @@ -2,6 +2,17 @@ declare(strict_types=1); +/* + * This file is part of the Liip/TestFixturesBundle + * + * (c) Lukas Kahwe Smith + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Liip\Acme\Tests\Test; + /* * This file is part of the Liip/TestFixturesBundle * @@ -12,6 +23,7 @@ */ use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle; +use Doctrine\Common\DataFixtures\Executor\MongoDBExecutor; use Doctrine\Common\DataFixtures\ProxyReferenceRepository; use Doctrine\ODM\MongoDB\Repository\DocumentRepository; use Liip\Acme\Tests\AppConfigMongodb\AppConfigMongodbKernel; @@ -21,6 +33,7 @@ use Liip\TestFixturesBundle\Services\DatabaseToolCollection; use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool; use Liip\TestFixturesBundle\Services\DatabaseTools\MongoDBDatabaseTool; +use PHPUnit\Framework\Attributes\PreserveGlobalState; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; /** @@ -30,12 +43,9 @@ * Tests/App/AppKernel.php. * So it must be loaded in a separate process. * - * @#runTestsInSeparateProcesses - * - * @preserveGlobalState disabled - * * @internal */ +#[PreserveGlobalState(false)] class ConfigMongodbTest extends KernelTestCase { use ContainerProvider; @@ -75,7 +85,7 @@ public function testLoadFixturesMongodb(): void ]); $this->assertInstanceOf( - Doctrine\Common\DataFixtures\Executor\MongoDBExecutor::class, + MongoDBExecutor::class, $fixtures ); diff --git a/tests/Test/ConfigMysqlCacheDbTest.php b/tests/Test/ConfigMysqlCacheDbTest.php index e4d01955..7b3a03c8 100644 --- a/tests/Test/ConfigMysqlCacheDbTest.php +++ b/tests/Test/ConfigMysqlCacheDbTest.php @@ -13,9 +13,10 @@ namespace Liip\Acme\Tests\Test; -use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation; use Liip\Acme\Tests\App\Entity\User; use Liip\Acme\Tests\AppConfigMysqlCacheDb\AppConfigMysqlKernelCacheDb; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\PreserveGlobalState; /** * Test MySQL database with database caching enabled. @@ -31,19 +32,11 @@ * Tests/App/AppKernel.php. * So it must be loaded in a separate process. * - * @runTestsInSeparateProcesses - * - * @preserveGlobalState disabled - * - * @IgnoreAnnotation("group") - * * @internal */ +#[PreserveGlobalState(false)] class ConfigMysqlCacheDbTest extends ConfigMysqlTest { - /** - * @group mysql - */ public function testLoadFixturesAndCheckBackup(): void { $this->assertTrue($this->databaseTool->isDatabaseCacheEnabled()); @@ -114,9 +107,6 @@ public function testLoadFixturesAndCheckBackup(): void ); } - /** - * @group mysql - */ public function testLoadFixturesCheckReferences(): void { $this->markTestSkipped('This test is broken right now.'); diff --git a/tests/Test/ConfigMysqlKeepDatabaseAndSchemaTest.php b/tests/Test/ConfigMysqlKeepDatabaseAndSchemaTest.php index e733dc83..d4e853c3 100644 --- a/tests/Test/ConfigMysqlKeepDatabaseAndSchemaTest.php +++ b/tests/Test/ConfigMysqlKeepDatabaseAndSchemaTest.php @@ -13,8 +13,8 @@ namespace Liip\Acme\Tests\Test; -use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation; use Liip\Acme\Tests\AppConfigMysqlKeepDatabaseAndSchema\AppConfigMysqlKernelKeepDatabaseAndSchema; +use PHPUnit\Framework\Attributes\PreserveGlobalState; /** * Test MySQL database with database caching enabled. @@ -30,14 +30,9 @@ * Tests/App/AppKernel.php. * So it must be loaded in a separate process. * - * @runTestsInSeparateProcesses - * - * @preserveGlobalState disabled - * - * @IgnoreAnnotation("group") - * * @internal */ +#[PreserveGlobalState(false)] class ConfigMysqlKeepDatabaseAndSchemaTest extends ConfigMysqlTest { protected static function getKernelClass(): string diff --git a/tests/Test/ConfigMysqlTest.php b/tests/Test/ConfigMysqlTest.php index f130eca9..49b56745 100644 --- a/tests/Test/ConfigMysqlTest.php +++ b/tests/Test/ConfigMysqlTest.php @@ -13,7 +13,6 @@ namespace Liip\Acme\Tests\Test; -use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation; use Doctrine\Common\DataFixtures\Purger\ORMPurger; use Doctrine\Persistence\ObjectRepository; use Liip\Acme\Tests\App\Entity\User; @@ -22,6 +21,7 @@ use Liip\TestFixturesBundle\Services\DatabaseToolCollection; use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool; use Liip\TestFixturesBundle\Services\DatabaseTools\ORMDatabaseTool; +use PHPUnit\Framework\Attributes\PreserveGlobalState; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; // BC, needed by "theofidry/alice-data-fixtures: <1.3" not compatible with "doctrine/persistence: ^2.0" @@ -44,14 +44,9 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence * Tests/App/AppKernel.php. * So it must be loaded in a separate process. * - * @runTestsInSeparateProcesses - * - * @preserveGlobalState disabled - * - * @IgnoreAnnotation("group") - * * @internal */ +#[PreserveGlobalState(false)] class ConfigMysqlTest extends KernelTestCase { use ContainerProvider; @@ -77,11 +72,6 @@ protected function setUp(): void $this->assertInstanceOf(ORMDatabaseTool::class, $this->databaseTool); } - /** - * Data fixtures. - * - * @group mysql - */ public function testLoadEmptyFixtures(): void { $fixtures = $this->databaseTool->loadFixtures([]); @@ -92,9 +82,6 @@ public function testLoadEmptyFixtures(): void ); } - /** - * @group mysql - */ public function testLoadFixtures(int $firstUserId = 1): void { $fixtures = $this->databaseTool->loadFixtures([ @@ -132,9 +119,6 @@ public function testLoadFixtures(int $firstUserId = 1): void ); } - /** - * @group mysql - */ public function testAppendFixtures(int $firstUserId = 1, int $thirdUserId = 3): void { $this->databaseTool->loadFixtures([ @@ -189,8 +173,6 @@ public function testAppendFixtures(int $firstUserId = 1, int $thirdUserId = 3): * * Purge modes are defined in * Doctrine\Common\DataFixtures\Purger\ORMPurger. - * - * @group mysql */ public function testLoadFixturesAndExcludeFromPurge(): void { @@ -227,8 +209,6 @@ public function testLoadFixturesAndExcludeFromPurge(): void * * Purge modes are defined in * Doctrine\Common\DataFixtures\Purger\ORMPurger. - * - * @group mysql */ public function testLoadFixturesAndPurge(): void { @@ -289,8 +269,6 @@ public function testLoadFixturesAndPurge(): void /** * Use nelmio/alice. - * - * @group mysql */ public function testLoadFixturesFiles(): void { diff --git a/tests/Test/ConfigMysqlUrlTest.php b/tests/Test/ConfigMysqlUrlTest.php index 44daa68c..7fe89aeb 100644 --- a/tests/Test/ConfigMysqlUrlTest.php +++ b/tests/Test/ConfigMysqlUrlTest.php @@ -14,6 +14,7 @@ namespace Liip\Acme\Tests\Test; use Liip\Acme\Tests\AppConfigMysqlUrl\AppConfigMysqlUrlKernel; +use PHPUnit\Framework\Attributes\PreserveGlobalState; /** * Test MySQL database with a configuration by url. @@ -29,12 +30,9 @@ * Tests/App/AppKernel.php. * So it must be loaded in a separate process. * - * @runTestsInSeparateProcesses - * - * @preserveGlobalState disabled - * * @internal */ +#[PreserveGlobalState(false)] class ConfigMysqlUrlTest extends ConfigMysqlTest { protected static function getKernelClass(): string diff --git a/tests/Test/ConfigPgsqlTest.php b/tests/Test/ConfigPgsqlTest.php index a6b318db..90e685e0 100644 --- a/tests/Test/ConfigPgsqlTest.php +++ b/tests/Test/ConfigPgsqlTest.php @@ -15,6 +15,7 @@ use Liip\Acme\Tests\AppConfigPgsql\AppConfigPgsqlKernel; use Liip\TestFixturesBundle\Services\DatabaseTools\ORMDatabaseTool; +use PHPUnit\Framework\Attributes\PreserveGlobalState; /** * Test PostgreSQL database. @@ -30,12 +31,9 @@ * Tests/App/AppKernel.php. * So it must be loaded in a separate process. * - * @runTestsInSeparateProcesses - * - * @preserveGlobalState disabled - * * @internal */ +#[PreserveGlobalState(false)] class ConfigPgsqlTest extends ConfigMysqlTest { public function testToolType(): void diff --git a/tests/Test/ConfigSqliteTest.php b/tests/Test/ConfigSqliteTest.php index 8318a2cb..a4d0e2e7 100644 --- a/tests/Test/ConfigSqliteTest.php +++ b/tests/Test/ConfigSqliteTest.php @@ -19,7 +19,6 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence\ObjectManager'); } -use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation; use Doctrine\Common\DataFixtures\Purger\ORMPurger; use Doctrine\Persistence\ObjectRepository; use Liip\Acme\Tests\App\Entity\User; @@ -28,18 +27,14 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence use Liip\TestFixturesBundle\Services\DatabaseToolCollection; use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool; use Liip\TestFixturesBundle\Services\DatabaseTools\ORMSqliteDatabaseTool; +use PHPUnit\Framework\Attributes\Depends; +use PHPUnit\Framework\Attributes\PreserveGlobalState; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; /** - * @runTestsInSeparateProcesses - * - * @preserveGlobalState disabled - * - * @IgnoreAnnotation("depends") - * @IgnoreAnnotation("expectedException") - * * @internal */ +#[PreserveGlobalState(false)] class ConfigSqliteTest extends KernelTestCase { use ContainerProvider; @@ -357,9 +352,8 @@ public function testLoadNonexistentFixturesFiles(): void /** * Use nelmio/alice with PURGE_MODE_TRUNCATE. - * - * @depends testLoadFixturesFiles */ + #[Depends('testLoadFixturesFiles')] public function testLoadFixturesFilesWithPurgeModeTruncate(): void { $this->databaseTool->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE); diff --git a/tests/Test/ConfigSqliteUrlTest.php b/tests/Test/ConfigSqliteUrlTest.php index 5ccd8321..f8aa5986 100644 --- a/tests/Test/ConfigSqliteUrlTest.php +++ b/tests/Test/ConfigSqliteUrlTest.php @@ -19,21 +19,15 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence\ObjectManager'); } -use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation; use Liip\Acme\Tests\AppConfigSqliteUrl\AppConfigSqliteUrlKernel; +use PHPUnit\Framework\Attributes\PreserveGlobalState; /** * Run SQLite tests by using an URL for Doctrine. * - * @runTestsInSeparateProcesses - * - * @preserveGlobalState disabled - * - * @IgnoreAnnotation("depends") - * @IgnoreAnnotation("expectedException") - * * @internal */ +#[PreserveGlobalState(false)] class ConfigSqliteUrlTest extends ConfigSqliteTest { public static function getKernelClass(): string diff --git a/tests/Test/ConfigTest.php b/tests/Test/ConfigTest.php index 45fea84b..0bf18ffb 100644 --- a/tests/Test/ConfigTest.php +++ b/tests/Test/ConfigTest.php @@ -13,7 +13,6 @@ namespace Liip\Acme\Tests\Test; -use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation; use Doctrine\Persistence\ObjectRepository; use Liip\Acme\Tests\App\Entity\User; use Liip\Acme\Tests\AppConfig\AppConfigKernel; @@ -22,6 +21,7 @@ use Liip\TestFixturesBundle\Services\DatabaseToolCollection; use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool; use Liip\TestFixturesBundle\Services\DatabaseTools\ORMSqliteDatabaseTool; +use PHPUnit\Framework\Attributes\PreserveGlobalState; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; /** @@ -31,17 +31,9 @@ * Tests/App/AppKernel.php. * So it must be loaded in a separate process. * - * @runTestsInSeparateProcesses - * - * @preserveGlobalState disabled - * - * Avoid conflict with PHPUnit annotation when reading QueryCount - * annotation: - * - * @IgnoreAnnotation("expectedException") - * * @internal */ +#[PreserveGlobalState(false)] class ConfigTest extends KernelTestCase { use ContainerProvider;