From 823c1716acff81b8fa01a4ebbf15aa99f9ec5ae9 Mon Sep 17 00:00:00 2001 From: Nicolas PHILIPPE Date: Sun, 9 Feb 2025 13:50:40 +0100 Subject: [PATCH] chore: use PHPUnit 12 --- .env | 2 +- .github/workflows/ci.yml | 21 +++++++----- composer.json | 2 +- phpunit | 6 ++-- src/Persistence/ProxyRepositoryDecorator.php | 2 +- src/Persistence/RepositoryDecorator.php | 2 -- tests/Integration/ArrayFactoryTest.php | 3 ++ .../WithStory/WithStoryOnClassTest.php | 9 ----- .../WithStory/WithStoryOnMethodTest.php | 9 ----- .../WithStory/WithStoryOnParentClassTest.php | 3 -- tests/Integration/EventsTest.php | 2 ++ tests/Integration/Maker/MakeFactoryTest.php | 27 +++++++++++++++ tests/Integration/Maker/MakeStoryTest.php | 14 ++++++++ tests/Integration/Maker/MakerTestCase.php | 4 +++ .../Mongo/EmbeddableDocumentFactoryTest.php | 2 ++ .../ORM/EdgeCasesRelationshipTest.php | 10 +++--- .../EntityFactoryRelationshipTestCase.php | 13 ++++--- ...lymorphicEntityFactoryRelationshipTest.php | 1 - .../ProxyEntityFactoryRelationshipTest.php | 1 - .../StandardEntityFactoryRelationshipTest.php | 1 - tests/Integration/ObjectFactoryTest.php | 4 +++ .../Persistence/EmbeddableFactoryTestCase.php | 8 +++-- .../FactoryWithHooksInInitializeTest.php | 2 ++ .../Persistence/GenericFactoryTestCase.php | 34 +++++++++++++++++++ .../GenericProxyFactoryTestCase.php | 13 +++++++ .../GenericRepositoryDecoratorTestCase.php | 4 +++ .../PersistenceManagerTestCase.php | 2 ++ tests/Integration/Persistence/StoryTest.php | 22 ++++++++++++ tests/Integration/RequiresMongo.php | 8 ++++- tests/Integration/RequiresORM.php | 10 +++++- .../ResetDatabase/GlobalStoryTest.php | 3 ++ .../ResetDatabase/ResetDatabaseTest.php | 11 ++++++ tests/Unit/ArrayFactoryTest.php | 6 ++++ tests/Unit/FactoryTest.php | 9 +++++ tests/Unit/InstantiatorTest.php | 2 ++ tests/Unit/LazyValueTest.php | 5 +++ tests/Unit/ObjectFactoryTest.php | 23 +++++++++++++ .../PersistentObjectFactoryTest.php | 4 +++ tests/Unit/Persistence/ProxyGeneratorTest.php | 4 +++ 39 files changed, 252 insertions(+), 56 deletions(-) diff --git a/.env b/.env index 673ee0958..0ad92f850 100644 --- a/.env +++ b/.env @@ -9,4 +9,4 @@ MONGO_URL="mongodb://127.0.0.1:27018/dbName?compressors=disabled&gssapiServi USE_DAMA_DOCTRINE_TEST_BUNDLE="0" USE_FOUNDRY_PHPUNIT_EXTENSION="0" -PHPUNIT_VERSION="9" # allowed values: 9, 10, 11 +PHPUNIT_VERSION="9" # allowed values: 9, 10, 11, 12 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f8d084949..02d32d81f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,32 +16,35 @@ jobs: php: [ 8.2, 8.3, 8.4 ] symfony: [ 6.4.*, 7.1.*, 7.2.* ] database: [ mysql|mongo ] - phpunit: [ 11 ] + phpunit: [ 11, 12 ] # default values: # deps: [ highest ] # use-phpunit-extension: [ 0 ] exclude: - - {php: 8.1, symfony: 7.1.*} - - {php: 8.1, symfony: 7.2.*} + - {php: 8.2, phpunit: 12} + - {php: 8.3, phpunit: 11} + - {php: 8.4, phpunit: 11} + include: # php 8.1 - {php: 8.1, symfony: 6.4.*, phpunit: 9, database: mysql} # old PHPUnit versions - {php: 8.3, symfony: '*', phpunit: 9, database: mysql} - - {php: 8.3, symfony: '*', phpunit: 10, database: mysql} + - {php: 8.4, symfony: '*', phpunit: 10, database: mysql} + - {php: 8.4, symfony: '*', phpunit: 11, database: mysql} # test with no database (PHPUnit 9 is used to prevent some problems with empty data providers) - {php: 8.3, symfony: '*', phpunit: 9, database: none} - {php: 8.3, symfony: '*', phpunit: 9, database: none, deps: lowest} # One permutation per DBMS - - {php: 8.3, symfony: '*', phpunit: 11, database: mongo} - - {php: 8.3, symfony: '*', phpunit: 11, database: pgsql} - - {php: 8.3, symfony: '*', phpunit: 11, database: sqlite} - - {php: 8.3, symfony: '*', phpunit: 11, database: mysql} + - {php: 8.4, symfony: '*', phpunit: 12, database: mongo} + - {php: 8.4, symfony: '*', phpunit: 12, database: pgsql} + - {php: 8.4, symfony: '*', phpunit: 12, database: sqlite} + - {php: 8.4, symfony: '*', phpunit: 12, database: mysql} # lowest deps (one per DBMS) - {php: 8.3, symfony: '*', phpunit: 9, database: mysql|mongo, deps: lowest} @@ -51,7 +54,7 @@ jobs: - {php: 8.3, symfony: '*', phpunit: 9, database: mysql, deps: lowest} # using Foundry's PHPUnit extension - - {php: 8.3, symfony: '*', phpunit: 11, database: mysql|mongo, use-phpunit-extension: 1} + - {php: 8.4, symfony: '*', phpunit: 12, database: mysql|mongo, use-phpunit-extension: 1} env: DATABASE_URL: ${{ contains(matrix.database, 'mysql') && 'mysql://root:root@localhost:3306/foundry?serverVersion=5.7.42' || contains(matrix.database, 'pgsql') && 'postgresql://root:root@localhost:5432/foundry?serverVersion=15' || contains(matrix.database, 'sqlite') && 'sqlite:///%kernel.project_dir%/var/data.db' || '' }} MONGO_URL: ${{ contains(matrix.database, 'mongo') && 'mongodb://127.0.0.1:27017/dbName?compressors=disabled&gssapiServiceName=mongodb' || '' }} diff --git a/composer.json b/composer.json index beeb7cafb..d7695ea1d 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "doctrine/mongodb-odm-bundle": "^4.6|^5.0", "doctrine/mongodb-odm": "^2.4", "doctrine/orm": "^2.16|^3.0", - "phpunit/phpunit": "^9.5.0 || ^10.0 || ^11.0", + "phpunit/phpunit": "^9.5.0 || ^10.0 || ^11.0 || ^12.0", "symfony/console": "^6.4|^7.0", "symfony/dotenv": "^6.4|^7.0", "symfony/maker-bundle": "^1.55", diff --git a/phpunit b/phpunit index dfe4b3f60..66982847f 100755 --- a/phpunit +++ b/phpunit @@ -26,8 +26,8 @@ fi ### << ### >> update PHPUnit if needed -if [[ " 9 10 11 " != *" ${PHPUNIT_VERSION-9} "* ]]; then - echo "❌ PHPUNIT_VERSION should be one of 9, 10, 11"; +if [[ " 9 10 11 12 " != *" ${PHPUNIT_VERSION-9} "* ]]; then + echo "❌ PHPUNIT_VERSION should be one of 9, 10, 11, 12"; exit 1; fi @@ -62,7 +62,7 @@ case ${PHPUNIT_VERSION} in PHPUNIT_EXEC="${PHPUNIT_EXEC} -c phpunit-10.xml.dist" ;; - "11") + "11"|"12") PHPUNIT_EXEC="${PHPUNIT_EXEC} -c phpunit-10.xml.dist --extension Zenstruck\Foundry\Tests\Fixture\DoctrineCascadeRelationship\PhpUnitTestExtension" if [ "${USE_DAMA_DOCTRINE_TEST_BUNDLE:-0}" = "1" ]; then diff --git a/src/Persistence/ProxyRepositoryDecorator.php b/src/Persistence/ProxyRepositoryDecorator.php index 578a05c1c..bc7917718 100644 --- a/src/Persistence/ProxyRepositoryDecorator.php +++ b/src/Persistence/ProxyRepositoryDecorator.php @@ -20,7 +20,7 @@ * @template I of ObjectRepository * @extends RepositoryDecorator, I> */ -final class ProxyRepositoryDecorator extends RepositoryDecorator // @phpstan-ignore class.extendsFinalByPhpDoc +final class ProxyRepositoryDecorator extends RepositoryDecorator { /** * @return T|Proxy|null diff --git a/src/Persistence/RepositoryDecorator.php b/src/Persistence/RepositoryDecorator.php index 7dc8af29f..01bfb46b3 100644 --- a/src/Persistence/RepositoryDecorator.php +++ b/src/Persistence/RepositoryDecorator.php @@ -26,8 +26,6 @@ * @implements \IteratorAggregate * @mixin I * - * @final - * * @phpstan-import-type Parameters from Factory */ class RepositoryDecorator implements ObjectRepository, \IteratorAggregate, \Countable diff --git a/tests/Integration/ArrayFactoryTest.php b/tests/Integration/ArrayFactoryTest.php index 6aac2e8d6..d5e98ed29 100644 --- a/tests/Integration/ArrayFactoryTest.php +++ b/tests/Integration/ArrayFactoryTest.php @@ -11,6 +11,7 @@ namespace Zenstruck\Foundry\Tests\Integration; +use PHPUnit\Framework\Attributes\Test; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Zenstruck\Foundry\LazyValue; use Zenstruck\Foundry\Test\Factories; @@ -26,6 +27,7 @@ final class ArrayFactoryTest extends KernelTestCase /** * @test */ + #[Test] public function can_create_with_defaults(): void { $this->assertSame( @@ -42,6 +44,7 @@ public function can_create_with_defaults(): void /** * @test */ + #[Test] public function can_create_with_overrides(): void { $this->assertSame( diff --git a/tests/Integration/Attribute/WithStory/WithStoryOnClassTest.php b/tests/Integration/Attribute/WithStory/WithStoryOnClassTest.php index b64777c46..f88ab6c8e 100644 --- a/tests/Integration/Attribute/WithStory/WithStoryOnClassTest.php +++ b/tests/Integration/Attribute/WithStory/WithStoryOnClassTest.php @@ -37,9 +37,6 @@ final class WithStoryOnClassTest extends KernelTestCase { use Factories, RequiresORM, ResetDatabase; - /** - * @test - */ #[Test] public function can_use_story_in_attribute(): void { @@ -49,9 +46,6 @@ public function can_use_story_in_attribute(): void $this->assertSame('foo', EntityStory::get('foo')->getProp1()); } - /** - * @test - */ #[Test] #[WithStory(EntityStory::class)] public function can_use_story_in_attribute_multiple_times(): void @@ -59,9 +53,6 @@ public function can_use_story_in_attribute_multiple_times(): void GenericEntityFactory::assert()->count(2); } - /** - * @test - */ #[Test] #[WithStory(EntityPoolStory::class)] public function can_use_another_story_at_level_class(): void diff --git a/tests/Integration/Attribute/WithStory/WithStoryOnMethodTest.php b/tests/Integration/Attribute/WithStory/WithStoryOnMethodTest.php index c6f0df929..f1df60672 100644 --- a/tests/Integration/Attribute/WithStory/WithStoryOnMethodTest.php +++ b/tests/Integration/Attribute/WithStory/WithStoryOnMethodTest.php @@ -37,9 +37,6 @@ final class WithStoryOnMethodTest extends KernelTestCase { use Factories, RequiresORM, ResetDatabase; - /** - * @test - */ #[Test] #[WithStory(EntityStory::class)] public function can_use_story_in_attribute(): void @@ -50,9 +47,6 @@ public function can_use_story_in_attribute(): void $this->assertSame('foo', EntityStory::get('foo')->getProp1()); } - /** - * @test - */ #[Test] #[WithStory(EntityStory::class)] #[WithStory(EntityPoolStory::class)] @@ -61,9 +55,6 @@ public function can_use_multiple_story_in_attribute(): void GenericEntityFactory::assert()->count(5); } - /** - * @test - */ #[Test] #[WithStory(ServiceStory::class)] public function can_use_service_story(): void diff --git a/tests/Integration/Attribute/WithStory/WithStoryOnParentClassTest.php b/tests/Integration/Attribute/WithStory/WithStoryOnParentClassTest.php index 84c199576..5b26bc18b 100644 --- a/tests/Integration/Attribute/WithStory/WithStoryOnParentClassTest.php +++ b/tests/Integration/Attribute/WithStory/WithStoryOnParentClassTest.php @@ -30,9 +30,6 @@ #[WithStory(EntityPoolStory::class)] final class WithStoryOnParentClassTest extends ParentClassWithStoryAttributeTestCase { - /** - * @test - */ #[Test] public function can_use_story_in_attribute_from_parent_class(): void { diff --git a/tests/Integration/EventsTest.php b/tests/Integration/EventsTest.php index 25398d187..0f003b44c 100644 --- a/tests/Integration/EventsTest.php +++ b/tests/Integration/EventsTest.php @@ -13,6 +13,7 @@ namespace Zenstruck\Foundry\Tests\Integration; +use PHPUnit\Framework\Attributes\Test; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Zenstruck\Foundry\Test\Factories; use Zenstruck\Foundry\Test\ResetDatabase; @@ -25,6 +26,7 @@ final class EventsTest extends KernelTestCase /** * @test */ + #[Test] public function it_can_call_hooks(): void { $address = FactoryWithEventListeners::createOne(['name' => 'events']); diff --git a/tests/Integration/Maker/MakeFactoryTest.php b/tests/Integration/Maker/MakeFactoryTest.php index 39e4a7a47..8da92332e 100644 --- a/tests/Integration/Maker/MakeFactoryTest.php +++ b/tests/Integration/Maker/MakeFactoryTest.php @@ -11,6 +11,9 @@ namespace Zenstruck\Foundry\Tests\Integration\Maker; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\Test; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException; use Symfony\Component\Console\Tester\CommandTester; @@ -29,6 +32,7 @@ * @author Kevin Bond * @group maker */ +#[Group('maker')] final class MakeFactoryTest extends MakerTestCase { private const PHPSTAN_PATH = __DIR__.'/../../..'.FactoryGenerator::PHPSTAN_PATH; @@ -59,6 +63,7 @@ protected function tearDown(): void /** * @test */ + #[Test] public function can_create_factory(): void { if (!\getenv('DATABASE_URL')) { @@ -79,6 +84,7 @@ public function can_create_factory(): void /** * @test */ + #[Test] public function can_create_factory_interactively(): void { if (!\getenv('DATABASE_URL')) { @@ -106,6 +112,7 @@ public function can_create_factory_interactively(): void /** * @test */ + #[Test] public function can_create_factory_in_test_dir(): void { if (!\getenv('DATABASE_URL')) { @@ -123,6 +130,8 @@ public function can_create_factory_in_test_dir(): void * @test * @dataProvider scaToolProvider */ + #[Test] + #[DataProvider('scaToolProvider')] public function can_create_factory_with_static_analysis_annotations(string $scaTool): void { if (!\getenv('DATABASE_URL')) { @@ -150,6 +159,7 @@ public static function scaToolProvider(): iterable /** * @test */ + #[Test] public function can_create_factory_for_entity_with_repository(): void { if (!\getenv('DATABASE_URL')) { @@ -166,6 +176,7 @@ public function can_create_factory_for_entity_with_repository(): void /** * @test */ + #[Test] public function invalid_entity_throws_exception(): void { $tester = $this->makeFactoryCommandTester(); @@ -185,6 +196,7 @@ public function invalid_entity_throws_exception(): void /** * @test */ + #[Test] public function can_create_factory_for_not_persisted_class(): void { $tester = $this->makeFactoryCommandTester(); @@ -197,6 +209,7 @@ public function can_create_factory_for_not_persisted_class(): void /** * @test */ + #[Test] public function can_create_factory_for_not_persisted_class_interactively(): void { $tester = $this->makeFactoryCommandTester(); @@ -215,6 +228,7 @@ public function can_create_factory_for_not_persisted_class_interactively(): void /** * @test */ + #[Test] public function can_customize_namespace(): void { if (!\getenv('DATABASE_URL')) { @@ -234,6 +248,7 @@ public function can_customize_namespace(): void /** * @test */ + #[Test] public function can_customize_namespace_with_test_flag(): void { if (!\getenv('DATABASE_URL')) { @@ -253,6 +268,7 @@ public function can_customize_namespace_with_test_flag(): void /** * @test */ + #[Test] public function can_customize_namespace_with_root_namespace_prefix(): void { if (!\getenv('DATABASE_URL')) { @@ -272,6 +288,7 @@ public function can_customize_namespace_with_root_namespace_prefix(): void /** * @test */ + #[Test] public function can_customize_namespace_with_test_flag_with_root_namespace_prefix(): void { if (!\getenv('DATABASE_URL')) { @@ -292,6 +309,8 @@ public function can_customize_namespace_with_test_flag_with_root_namespace_prefi * @test * @dataProvider documentProvider */ + #[Test] + #[DataProvider('documentProvider')] public function can_create_factory_for_odm(string $class, string $file): void { if (!\getenv('MONGO_URL')) { @@ -318,6 +337,7 @@ public static function documentProvider(): iterable /** * @test */ + #[Test] public function can_create_all_factories_for_doctrine_objects(): void { if (!\getenv('MONGO_URL') && !\getenv('DATABASE_URL')) { @@ -350,6 +370,7 @@ public function can_create_all_factories_for_doctrine_objects(): void /** * @test */ + #[Test] public function can_create_factory_with_auto_activated_not_persisted_option(): void { if (\getenv('MONGO_URL') || \getenv('DATABASE_URL')) { @@ -369,6 +390,7 @@ public function can_create_factory_with_auto_activated_not_persisted_option(): v /** * @test */ + #[Test] public function can_create_factory_with_all_fields(): void { if (!\getenv('DATABASE_URL')) { @@ -386,6 +408,8 @@ public function can_create_factory_with_all_fields(): void * @test * @dataProvider objectsWithEmbeddableProvider */ + #[Test] + #[DataProvider('objectsWithEmbeddableProvider')] public function can_create_factory_with_embeddable(string $objectClass, string $objectFactoryName): void { $tester = $this->makeFactoryCommandTester(); @@ -413,6 +437,7 @@ public static function objectsWithEmbeddableProvider(): iterable /** * @test */ + #[Test] public function can_create_factory_with_default_enum(): void { $tester = $this->makeFactoryCommandTester(); @@ -425,6 +450,7 @@ public function can_create_factory_with_default_enum(): void /** * @test */ + #[Test] public function does_not_initialize_non_settable(): void { $tester = $this->makeFactoryCommandTester(); @@ -437,6 +463,7 @@ public function does_not_initialize_non_settable(): void /** * @test */ + #[Test] public function does_force_initialization_of_non_settable_with_always_force(): void { $tester = $this->makeFactoryCommandTester(['environment' => 'always_force']); diff --git a/tests/Integration/Maker/MakeStoryTest.php b/tests/Integration/Maker/MakeStoryTest.php index 81f214088..9f30d9f1b 100644 --- a/tests/Integration/Maker/MakeStoryTest.php +++ b/tests/Integration/Maker/MakeStoryTest.php @@ -11,6 +11,9 @@ namespace Zenstruck\Foundry\Tests\Integration\Maker; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\Test; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; @@ -18,12 +21,15 @@ * @author Kevin Bond * @group maker */ +#[Group('maker')] final class MakeStoryTest extends MakerTestCase { /** * @test * @dataProvider storyNameProvider */ + #[Test] + #[DataProvider('storyNameProvider')] public function can_create_story(string $name): void { $tester = new CommandTester((new Application(self::bootKernel()))->find('make:story')); @@ -66,6 +72,8 @@ public function build(): void * @test * @dataProvider storyNameProvider */ + #[Test] + #[DataProvider('storyNameProvider')] public function can_create_story_interactively(string $name): void { $tester = new CommandTester((new Application(self::bootKernel()))->find('make:story')); @@ -112,6 +120,8 @@ public function build(): void * @test * @dataProvider storyNameProvider */ + #[Test] + #[DataProvider('storyNameProvider')] public function can_create_story_in_test_dir(string $name): void { $tester = new CommandTester((new Application(self::bootKernel()))->find('make:story')); @@ -154,6 +164,8 @@ public function build(): void * @test * @dataProvider storyNameProvider */ + #[Test] + #[DataProvider('storyNameProvider')] public function can_create_story_in_test_dir_interactively(string $name): void { $tester = new CommandTester((new Application(self::bootKernel()))->find('make:story')); @@ -210,6 +222,8 @@ public static function storyNameProvider(): iterable * @dataProvider namespaceProvider * @param array $commandOptions */ + #[Test] + #[DataProvider('namespaceProvider')] public function can_customize_namespace(string $filePath, array $commandOptions, string $expectedFullNamespace): void { $tester = new CommandTester((new Application(self::bootKernel()))->find('make:story')); diff --git a/tests/Integration/Maker/MakerTestCase.php b/tests/Integration/Maker/MakerTestCase.php index 1e830d3d9..928c99945 100644 --- a/tests/Integration/Maker/MakerTestCase.php +++ b/tests/Integration/Maker/MakerTestCase.php @@ -11,6 +11,8 @@ namespace Zenstruck\Foundry\Tests\Integration\Maker; +use PHPUnit\Framework\Attributes\Before; +use PHPUnit\Framework\Attributes\Group; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\String\Slugger\AsciiSlugger; @@ -19,11 +21,13 @@ * @author Kevin Bond * @group maker */ +#[Group('maker')] abstract class MakerTestCase extends KernelTestCase { /** * @before */ + #[Before] public static function cleanupTempDir(): void { (new Filesystem())->remove(self::tempDir()); diff --git a/tests/Integration/Mongo/EmbeddableDocumentFactoryTest.php b/tests/Integration/Mongo/EmbeddableDocumentFactoryTest.php index ef036ea3e..bb5b40c32 100644 --- a/tests/Integration/Mongo/EmbeddableDocumentFactoryTest.php +++ b/tests/Integration/Mongo/EmbeddableDocumentFactoryTest.php @@ -11,6 +11,7 @@ namespace Zenstruck\Foundry\Tests\Integration\Mongo; +use PHPUnit\Framework\Attributes\Test; use Zenstruck\Foundry\Persistence\PersistentObjectFactory; use Zenstruck\Foundry\Tests\Fixture\Document\WithEmbeddableDocument; use Zenstruck\Foundry\Tests\Fixture\Model\Embeddable; @@ -32,6 +33,7 @@ final class EmbeddableDocumentFactoryTest extends EmbeddableFactoryTestCase /** * @test */ + #[Test] public function embed_many(): void { $document = persist(WithEmbeddableDocument::class, [ diff --git a/tests/Integration/ORM/EdgeCasesRelationshipTest.php b/tests/Integration/ORM/EdgeCasesRelationshipTest.php index 5605c2f1b..86c1f37ae 100644 --- a/tests/Integration/ORM/EdgeCasesRelationshipTest.php +++ b/tests/Integration/ORM/EdgeCasesRelationshipTest.php @@ -99,7 +99,7 @@ public function inverse_one_to_one_with_both_nullable(): void #[DataProvider('provideCascadeRelationshipsCombinations')] #[UsingRelationships(InversedOneToOneWithOneToMany\OwningSide::class, ['inverseSide'])] #[UsingRelationships(InversedOneToOneWithOneToMany\Item::class, ['owningSide'])] - #[RequiresPhpunit('^11.4')] + #[RequiresPhpunit('>=11.4')] public function inverse_one_to_one_with_one_to_many(): void { $inverseSideFactory = persistent_factory(InversedOneToOneWithOneToMany\InverseSide::class); @@ -122,9 +122,8 @@ public function inverse_one_to_one_with_one_to_many(): void self::assertCount(2, $inverseSide->getOwningSide()->getItems()); } - /** - * @test - */ + /** @test */ + #[Test] public function many_to_many_to_self_referencing_inverse_side(): void { $owningSideFactory = persistent_factory(ManyToOneToSelfReferencing\OwningSide::class); @@ -140,7 +139,7 @@ public function many_to_many_to_self_referencing_inverse_side(): void #[Test] #[DataProvider('provideCascadeRelationshipsCombinations')] #[UsingRelationships(IndexedOneToMany\ParentEntity::class, ['items'])] - #[RequiresPhpunit('^11.4')] + #[RequiresPhpunit('>=11.4')] public function indexed_one_to_many(): void { $parentFactory = persistent_factory(IndexedOneToMany\ParentEntity::class); @@ -161,6 +160,7 @@ public function indexed_one_to_many(): void /** * @test */ + #[Test] public function inversed_multiple_mandatory_relationship_to_same_entity(): void { $this->markTestIncomplete('fixme! 🙏'); diff --git a/tests/Integration/ORM/EntityRelationship/EntityFactoryRelationshipTestCase.php b/tests/Integration/ORM/EntityRelationship/EntityFactoryRelationshipTestCase.php index bb64c6e29..3a6c3ce0b 100644 --- a/tests/Integration/ORM/EntityRelationship/EntityFactoryRelationshipTestCase.php +++ b/tests/Integration/ORM/EntityRelationship/EntityFactoryRelationshipTestCase.php @@ -37,7 +37,6 @@ /** * @author Kevin Bond * @author Nicolas PHILIPPE - * @requires PHPUnit >=11.4 */ #[RequiresPhpunit('>=11.4')] abstract class EntityFactoryRelationshipTestCase extends KernelTestCase @@ -304,7 +303,7 @@ public function forced_one_to_many_with_doctrine_collection_type(): void public function disabling_persistence_cascades_to_children(): void { $contact = static::contactFactory()->withoutPersisting()->create([ - 'tags' => static::tagFactory()::new()->many(3), + 'tags' => static::tagFactory()->many(3), 'category' => static::categoryFactory(), ]); @@ -365,9 +364,8 @@ public function ensure_one_to_many_relations_are_not_pre_persisted(): void } } - /** - * @test - */ + /** @test */ + #[Test] public function assert_updates_are_implicitly_persisted(): void { $category = static::categoryFactory()->create(); @@ -404,6 +402,7 @@ public function it_can_add_unmanaged_entity_to_many_to_one(): void } /** @test */ + #[Test] public function it_uses_after_persist_with_many_to_many(): void { $contact = static::contactFactory() @@ -420,6 +419,7 @@ public function it_uses_after_persist_with_many_to_many(): void } /** @test */ + #[Test] public function it_uses_after_persist_with_one_to_many(): void { $category = static::categoryFactory() @@ -435,6 +435,7 @@ public function it_uses_after_persist_with_one_to_many(): void } /** @test */ + #[Test] public function it_uses_after_persist_with_many_to_one(): void { $contact = static::contactFactory() @@ -449,6 +450,7 @@ public function it_uses_after_persist_with_many_to_one(): void } /** @test */ + #[Test] public function it_uses_after_persist_with_one_to_one(): void { $contact = static::contactFactory() @@ -461,6 +463,7 @@ public function it_uses_after_persist_with_one_to_one(): void } /** @test */ + #[Test] public function it_uses_after_persist_with_inversed_one_to_one(): void { $address = static::addressFactory() diff --git a/tests/Integration/ORM/EntityRelationship/PolymorphicEntityFactoryRelationshipTest.php b/tests/Integration/ORM/EntityRelationship/PolymorphicEntityFactoryRelationshipTest.php index 7b85207fd..7c93bfd3e 100644 --- a/tests/Integration/ORM/EntityRelationship/PolymorphicEntityFactoryRelationshipTest.php +++ b/tests/Integration/ORM/EntityRelationship/PolymorphicEntityFactoryRelationshipTest.php @@ -22,7 +22,6 @@ * * @author Kevin Bond * @author Nicolas PHILIPPE - * @requires PHPUnit >=11.4 */ #[RequiresPhpunit('>=11.4')] final class PolymorphicEntityFactoryRelationshipTest extends EntityFactoryRelationshipTestCase diff --git a/tests/Integration/ORM/EntityRelationship/ProxyEntityFactoryRelationshipTest.php b/tests/Integration/ORM/EntityRelationship/ProxyEntityFactoryRelationshipTest.php index ebdaca361..639469658 100644 --- a/tests/Integration/ORM/EntityRelationship/ProxyEntityFactoryRelationshipTest.php +++ b/tests/Integration/ORM/EntityRelationship/ProxyEntityFactoryRelationshipTest.php @@ -31,7 +31,6 @@ /** * @author Kevin Bond * @author Nicolas PHILIPPE - * @requires PHPUnit >=11.4 */ #[RequiresPhpunit('>=11.4')] final class ProxyEntityFactoryRelationshipTest extends EntityFactoryRelationshipTestCase diff --git a/tests/Integration/ORM/EntityRelationship/StandardEntityFactoryRelationshipTest.php b/tests/Integration/ORM/EntityRelationship/StandardEntityFactoryRelationshipTest.php index f9b217cf8..2051a4d65 100644 --- a/tests/Integration/ORM/EntityRelationship/StandardEntityFactoryRelationshipTest.php +++ b/tests/Integration/ORM/EntityRelationship/StandardEntityFactoryRelationshipTest.php @@ -22,7 +22,6 @@ /** * @author Kevin Bond * @author Nicolas PHILIPPE - * @requires PHPUnit >=11.4 */ #[RequiresPhpunit('>=11.4')] final class StandardEntityFactoryRelationshipTest extends EntityFactoryRelationshipTestCase diff --git a/tests/Integration/ObjectFactoryTest.php b/tests/Integration/ObjectFactoryTest.php index 96f3ca87e..f99fbf6f6 100644 --- a/tests/Integration/ObjectFactoryTest.php +++ b/tests/Integration/ObjectFactoryTest.php @@ -11,6 +11,7 @@ namespace Zenstruck\Foundry\Tests\Integration; +use PHPUnit\Framework\Attributes\Test; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Zenstruck\Foundry\Test\Factories; use Zenstruck\Foundry\Tests\Fixture\Factories\Object1Factory; @@ -26,6 +27,7 @@ final class ObjectFactoryTest extends KernelTestCase /** * @test */ + #[Test] public function can_create_service_factory(): void { $object = Object1Factory::createOne(); @@ -38,6 +40,7 @@ public function can_create_service_factory(): void /** * @test */ + #[Test] public function can_create_non_service_factories(): void { $object = Object2Factory::createOne(); @@ -48,6 +51,7 @@ public function can_create_non_service_factories(): void /** * @test */ + #[Test] public function can_create_different_objects_based_on_same_factory(): void { $factory = Object1Factory::new(['prop1' => 'first object']); diff --git a/tests/Integration/Persistence/EmbeddableFactoryTestCase.php b/tests/Integration/Persistence/EmbeddableFactoryTestCase.php index 29165da1e..f556969eb 100644 --- a/tests/Integration/Persistence/EmbeddableFactoryTestCase.php +++ b/tests/Integration/Persistence/EmbeddableFactoryTestCase.php @@ -11,6 +11,7 @@ namespace Zenstruck\Foundry\Tests\Integration\Persistence; +use PHPUnit\Framework\Attributes\Test; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Zenstruck\Foundry\Persistence\PersistentObjectFactory; use Zenstruck\Foundry\Test\Factories; @@ -27,9 +28,8 @@ abstract class EmbeddableFactoryTestCase extends KernelTestCase { use Factories, ResetDatabase; - /** - * @test - */ + /** @test */ + #[Test] public function embed_one(): void { $factory = $this->withEmbeddableFactory(); @@ -48,6 +48,7 @@ public function embed_one(): void /** * @test */ + #[Test] public function can_find_using_embeddable_object(): void { $factory = $this->withEmbeddableFactory(); @@ -64,6 +65,7 @@ public function can_find_using_embeddable_object(): void /** * @test */ + #[Test] public function can_use_embeddable_as_factory_parameter(): void { $factory = $this->withEmbeddableFactory(); diff --git a/tests/Integration/Persistence/FactoryWithHooksInInitializeTest.php b/tests/Integration/Persistence/FactoryWithHooksInInitializeTest.php index 4cb182a76..e45adc671 100644 --- a/tests/Integration/Persistence/FactoryWithHooksInInitializeTest.php +++ b/tests/Integration/Persistence/FactoryWithHooksInInitializeTest.php @@ -13,6 +13,7 @@ namespace Zenstruck\Foundry\Tests\Integration\Persistence; +use PHPUnit\Framework\Attributes\Test; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Zenstruck\Foundry\Test\Factories; use Zenstruck\Foundry\Tests\Fixture\Factories\WithHooksInInitializeFactory; @@ -27,6 +28,7 @@ final class FactoryWithHooksInInitializeTest extends KernelTestCase /** * @test */ + #[Test] public function it_can_access_current_factory_in_hooks(): void { $address = WithHooksInInitializeFactory::new()->withoutPersisting()->create(); diff --git a/tests/Integration/Persistence/GenericFactoryTestCase.php b/tests/Integration/Persistence/GenericFactoryTestCase.php index 4163cbadd..3c8689caf 100644 --- a/tests/Integration/Persistence/GenericFactoryTestCase.php +++ b/tests/Integration/Persistence/GenericFactoryTestCase.php @@ -11,6 +11,8 @@ namespace Zenstruck\Foundry\Tests\Integration\Persistence; +use PHPUnit\Framework\Attributes\Depends; +use PHPUnit\Framework\Attributes\Test; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Zenstruck\Foundry\Configuration; use Zenstruck\Foundry\Exception\PersistenceDisabled; @@ -42,6 +44,7 @@ abstract class GenericFactoryTestCase extends KernelTestCase /** * @test */ + #[Test] public function can_create_and_update(): void { static::factory()::assert()->empty(); @@ -70,6 +73,7 @@ public function can_create_and_update(): void /** * @test */ + #[Test] public function can_disable_auto_persist(): void { static::factory()->repository()->assert()->empty(); @@ -89,6 +93,7 @@ public function can_disable_auto_persist(): void /** * @test */ + #[Test] public function can_refresh(): void { $object = static::factory()->create(); @@ -116,6 +121,7 @@ public function can_refresh(): void /** * @test */ + #[Test] public function cannot_refresh_if_there_are_unsaved_changes(): void { $object = static::factory()->create(); @@ -140,6 +146,7 @@ public function cannot_refresh_if_there_are_unsaved_changes(): void /** * @test */ + #[Test] public function can_delete(): void { $object = static::factory()->create(); @@ -154,6 +161,7 @@ public function can_delete(): void /** * @test */ + #[Test] public function repository_and_create_function(): void { repository($this->modelClass())->assert()->empty(); @@ -169,6 +177,7 @@ public function repository_and_create_function(): void /** * @test */ + #[Test] public function create_many(): void { $models = static::factory()->createMany(3, fn(int $i) => ['prop1' => "value{$i}"]); @@ -183,6 +192,7 @@ public function create_many(): void /** * @test */ + #[Test] public function find(): void { $object = static::factory()->create(['prop1' => 'foo']); @@ -194,6 +204,7 @@ public function find(): void /** * @test */ + #[Test] public function find_must_return_object(): void { $this->expectException(\RuntimeException::class); @@ -204,6 +215,7 @@ public function find_must_return_object(): void /** * @test */ + #[Test] public function find_by(): void { static::factory()->create(['prop1' => 'a']); @@ -217,6 +229,7 @@ public function find_by(): void /** * @test */ + #[Test] public function find_or_create(): void { static::factory()->create(['prop1' => 'a']); @@ -233,6 +246,7 @@ public function find_or_create(): void /** * @test */ + #[Test] public function random(): void { static::factory()->create(['prop1' => 'a']); @@ -246,6 +260,7 @@ public function random(): void /** * @test */ + #[Test] public function random_must_return_an_object(): void { $this->expectException(NotEnoughObjects::class); @@ -256,6 +271,7 @@ public function random_must_return_an_object(): void /** * @test */ + #[Test] public function random_or_create(): void { static::factory()->create(['prop1' => 'a']); @@ -273,6 +289,7 @@ public function random_or_create(): void /** * @test */ + #[Test] public function random_set(): void { static::factory()->create(['prop1' => 'a']); @@ -295,6 +312,7 @@ public function random_set(): void /** * @test */ + #[Test] public function random_set_requires_at_least_the_number_available(): void { static::factory()::createMany(3); @@ -307,6 +325,7 @@ public function random_set_requires_at_least_the_number_available(): void /** * @test */ + #[Test] public function random_range(): void { static::factory()->create(['prop1' => 'a']); @@ -336,6 +355,7 @@ public function random_range(): void /** * @test */ + #[Test] public function random_range_requires_at_least_the_max_available(): void { static::factory()::createMany(3); @@ -348,6 +368,7 @@ public function random_range_requires_at_least_the_max_available(): void /** * @test */ + #[Test] public function factory_count(): void { static::factory()::createOne(['prop1' => 'a']); @@ -361,6 +382,7 @@ public function factory_count(): void /** * @test */ + #[Test] public function truncate(): void { static::factory()::createMany(3); @@ -374,6 +396,7 @@ public function truncate(): void /** * @test */ + #[Test] public function factory_all(): void { static::factory()::createMany(3); @@ -384,6 +407,7 @@ public function factory_all(): void /** * @test */ + #[Test] public function repository_assertions(): void { $assert = static::factory()::repository()->assert(); @@ -414,6 +438,7 @@ public function repository_assertions(): void /** * @test */ + #[Test] public function repository_is_lazy(): void { static::factory()::createOne(); @@ -432,6 +457,7 @@ public function repository_is_lazy(): void /** * @test */ + #[Test] public function flush_after(): void { static::factory()::repository()->assert()->empty(); @@ -455,6 +481,7 @@ public function flush_after(): void /** * @test */ + #[Test] public function can_disable_and_enable_persisting_globally(): void { static::factory()::repository()->assert()->empty(); @@ -475,6 +502,7 @@ public function can_disable_and_enable_persisting_globally(): void /** * @test */ + #[Test] public function cannot_access_repository_method_when_persist_disabled(): void { disable_persisting(); @@ -504,6 +532,7 @@ public function cannot_access_repository_method_when_persist_disabled(): void /** * @test */ + #[Test] public function can_persist_object_with_sequence(): void { static::factory()->sequence([['prop1' => 'foo'], ['prop1' => 'bar']])->create(); @@ -517,6 +546,8 @@ public function can_persist_object_with_sequence(): void * @test * @depends cannot_access_repository_method_when_persist_disabled */ + #[Test] + #[Depends('cannot_access_repository_method_when_persist_disabled')] public function assert_persist_is_re_enabled_automatically(): void { $configuration = Configuration::instance(); @@ -530,6 +561,7 @@ public function assert_persist_is_re_enabled_automatically(): void /** * @test */ + #[Test] public function assert_it_ca_create_object_with_dates(): void { $object = static::factory()->create(['date' => $date = new \DateTimeImmutable()]); @@ -539,6 +571,7 @@ public function assert_it_ca_create_object_with_dates(): void /** * @test */ + #[Test] public function it_should_not_create_proxy_for_not_persistable_objects(): void { $this->factory()->create(['date' => new \DateTimeImmutable()]); @@ -548,6 +581,7 @@ public function it_should_not_create_proxy_for_not_persistable_objects(): void /** * @test */ + #[Test] public function can_use_after_persist_with_attributes(): void { $object = static::factory() diff --git a/tests/Integration/Persistence/GenericProxyFactoryTestCase.php b/tests/Integration/Persistence/GenericProxyFactoryTestCase.php index 66da90b39..b6c07ff0a 100644 --- a/tests/Integration/Persistence/GenericProxyFactoryTestCase.php +++ b/tests/Integration/Persistence/GenericProxyFactoryTestCase.php @@ -30,6 +30,7 @@ abstract class GenericProxyFactoryTestCase extends GenericFactoryTestCase /** * @test */ + #[Test] public function can_update_and_delete_via_proxy(): void { static::factory()->repository()->assert()->empty(); @@ -63,6 +64,7 @@ public function can_update_and_delete_via_proxy(): void /** * @test */ + #[Test] public function can_disable_persisting_by_factory_and_save_proxy(): void { static::factory()->repository()->assert()->empty(); @@ -82,6 +84,7 @@ public function can_disable_persisting_by_factory_and_save_proxy(): void /** * @test */ + #[Test] public function can_disable_and_enable_proxy_auto_refreshing(): void { $object = static::factory()->create(); @@ -103,6 +106,7 @@ public function can_disable_and_enable_proxy_auto_refreshing(): void /** * @test */ + #[Test] public function can_disable_and_enable_proxy_auto_refreshing_with_callback(): void { $object = static::factory()->create(); @@ -124,6 +128,7 @@ public function can_disable_and_enable_proxy_auto_refreshing_with_callback(): vo /** * @test */ + #[Test] public function can_manually_refresh_via_proxy(): void { $object = static::factory()->create()->_disableAutoRefresh(); @@ -151,6 +156,7 @@ public function can_manually_refresh_via_proxy(): void /** * @test */ + #[Test] public function proxy_auto_refreshes(): void { $object = static::factory()->create(); @@ -176,6 +182,7 @@ public function proxy_auto_refreshes(): void /** * @test */ + #[Test] public function cannot_auto_refresh_proxy_if_changes(): void { $object = static::factory()->create(); @@ -203,6 +210,7 @@ public function cannot_auto_refresh_proxy_if_changes(): void /** * @test */ + #[Test] public function can_access_repository_from_proxy(): void { $object = static::factory()::createOne(); @@ -215,6 +223,7 @@ public function can_access_repository_from_proxy(): void /** * @test */ + #[Test] public function can_force_set_and_get_proxy(): void { $object = static::factory()::createOne(); @@ -229,6 +238,7 @@ public function can_force_set_and_get_proxy(): void /** * @test */ + #[Test] public function can_get_real_object_even_if_modified(): void { $object = static::factory()->create(); @@ -241,6 +251,7 @@ public function can_get_real_object_even_if_modified(): void /** * @test */ + #[Test] public function can_create_object_with_readonly_properties(): void { $factory = $this->objectWithReadonlyFactory(); @@ -259,6 +270,7 @@ public function can_create_object_with_readonly_properties(): void /** * @test */ + #[Test] public function can_delete_proxified_object_and_still_access_its_methods(): void { $object = static::factory()->create(); @@ -270,6 +282,7 @@ public function can_delete_proxified_object_and_still_access_its_methods(): void /** * @test */ + #[Test] public function can_use_after_persist_with_attributes_added_in_before_instantiate(): void { $value = 'value set with before instantiate'; diff --git a/tests/Integration/Persistence/GenericRepositoryDecoratorTestCase.php b/tests/Integration/Persistence/GenericRepositoryDecoratorTestCase.php index 4e58fd2e0..76ae76e94 100644 --- a/tests/Integration/Persistence/GenericRepositoryDecoratorTestCase.php +++ b/tests/Integration/Persistence/GenericRepositoryDecoratorTestCase.php @@ -13,6 +13,7 @@ namespace Zenstruck\Foundry\Tests\Integration\Persistence; +use PHPUnit\Framework\Attributes\Test; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Zenstruck\Foundry\Persistence\PersistentObjectFactory; use Zenstruck\Foundry\Test\Factories; @@ -29,6 +30,7 @@ abstract class GenericRepositoryDecoratorTestCase extends KernelTestCase /** * @test */ + #[Test] public function repository_proxy_is_countable_and_iterable(): void { $this->factory()->many(4)->create(); @@ -42,6 +44,7 @@ public function repository_proxy_is_countable_and_iterable(): void /** * @test */ + #[Test] public function can_fetch_objects(): void { $this->factory()->many(2)->create(); @@ -60,6 +63,7 @@ public function can_fetch_objects(): void /** * @test */ + #[Test] public function can_call_find_with_empty_array(): void { $object = $this->factory()->create(); diff --git a/tests/Integration/Persistence/PersistenceManagerTestCase.php b/tests/Integration/Persistence/PersistenceManagerTestCase.php index f8d2e3992..c1602295b 100644 --- a/tests/Integration/Persistence/PersistenceManagerTestCase.php +++ b/tests/Integration/Persistence/PersistenceManagerTestCase.php @@ -14,6 +14,7 @@ namespace Zenstruck\Foundry\Tests\Integration\Persistence; use Doctrine\Persistence\ObjectManager; +use PHPUnit\Framework\Attributes\Test; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Zenstruck\Foundry\Configuration; use Zenstruck\Foundry\Test\Factories; @@ -25,6 +26,7 @@ abstract class PersistenceManagerTestCase extends KernelTestCase /** * @test */ + #[Test] public function it_can_test_if_object_with_uuid_is_persisted(): void { $object = $this->createObject(); diff --git a/tests/Integration/Persistence/StoryTest.php b/tests/Integration/Persistence/StoryTest.php index 0d17f9b61..01e824f20 100644 --- a/tests/Integration/Persistence/StoryTest.php +++ b/tests/Integration/Persistence/StoryTest.php @@ -11,6 +11,8 @@ namespace Zenstruck\Foundry\Tests\Integration\Persistence; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Zenstruck\Foundry\Persistence\PersistentObjectFactory; use Zenstruck\Foundry\Story; @@ -56,6 +58,8 @@ public static function storiesProvider(): iterable * @test * @dataProvider storiesProvider */ + #[Test] + #[DataProvider('storiesProvider')] public function stories_only_loaded_once(string $story, string $factory): void { $factory::repository()->assert()->empty(); @@ -73,6 +77,8 @@ public function stories_only_loaded_once(string $story, string $factory): void * @test * @dataProvider storiesProvider */ + #[Test] + #[DataProvider('storiesProvider')] public function can_access_story_state(string $story): void { $this->assertSame('foo', $story::get('foo')->getProp1()); @@ -91,6 +97,8 @@ public function can_access_story_state(string $story): void * @test * @dataProvider storiesProvider */ + #[Test] + #[DataProvider('storiesProvider')] public function can_access_story_state_with_magic_call(string $story): void { $this->assertSame('foo', $story::foo()->getProp1()); @@ -109,6 +117,8 @@ public function can_access_story_state_with_magic_call(string $story): void * @test * @dataProvider storiesProvider */ + #[Test] + #[DataProvider('storiesProvider')] public function can_access_story_state_with_magic_call_on_instance(string $story): void { $this->assertSame('foo', $story::load()->foo()->getProp1()); @@ -127,6 +137,8 @@ public function can_access_story_state_with_magic_call_on_instance(string $story * @test * @dataProvider storiesProvider */ + #[Test] + #[DataProvider('storiesProvider')] public function cannot_access_invalid_object(string $story): void { $this->expectException(\InvalidArgumentException::class); @@ -154,6 +166,8 @@ public static function poolStoriesProvider(): iterable * @test * @dataProvider poolStoriesProvider */ + #[Test] + #[DataProvider('poolStoriesProvider')] public function can_get_random_object_set_from_pool(string $story): void { $objects = $story::getRandomSet($story, 2); @@ -167,6 +181,8 @@ public function can_get_random_object_set_from_pool(string $story): void * @test * @dataProvider poolStoriesProvider */ + #[Test] + #[DataProvider('poolStoriesProvider')] public function can_get_random_object_from_pool(string $story): void { $ids = []; @@ -184,6 +200,8 @@ public function can_get_random_object_from_pool(string $story): void * @test * @dataProvider poolStoriesProvider */ + #[Test] + #[DataProvider('poolStoriesProvider')] public function can_get_random_object_range_from_pool(string $story): void { $counts = []; @@ -206,6 +224,8 @@ public function can_get_random_object_range_from_pool(string $story): void * @test * @dataProvider poolStoriesProvider */ + #[Test] + #[DataProvider('poolStoriesProvider')] public function story_can_access_its_own_pool(string $story): void { $item = $story::get('random-from-own-pool'); @@ -218,6 +238,7 @@ public function story_can_access_its_own_pool(string $story): void /** * @test */ + #[Test] public function can_use_story_with_simple_object(): void { ObjectStory::load(); @@ -227,6 +248,7 @@ public function can_use_story_with_simple_object(): void /** * @test */ + #[Test] public function can_use_story_with_persistence_disabled(): void { PersistenceDisabledStory::load(); diff --git a/tests/Integration/RequiresMongo.php b/tests/Integration/RequiresMongo.php index 250a3fdaf..9af65c4c2 100644 --- a/tests/Integration/RequiresMongo.php +++ b/tests/Integration/RequiresMongo.php @@ -11,12 +11,18 @@ namespace Zenstruck\Foundry\Tests\Integration; +use PHPUnit\Framework\Attributes\BeforeClass; + /** * @author Kevin Bond */ trait RequiresMongo { - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + #[BeforeClass] + public static function _requiresMongo(): void { if (!\getenv('MONGO_URL')) { self::markTestSkipped('MongoDB not available.'); diff --git a/tests/Integration/RequiresORM.php b/tests/Integration/RequiresORM.php index 6da0bd0db..fe318f9f5 100644 --- a/tests/Integration/RequiresORM.php +++ b/tests/Integration/RequiresORM.php @@ -11,15 +11,23 @@ namespace Zenstruck\Foundry\Tests\Integration; +use PHPUnit\Framework\Attributes\BeforeClass; + /** * @author Kevin Bond */ trait RequiresORM { - public static function setUpBeforeClass(): void + /** + * @beforeClass + */ + #[BeforeClass] + public static function _requiresOrm(): void { if (!\getenv('DATABASE_URL')) { self::markTestSkipped('SQL database not available.'); } + + parent::setUpBeforeClass(); } } diff --git a/tests/Integration/ResetDatabase/GlobalStoryTest.php b/tests/Integration/ResetDatabase/GlobalStoryTest.php index c6d88124d..5e7f410b5 100644 --- a/tests/Integration/ResetDatabase/GlobalStoryTest.php +++ b/tests/Integration/ResetDatabase/GlobalStoryTest.php @@ -13,6 +13,7 @@ namespace Zenstruck\Foundry\Tests\Integration\ResetDatabase; +use PHPUnit\Framework\Attributes\Test; use Zenstruck\Foundry\Tests\Fixture\Document\GlobalDocument; use Zenstruck\Foundry\Tests\Fixture\Entity\GlobalEntity; use Zenstruck\Foundry\Tests\Fixture\FoundryTestKernel; @@ -25,6 +26,7 @@ final class GlobalStoryTest extends ResetDatabaseTestCase /** * @test */ + #[Test] public function global_stories_are_loaded(): void { if (FoundryTestKernel::hasORM()) { @@ -39,6 +41,7 @@ public function global_stories_are_loaded(): void /** * @test */ + #[Test] public function global_stories_cannot_be_loaded_again(): void { GlobalStory::load(); diff --git a/tests/Integration/ResetDatabase/ResetDatabaseTest.php b/tests/Integration/ResetDatabase/ResetDatabaseTest.php index 304a83e09..0377ef93f 100644 --- a/tests/Integration/ResetDatabase/ResetDatabaseTest.php +++ b/tests/Integration/ResetDatabase/ResetDatabaseTest.php @@ -13,6 +13,8 @@ namespace Zenstruck\Foundry\Tests\Integration\ResetDatabase; +use PHPUnit\Framework\Attributes\Depends; +use PHPUnit\Framework\Attributes\Test; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; @@ -35,6 +37,7 @@ final class ResetDatabaseTest extends ResetDatabaseTestCase /** * @test */ + #[Test] public function it_generates_valid_schema(): void { $application = new Application(self::bootKernel()); @@ -59,6 +62,7 @@ public function it_generates_valid_schema(): void /** * @test */ + #[Test] public function it_can_store_object(): void { if (FoundryTestKernel::hasORM()) { @@ -78,6 +82,8 @@ public function it_can_store_object(): void * @test * @depends it_can_store_object */ + #[Test] + #[Depends('it_can_store_object')] public function it_still_starts_from_fresh_db(): void { if (FoundryTestKernel::hasORM()) { @@ -92,6 +98,7 @@ public function it_still_starts_from_fresh_db(): void /** * @test */ + #[Test] public function can_create_object_in_another_schema(): void { if (!\str_starts_with(\getenv('DATABASE_URL') ?: '', 'postgresql')) { @@ -105,6 +112,7 @@ public function can_create_object_in_another_schema(): void /** * @test */ + #[Test] public function can_extend_orm_reset_mechanism_first(): void { if (!FoundryTestKernel::hasORM()) { @@ -127,6 +135,8 @@ public function can_extend_orm_reset_mechanism_first(): void * @test * @depends can_extend_orm_reset_mechanism_first */ + #[Test] + #[Depends('can_extend_orm_reset_mechanism_first')] public function can_extend_orm_reset_mechanism_second(): void { if (!FoundryTestKernel::hasORM()) { @@ -146,6 +156,7 @@ public function can_extend_orm_reset_mechanism_second(): void /** * @test */ + #[Test] public function can_extend_mongo_reset_mechanism_first(): void { if (!FoundryTestKernel::hasMongo()) { diff --git a/tests/Unit/ArrayFactoryTest.php b/tests/Unit/ArrayFactoryTest.php index 3dc8e74ed..b913e6082 100644 --- a/tests/Unit/ArrayFactoryTest.php +++ b/tests/Unit/ArrayFactoryTest.php @@ -11,6 +11,7 @@ namespace Zenstruck\Foundry\Tests\Unit; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Zenstruck\Foundry\LazyValue; use Zenstruck\Foundry\Test\Factories; @@ -26,6 +27,7 @@ final class ArrayFactoryTest extends TestCase /** * @test */ + #[Test] public function can_create_with_defaults(): void { $this->assertSame( @@ -42,6 +44,7 @@ public function can_create_with_defaults(): void /** * @test */ + #[Test] public function can_create_with_overrides(): void { $this->assertSame( @@ -61,6 +64,7 @@ public function can_create_with_overrides(): void /** * @test */ + #[Test] public function can_create_many(): void { $this->assertCount(2, ArrayFactory::createMany(2)); @@ -78,6 +82,7 @@ public function can_create_many(): void /** * @test */ + #[Test] public function can_create_range(): void { $range = ArrayFactory::createRange(2, 4); @@ -89,6 +94,7 @@ public function can_create_range(): void /** * @test */ + #[Test] public function can_create_sequence(): void { $sequence = ArrayFactory::createSequence([ diff --git a/tests/Unit/FactoryTest.php b/tests/Unit/FactoryTest.php index 925cde61a..0da2523ea 100644 --- a/tests/Unit/FactoryTest.php +++ b/tests/Unit/FactoryTest.php @@ -14,6 +14,7 @@ namespace Zenstruck\Foundry\Tests\Unit; use Faker; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Zenstruck\Foundry\Configuration; use Zenstruck\Foundry\Persistence\Proxy; @@ -48,6 +49,7 @@ protected function tearDown(): void /** * @test */ + #[Test] public function can_register_custom_faker(): void { $defaultFaker = faker(); @@ -61,6 +63,7 @@ public function can_register_custom_faker(): void /** * @test */ + #[Test] public function can_use_arrays_for_attribute_values(): void { $object = new class { @@ -75,6 +78,7 @@ public function can_use_arrays_for_attribute_values(): void /** * @test */ + #[Test] public function can_use_user_defined_proxy_persistent_factory_in_unit_test(): void { $object = GenericProxyEntityFactory::createOne(); @@ -86,6 +90,7 @@ public function can_use_user_defined_proxy_persistent_factory_in_unit_test(): vo /** * @test */ + #[Test] public function can_use_user_anonymous_proxy_persistent_factory_in_unit_test(): void { $object = proxy_factory(GenericEntity::class, ['prop1' => 'prop1'])->create(); @@ -97,6 +102,7 @@ public function can_use_user_anonymous_proxy_persistent_factory_in_unit_test(): /** * @test */ + #[Test] public function can_register_default_instantiator(): void { UnitTestConfig::configure(instantiator: static fn(): Object1 => new Object1( @@ -113,6 +119,7 @@ public function can_register_default_instantiator(): void /** * @test */ + #[Test] public function proxy_attributes_can_be_used_in_unit_test(): void { $object = ProxyContactFactory::createOne([ @@ -126,6 +133,7 @@ public function proxy_attributes_can_be_used_in_unit_test(): void /** * @test */ + #[Test] public function instantiating_with_factory_attribute_instantiates_the_factory(): void { $object = ContactFactory::createOne([ @@ -138,6 +146,7 @@ public function instantiating_with_factory_attribute_instantiates_the_factory(): /** * @test */ + #[Test] public function instantiating_with_proxy_attribute_normalizes_to_underlying_object(): void { $object = ProxyContactFactory::createOne([ diff --git a/tests/Unit/InstantiatorTest.php b/tests/Unit/InstantiatorTest.php index ee73d1c66..98e6d363a 100644 --- a/tests/Unit/InstantiatorTest.php +++ b/tests/Unit/InstantiatorTest.php @@ -13,6 +13,7 @@ namespace Zenstruck\Foundry\Tests\Unit; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Zenstruck\Foundry\Object\Instantiator; @@ -21,6 +22,7 @@ final class InstantiatorTest extends TestCase /** * @test */ + #[Test] public function can_set_variadic_constructor_attributes(): void { $object = Instantiator::withConstructor()([ diff --git a/tests/Unit/LazyValueTest.php b/tests/Unit/LazyValueTest.php index 95a580310..a9d23bfd7 100644 --- a/tests/Unit/LazyValueTest.php +++ b/tests/Unit/LazyValueTest.php @@ -11,6 +11,7 @@ namespace Zenstruck\Foundry\Tests\Unit; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Zenstruck\Foundry\LazyValue; @@ -25,6 +26,7 @@ final class LazyValueTest extends TestCase /** * @test */ + #[Test] public function lazy(): void { $value = lazy(fn() => new \stdClass()); @@ -35,6 +37,7 @@ public function lazy(): void /** * @test */ + #[Test] public function memoize(): void { $value = memoize(fn() => new \stdClass()); @@ -45,6 +48,7 @@ public function memoize(): void /** * @test */ + #[Test] public function can_handle_nested_lazy_values(): void { $value = LazyValue::new(LazyValue::new(LazyValue::new(fn() => LazyValue::new(fn() => 'foo')))); @@ -55,6 +59,7 @@ public function can_handle_nested_lazy_values(): void /** * @test */ + #[Test] public function can_handle_array_with_lazy_values(): void { $value = LazyValue::new(fn() => [ diff --git a/tests/Unit/ObjectFactoryTest.php b/tests/Unit/ObjectFactoryTest.php index ffb33dc96..7e80ce14e 100644 --- a/tests/Unit/ObjectFactoryTest.php +++ b/tests/Unit/ObjectFactoryTest.php @@ -11,6 +11,8 @@ namespace Zenstruck\Foundry\Tests\Unit; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Zenstruck\Foundry\Factory; use Zenstruck\Foundry\Object\Instantiator; @@ -36,6 +38,7 @@ final class ObjectFactoryTest extends TestCase /** * @test */ + #[Test] public function defaults(): void { $object = Object1Factory::createOne(); @@ -48,6 +51,7 @@ public function defaults(): void /** * @test */ + #[Test] public function named_constructor_defaults(): void { $object = Object1Factory::new()->instantiateWith(Instantiator::namedConstructor('factory'))->create(); @@ -60,6 +64,7 @@ public function named_constructor_defaults(): void /** * @test */ + #[Test] public function default_instantiator_and_hydrator(): void { $object = Object1Factory::createOne([ @@ -76,6 +81,7 @@ public function default_instantiator_and_hydrator(): void /** * @test */ + #[Test] public function without_constructor_instantiator(): void { $object = Object1Factory::new()->instantiateWith(Instantiator::withoutConstructor())->create([ @@ -92,6 +98,7 @@ public function without_constructor_instantiator(): void /** * @test */ + #[Test] public function with_closure_factory_constructor(): void { $object = Object1Factory::new() @@ -111,6 +118,7 @@ public function with_closure_factory_constructor(): void /** * @test */ + #[Test] public function with_method_factory_constructor(): void { $object = Object1Factory::new() @@ -130,6 +138,7 @@ public function with_method_factory_constructor(): void /** * @test */ + #[Test] public function with_named_constructor_instantiator(): void { $object = Object1Factory::new()->instantiateWith(Instantiator::namedConstructor('factory'))->create([ @@ -146,6 +155,7 @@ public function with_named_constructor_instantiator(): void /** * @test */ + #[Test] public function with_extra_and_force_mode_without_constructor(): void { $object = Object1Factory::new() @@ -166,6 +176,7 @@ public function with_extra_and_force_mode_without_constructor(): void /** * @test */ + #[Test] public function with_configured_hydrator(): void { $object = Object1Factory::new() @@ -186,6 +197,7 @@ public function with_configured_hydrator(): void /** * @test */ + #[Test] public function with_hydration_disabled(): void { $object = Object1Factory::new() @@ -206,6 +218,7 @@ public function with_hydration_disabled(): void /** * @test */ + #[Test] public function with_custom_instantiator_callable(): void { $object = Object1Factory::new() @@ -226,6 +239,7 @@ public function with_custom_instantiator_callable(): void /** * @test */ + #[Test] public function before_instantiate_hook(): void { $object = Object1Factory::new() @@ -250,6 +264,7 @@ public function before_instantiate_hook(): void /** * @test */ + #[Test] public function after_instantiate_hook(): void { $object = Object1Factory::new() @@ -269,6 +284,7 @@ public function after_instantiate_hook(): void /** * @test */ + #[Test] public function create_anonymous_factory(): void { $object = factory(Object1::class, ['prop1' => 'value1'])->create(['prop2' => 'value2']); @@ -293,6 +309,7 @@ public function create_anonymous_factory(): void /** * @test */ + #[Test] public function object_factories_are_converted(): void { $object = Object2Factory::createOne(); @@ -303,6 +320,7 @@ public function object_factories_are_converted(): void /** * @test */ + #[Test] public function can_create_many(): void { $objects = Object1Factory::createMany(3, fn(int $i) => ['prop1' => "value{$i}"]); @@ -323,6 +341,7 @@ public function can_create_many(): void /** * @test */ + #[Test] public function set_and_get_functions(): void { $object = new Object1('value'); @@ -341,6 +360,8 @@ public function set_and_get_functions(): void * * @test */ + #[Test] + #[DataProvider('sequenceDataProvider')] public function can_create_sequence(iterable|callable $sequence): void { self::assertEquals( @@ -392,6 +413,7 @@ static function() { /** * @test */ + #[Test] public function can_use_sequence_with_associative_array(): void { self::assertEquals( @@ -415,6 +437,7 @@ public function can_use_sequence_with_associative_array(): void /** * @test */ + #[Test] public function as_data_provider(): void { $this->markTestIncomplete(); diff --git a/tests/Unit/Persistence/PersistentObjectFactoryTest.php b/tests/Unit/Persistence/PersistentObjectFactoryTest.php index 073097f98..d299f330e 100644 --- a/tests/Unit/Persistence/PersistentObjectFactoryTest.php +++ b/tests/Unit/Persistence/PersistentObjectFactoryTest.php @@ -11,6 +11,7 @@ namespace Zenstruck\Foundry\Tests\Unit\Persistence; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Zenstruck\Foundry\Test\Factories; use Zenstruck\Foundry\Tests\Fixture\Entity\GenericEntity; @@ -26,6 +27,7 @@ final class PersistentObjectFactoryTest extends TestCase /** * @test */ + #[Test] public function can_create(): void { $entity1 = GenericEntityFactory::createOne(); @@ -42,6 +44,7 @@ public function can_create(): void /** * @test */ + #[Test] public function find_or_create(): void { $entity = GenericEntityFactory::findOrCreate(['prop1' => 'foo']); @@ -52,6 +55,7 @@ public function find_or_create(): void /** * @test */ + #[Test] public function random_or_create(): void { $entity = GenericEntityFactory::randomOrCreate(['prop1' => 'foo']); diff --git a/tests/Unit/Persistence/ProxyGeneratorTest.php b/tests/Unit/Persistence/ProxyGeneratorTest.php index 068d9a5d3..fb31a7975 100644 --- a/tests/Unit/Persistence/ProxyGeneratorTest.php +++ b/tests/Unit/Persistence/ProxyGeneratorTest.php @@ -13,6 +13,8 @@ namespace Zenstruck\Foundry\Tests\Unit\Persistence; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Zenstruck\Foundry\Persistence\ProxyGenerator; @@ -25,6 +27,8 @@ final class ProxyGeneratorTest extends TestCase * @test * @dataProvider classWithUnserializeMagicMethodProvider */ + #[Test] + #[DataProvider('classWithUnserializeMagicMethodProvider')] public function it_can_generate_proxy_for_class_with_unserialize_magic_method(object $obj): void { $proxyfiedObj = ProxyGenerator::wrap($obj);