From f31a249f3a74a5fbdc265821f20ad81f8f4ed569 Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 8 Feb 2024 07:30:39 +0100 Subject: [PATCH 01/12] Replace annotations with attributes --- composer.json | 5 ++-- .../CircularRelations/A.php | 16 +++++-------- .../CircularRelations/B.php | 16 +++++-------- .../CircularRelations/C.php | 18 +++++--------- .../CompositePrimaryKeyEntity.php | 17 ++++--------- .../EntityWithConstructorParameters.php | 24 ++++++------------- .../EntityWithEmbeddable.php | 17 ++++--------- .../doctrine2_entities/EntityWithUuid.php | 15 +++++------- .../data/doctrine2_entities/JoinedEntity.php | 8 ++----- .../doctrine2_entities/JoinedEntityBase.php | 18 +++++--------- .../MultilevelRelations/A.php | 18 +++++--------- .../MultilevelRelations/B.php | 23 ++++++------------ .../MultilevelRelations/C.php | 20 +++++----------- .../NonTypicalPrimaryKeyEntity.php | 10 +++----- tests/data/doctrine2_entities/PlainEntity.php | 16 ++++--------- .../QuirkyFieldName/Association.php | 16 ++++--------- .../QuirkyFieldName/AssociationHost.php | 20 +++++----------- .../QuirkyFieldName/Embeddable.php | 8 ++----- .../QuirkyFieldName/EmbeddableHost.php | 20 +++++----------- .../doctrine2_entities/SampleEmbeddable.php | 8 ++----- .../unit/Codeception/Module/Doctrine2Test.php | 16 +++++-------- 21 files changed, 105 insertions(+), 224 deletions(-) diff --git a/composer.json b/composer.json index 1cc878a..5963b3e 100644 --- a/composer.json +++ b/composer.json @@ -24,11 +24,10 @@ }, "require-dev": { "codeception/stub": "^4.0", - "doctrine/annotations": "^1.13", "doctrine/data-fixtures": "^1.5", - "doctrine/orm": "^2.10", + "doctrine/orm": "^2.14", "phpstan/phpstan": "^1.0", - "ramsey/uuid-doctrine": "^1.6", + "ramsey/uuid-doctrine": "^2.0", "symfony/cache": "^4.4 || ^5.4 || ^6.0" }, "conflict": { diff --git a/tests/data/doctrine2_entities/CircularRelations/A.php b/tests/data/doctrine2_entities/CircularRelations/A.php index 4ba59e5..ebfba13 100644 --- a/tests/data/doctrine2_entities/CircularRelations/A.php +++ b/tests/data/doctrine2_entities/CircularRelations/A.php @@ -6,23 +6,19 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - * @ORM\Table(name="circular_a") - */ +#[ORM\Entity] +#[ORM\Table(name: 'circular_a')] class A { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue] private ?int $id = null; /** * @var ArrayCollection - * @ORM\OneToMany(targetEntity="C", mappedBy="a") */ + #[ORM\OneToMany(targetEntity: C::class, mappedBy: 'a')] private Collection $cs; public function __construct() diff --git a/tests/data/doctrine2_entities/CircularRelations/B.php b/tests/data/doctrine2_entities/CircularRelations/B.php index 09f1006..3f95d3d 100644 --- a/tests/data/doctrine2_entities/CircularRelations/B.php +++ b/tests/data/doctrine2_entities/CircularRelations/B.php @@ -6,23 +6,19 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - * @ORM\Table(name="circular_b") - */ +#[ORM\Entity] +#[ORM\Table(name: 'circular_b')] class B { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue] private ?int $id = null; /** * @var ArrayCollection - * @ORM\OneToMany(targetEntity="C", mappedBy="b") */ + #[ORM\OneToMany(targetEntity: C::class, mappedBy: 'b')] private Collection $cs; public function __construct() diff --git a/tests/data/doctrine2_entities/CircularRelations/C.php b/tests/data/doctrine2_entities/CircularRelations/C.php index 6967b21..98cb35c 100644 --- a/tests/data/doctrine2_entities/CircularRelations/C.php +++ b/tests/data/doctrine2_entities/CircularRelations/C.php @@ -4,22 +4,16 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - * @ORM\Table(name="circular_c") - */ +#[ORM\Entity] +#[ORM\Table(name: 'circular_c')] class C { - /** - * @ORM\Id - * @ORM\ManyToOne(targetEntity="A", inversedBy="cs", cascade={"persist"}) - */ + #[ORM\Id] + #[ORM\ManyToOne(targetEntity: A::class, inversedBy: 'cs', cascade: ['persist'])] private ?A $a; - /** - * @ORM\Id - * @ORM\ManyToOne(targetEntity="B", inversedBy="cs", cascade={"persist"}) - */ + #[ORM\Id] + #[ORM\ManyToOne(targetEntity: B::class, inversedBy: 'cs', cascade: ['persist'])] private ?B $b; public function __construct(A $a, B $b) diff --git a/tests/data/doctrine2_entities/CompositePrimaryKeyEntity.php b/tests/data/doctrine2_entities/CompositePrimaryKeyEntity.php index ee3d6f1..184560a 100644 --- a/tests/data/doctrine2_entities/CompositePrimaryKeyEntity.php +++ b/tests/data/doctrine2_entities/CompositePrimaryKeyEntity.php @@ -2,21 +2,14 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class CompositePrimaryKeyEntity { - /** - * @ORM\Id - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] private int $integerPart; - /** - * - * @ORM\Id - * @ORM\Column(type="string") - */ + #[ORM\Id] + #[ORM\Column(type: 'string')] private string $stringPart; } diff --git a/tests/data/doctrine2_entities/EntityWithConstructorParameters.php b/tests/data/doctrine2_entities/EntityWithConstructorParameters.php index f40518d..c4caa5c 100644 --- a/tests/data/doctrine2_entities/EntityWithConstructorParameters.php +++ b/tests/data/doctrine2_entities/EntityWithConstructorParameters.php @@ -2,31 +2,21 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class EntityWithConstructorParameters { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue] private int $id; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] private ?string $name = null; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] private ?string $foo = null; - /** - * @ORM\Column(type="string") - */ + #[ORM\Column(type: 'string')] private string $bar = ''; public function __construct($name, $foo = null, $bar = 'foobar') diff --git a/tests/data/doctrine2_entities/EntityWithEmbeddable.php b/tests/data/doctrine2_entities/EntityWithEmbeddable.php index e832244..11d98d7 100644 --- a/tests/data/doctrine2_entities/EntityWithEmbeddable.php +++ b/tests/data/doctrine2_entities/EntityWithEmbeddable.php @@ -2,22 +2,15 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class EntityWithEmbeddable { - /** - * - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue] private int $id; - /** - * @ORM\Embedded(class="SampleEmbeddable") - */ + #[ORM\Embedded(class: SampleEmbeddable::class)] private SampleEmbeddable $embed; public function __construct() diff --git a/tests/data/doctrine2_entities/EntityWithUuid.php b/tests/data/doctrine2_entities/EntityWithUuid.php index ae2531e..fb67ff0 100644 --- a/tests/data/doctrine2_entities/EntityWithUuid.php +++ b/tests/data/doctrine2_entities/EntityWithUuid.php @@ -2,19 +2,16 @@ use Doctrine\ORM\Mapping as ORM; use Ramsey\Uuid\Uuid; +use Ramsey\Uuid\Doctrine\UuidGenerator; use Ramsey\Uuid\UuidInterface; -/** - * @ORM\Entity - */ +#[ORM\Entity] class EntityWithUuid { - /** - * @ORM\Id - * @ORM\Column(type="uuid", unique=true) - * @ORM\GeneratedValue(strategy="CUSTOM") - * @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator") - */ + #[ORM\Id] + #[ORM\Column(type: 'uuid', unique: true)] + #[ORM\GeneratedValue(strategy: 'CUSTOM')] + #[ORM\CustomIdGenerator(class: UuidGenerator::class)] private ?UuidInterface $id = null; public function __construct() diff --git a/tests/data/doctrine2_entities/JoinedEntity.php b/tests/data/doctrine2_entities/JoinedEntity.php index 15ef7cf..1eb7241 100644 --- a/tests/data/doctrine2_entities/JoinedEntity.php +++ b/tests/data/doctrine2_entities/JoinedEntity.php @@ -2,13 +2,9 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class JoinedEntity extends JoinedEntityBase { - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] private ?string $own = null; } diff --git a/tests/data/doctrine2_entities/JoinedEntityBase.php b/tests/data/doctrine2_entities/JoinedEntityBase.php index 9865640..c7d0170 100644 --- a/tests/data/doctrine2_entities/JoinedEntityBase.php +++ b/tests/data/doctrine2_entities/JoinedEntityBase.php @@ -2,21 +2,15 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - * @ORM\InheritanceType("JOINED") - */ +#[ORM\Entity] +#[ORM\InheritanceType('JOINED')] class JoinedEntityBase { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue] private int $id; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] private ?string $inherited = null; } diff --git a/tests/data/doctrine2_entities/MultilevelRelations/A.php b/tests/data/doctrine2_entities/MultilevelRelations/A.php index 91b74e7..a3c2bc1 100644 --- a/tests/data/doctrine2_entities/MultilevelRelations/A.php +++ b/tests/data/doctrine2_entities/MultilevelRelations/A.php @@ -6,27 +6,21 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class A { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue] private int $id; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] private ?string $name = null; /** * @var Collection|B[] - * @ORM\OneToMany(targetEntity="B", mappedBy="a") */ + #[ORM\OneToMany(targetEntity: B::class, mappedBy: 'a')] private Collection $b; public function __construct() diff --git a/tests/data/doctrine2_entities/MultilevelRelations/B.php b/tests/data/doctrine2_entities/MultilevelRelations/B.php index 92bcd53..e6378f5 100644 --- a/tests/data/doctrine2_entities/MultilevelRelations/B.php +++ b/tests/data/doctrine2_entities/MultilevelRelations/B.php @@ -6,33 +6,24 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class B { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue] private int $id; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] private ?string $name = null; - /** - * @ORM\ManyToOne(targetEntity="A") - */ + #[ORM\ManyToOne(targetEntity: A::class)] private ?A $a = null; /** * @var Collection|C[] - * - * @ORM\OneToMany(targetEntity="C", mappedBy="b") */ + #[ORM\OneToMany(targetEntity: C::class, mappedBy: 'b')] private Collection $c; public function __construct() diff --git a/tests/data/doctrine2_entities/MultilevelRelations/C.php b/tests/data/doctrine2_entities/MultilevelRelations/C.php index f7846dd..d874fb5 100644 --- a/tests/data/doctrine2_entities/MultilevelRelations/C.php +++ b/tests/data/doctrine2_entities/MultilevelRelations/C.php @@ -4,26 +4,18 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class C { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue] private int $id; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] private ?string $name = null; - /** - * @ORM\ManyToOne(targetEntity="B") - */ + #[ORM\ManyToOne(targetEntity: B::class)] private ?B $b = null; public function getB(): ?B diff --git a/tests/data/doctrine2_entities/NonTypicalPrimaryKeyEntity.php b/tests/data/doctrine2_entities/NonTypicalPrimaryKeyEntity.php index ba96369..f756769 100644 --- a/tests/data/doctrine2_entities/NonTypicalPrimaryKeyEntity.php +++ b/tests/data/doctrine2_entities/NonTypicalPrimaryKeyEntity.php @@ -2,14 +2,10 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class NonTypicalPrimaryKeyEntity { - /** - * @ORM\Id - * @ORM\Column(type="string") - */ + #[ORM\Id] + #[ORM\Column(type: 'string')] private string $primaryKey; } diff --git a/tests/data/doctrine2_entities/PlainEntity.php b/tests/data/doctrine2_entities/PlainEntity.php index 7d28aad..54eece6 100644 --- a/tests/data/doctrine2_entities/PlainEntity.php +++ b/tests/data/doctrine2_entities/PlainEntity.php @@ -2,21 +2,15 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class PlainEntity { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue] private ?int $id = null; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] private ?string $name = null; public function getId(): ?int diff --git a/tests/data/doctrine2_entities/QuirkyFieldName/Association.php b/tests/data/doctrine2_entities/QuirkyFieldName/Association.php index a8e39e0..daa9427 100644 --- a/tests/data/doctrine2_entities/QuirkyFieldName/Association.php +++ b/tests/data/doctrine2_entities/QuirkyFieldName/Association.php @@ -4,21 +4,15 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class Association { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue] private ?int $id = null; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] private ?string $val = null; public function getId(): ?int diff --git a/tests/data/doctrine2_entities/QuirkyFieldName/AssociationHost.php b/tests/data/doctrine2_entities/QuirkyFieldName/AssociationHost.php index d02f0fe..d071ab7 100644 --- a/tests/data/doctrine2_entities/QuirkyFieldName/AssociationHost.php +++ b/tests/data/doctrine2_entities/QuirkyFieldName/AssociationHost.php @@ -4,26 +4,18 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class AssociationHost { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue] private ?int $id = null; - /** - * @ORM\OneToOne(targetEntity="Association") - */ + #[ORM\OneToOne(targetEntity: Association::class)] private ?Association $assoc = null; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] private ?string $_assoc_val = null; public function getId(): ?int diff --git a/tests/data/doctrine2_entities/QuirkyFieldName/Embeddable.php b/tests/data/doctrine2_entities/QuirkyFieldName/Embeddable.php index 64a9780..c60c555 100644 --- a/tests/data/doctrine2_entities/QuirkyFieldName/Embeddable.php +++ b/tests/data/doctrine2_entities/QuirkyFieldName/Embeddable.php @@ -4,13 +4,9 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Embeddable - */ +#[ORM\Embeddable] class Embeddable { - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] private ?string $val = null; } diff --git a/tests/data/doctrine2_entities/QuirkyFieldName/EmbeddableHost.php b/tests/data/doctrine2_entities/QuirkyFieldName/EmbeddableHost.php index 67e2057..22ee2b7 100644 --- a/tests/data/doctrine2_entities/QuirkyFieldName/EmbeddableHost.php +++ b/tests/data/doctrine2_entities/QuirkyFieldName/EmbeddableHost.php @@ -4,26 +4,18 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class EmbeddableHost { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue] private int $id; - /** - * @ORM\Embedded(class="Embeddable") - */ + #[ORM\Embedded(class: Embeddable::class)] private Embeddable $embed; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] private ?string $embedval = null; public function __construct() diff --git a/tests/data/doctrine2_entities/SampleEmbeddable.php b/tests/data/doctrine2_entities/SampleEmbeddable.php index dd6fd25..12264c1 100644 --- a/tests/data/doctrine2_entities/SampleEmbeddable.php +++ b/tests/data/doctrine2_entities/SampleEmbeddable.php @@ -2,13 +2,9 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Embeddable - */ +#[ORM\Embeddable] class SampleEmbeddable { - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] private ?string $val = null; } diff --git a/tests/unit/Codeception/Module/Doctrine2Test.php b/tests/unit/Codeception/Module/Doctrine2Test.php index a78f993..bf81360 100644 --- a/tests/unit/Codeception/Module/Doctrine2Test.php +++ b/tests/unit/Codeception/Module/Doctrine2Test.php @@ -11,11 +11,12 @@ use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\Loader; use Doctrine\Common\DataFixtures\Purger\ORMPurger; +use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\ORMException; +use Doctrine\ORM\Exception\ORMException; +use Doctrine\ORM\ORMSetup; use Doctrine\ORM\Tools\SchemaTool; -use Doctrine\ORM\Tools\Setup; use MultilevelRelations\A; use MultilevelRelations\B; use MultilevelRelations\C; @@ -48,10 +49,6 @@ protected function _setUp() $this->markTestSkipped('doctrine/orm is not installed'); } - if (!class_exists(Doctrine\Common\Annotations\Annotation::class)) { - $this->markTestSkipped('doctrine/annotations is not installed'); - } - $dir = __DIR__ . "/../../../data/doctrine2_entities"; require_once $dir . "/CompositePrimaryKeyEntity.php"; @@ -73,10 +70,9 @@ protected function _setUp() require_once $dir . "/CircularRelations/C.php"; require_once $dir . '/EntityWithUuid.php'; - - $this->em = EntityManager::create( - ['url' => 'sqlite:///:memory:'], - Setup::createAnnotationMetadataConfiguration([$dir], true, null, null, false) + $this->em = new EntityManager( + DriverManager::getConnection(['url' => 'sqlite:///:memory:']), + ORMSetup::createAttributeMetadataConfiguration([$dir], true) ); (new SchemaTool($this->em))->createSchema([ From 43adc5b64109a564bc00f996224c362c614e2eac Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 8 Feb 2024 07:32:36 +0100 Subject: [PATCH 02/12] Allow symfony 7 in dev --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5963b3e..ef75b85 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "doctrine/orm": "^2.14", "phpstan/phpstan": "^1.0", "ramsey/uuid-doctrine": "^2.0", - "symfony/cache": "^4.4 || ^5.4 || ^6.0" + "symfony/cache": "^4.4 || ^5.4 || ^6.0 || ^7.0" }, "conflict": { "codeception/codeception": "<5.0" From ff27140c4ebbe013248a4fcdb42d6e2d0adc76c4 Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 8 Feb 2024 07:32:54 +0100 Subject: [PATCH 03/12] Allow doctrine/orm v3 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ef75b85..1fcb9ab 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "require-dev": { "codeception/stub": "^4.0", "doctrine/data-fixtures": "^1.5", - "doctrine/orm": "^2.14", + "doctrine/orm": "^2.14 || ^3.0", "phpstan/phpstan": "^1.0", "ramsey/uuid-doctrine": "^2.0", "symfony/cache": "^4.4 || ^5.4 || ^6.0 || ^7.0" From 2a8c1f9cd9e2e9b775c6e7b4a2d8b7beba6492a4 Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 8 Feb 2024 07:55:58 +0100 Subject: [PATCH 04/12] Do not try to modify EntityManager::$repositoryFactory in doctrine/orm:3 because the property became readonly --- src/Codeception/Module/Doctrine2.php | 14 +++++++++++--- tests/unit/Codeception/Module/Doctrine2Test.php | 5 +++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Codeception/Module/Doctrine2.php b/src/Codeception/Module/Doctrine2.php index e46a0b3..fa98e9b 100644 --- a/src/Codeception/Module/Doctrine2.php +++ b/src/Codeception/Module/Doctrine2.php @@ -401,7 +401,15 @@ public function haveFakeRepository(string $className, array $methods = []): void $reflectedRepositoryFactory = new ReflectionClass($repositoryFactory); - if ($reflectedRepositoryFactory->hasProperty('repositoryList')) { + // Do not call $reflectedRepositoryFactory->isReadOnly() directly because + // phpstan will complain about a non-existing method when using PHP 8.0. + // isReadOnly() is available as-of PHP 8.1. + if ($reflectedRepositoryFactory->hasMethod('isReadOnly') && $reflectedRepositoryFactory->getMethod('isReadOnly')->invoke(null)) { + $this->debugSection( + 'Warning', + 'Repository can\'t be mocked, the EntityManager\'s repositoryFactory is readonly' + ); + } elseif ($reflectedRepositoryFactory->hasProperty('repositoryList')) { $repositoryListProperty = $reflectedRepositoryFactory->getProperty('repositoryList'); $repositoryListProperty->setAccessible(true); @@ -415,13 +423,13 @@ public function haveFakeRepository(string $className, array $methods = []): void } else { $this->debugSection( 'Warning', - 'Repository can\'t be mocked, the EventManager\'s repositoryFactory doesn\'t have "repositoryList" property' + 'Repository can\'t be mocked, the EntityManager\'s repositoryFactory doesn\'t have "repositoryList" property' ); } } else { $this->debugSection( 'Warning', - 'Repository can\'t be mocked, the EventManager class doesn\'t have "repositoryFactory" or "repositories" property' + 'Repository can\'t be mocked, the EntityManager class doesn\'t have "repositoryFactory" or "repositories" property' ); } } diff --git a/tests/unit/Codeception/Module/Doctrine2Test.php b/tests/unit/Codeception/Module/Doctrine2Test.php index bf81360..b08e957 100644 --- a/tests/unit/Codeception/Module/Doctrine2Test.php +++ b/tests/unit/Codeception/Module/Doctrine2Test.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use Composer\InstalledVersions; use Codeception\Exception\ModuleException; use Codeception\Lib\ModuleContainer; use Codeception\Module\Doctrine2; @@ -564,6 +565,10 @@ public function testOneToManyRecursiveEntityCreation() public function testHaveFakeRepository() { + if (version_compare(InstalledVersions::getVersion('doctrine/orm'), '3', '>=')) { + $this->markTestSkipped('haveFakeRepository() is not supported for doctrine/orm:3 or higher'); + } + $e1 = new PlainEntity(); $e2 = new PlainEntity(); $this->module->haveFakeRepository(PlainEntity::class, [ From 964938f9bfaf23ab05c2c9ffa92cee61bedee597 Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 8 Feb 2024 08:20:41 +0100 Subject: [PATCH 05/12] Replace ramsey/uuid-doctrine with symfony/doctrine-bridge and symfony/uuid which do not block doctrine/dbal:4 --- composer.json | 5 +++-- tests/data/doctrine2_entities/EntityWithUuid.php | 11 +++++------ tests/unit/Codeception/Module/Doctrine2Test.php | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 1fcb9ab..095520c 100644 --- a/composer.json +++ b/composer.json @@ -27,8 +27,9 @@ "doctrine/data-fixtures": "^1.5", "doctrine/orm": "^2.14 || ^3.0", "phpstan/phpstan": "^1.0", - "ramsey/uuid-doctrine": "^2.0", - "symfony/cache": "^4.4 || ^5.4 || ^6.0 || ^7.0" + "symfony/cache": "^4.4 || ^5.4 || ^6.0 || ^7.0", + "symfony/doctrine-bridge": "^5.4 || ^6.4 || ^7.0", + "symfony/uid": "^5.4 || ^6.4 || ^7.0" }, "conflict": { "codeception/codeception": "<5.0" diff --git a/tests/data/doctrine2_entities/EntityWithUuid.php b/tests/data/doctrine2_entities/EntityWithUuid.php index fb67ff0..fef889f 100644 --- a/tests/data/doctrine2_entities/EntityWithUuid.php +++ b/tests/data/doctrine2_entities/EntityWithUuid.php @@ -1,9 +1,8 @@ id = Uuid::uuid4(); + $this->id = Uuid::v4(); } - public function getId(): UuidInterface + public function getId(): Uuid { return $this->id; } diff --git a/tests/unit/Codeception/Module/Doctrine2Test.php b/tests/unit/Codeception/Module/Doctrine2Test.php index b08e957..1a4eca8 100644 --- a/tests/unit/Codeception/Module/Doctrine2Test.php +++ b/tests/unit/Codeception/Module/Doctrine2Test.php @@ -25,8 +25,8 @@ use QuirkyFieldName\AssociationHost; use QuirkyFieldName\Embeddable; use QuirkyFieldName\EmbeddableHost; -use Ramsey\Uuid\Doctrine\UuidType; -use Ramsey\Uuid\UuidInterface; +use Symfony\Bridge\Doctrine\Types\UuidType; +use Symfony\Component\Uid\Uuid; final class Doctrine2Test extends Unit { @@ -418,13 +418,13 @@ public function testCompositePrimaryKeyWithEntities() /** * The purpose of this test is to verify that entites with object @id, that are - * not entites itself, e.g. Ramsey\Uuid\UuidInterface, don't break the debug message. + * not entites itself, e.g. Symfony\Component\Uid\Uuid, don't break the debug message. */ public function testDebugEntityWithNonEntityButObjectId() { $pk = $this->module->haveInRepository(EntityWithUuid::class); - self::assertInstanceOf(UuidInterface::class, $pk); + self::assertInstanceOf(Uuid::class, $pk); } public function testRefresh() From 07e1254640d219374b47c360d51045752eae507a Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 8 Feb 2024 08:34:05 +0100 Subject: [PATCH 06/12] Fix compatibility with doctrine/dbal v4 --- tests/unit/Codeception/Module/Doctrine2Test.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/unit/Codeception/Module/Doctrine2Test.php b/tests/unit/Codeception/Module/Doctrine2Test.php index 1a4eca8..a965e7e 100644 --- a/tests/unit/Codeception/Module/Doctrine2Test.php +++ b/tests/unit/Codeception/Module/Doctrine2Test.php @@ -13,6 +13,7 @@ use Doctrine\Common\DataFixtures\Loader; use Doctrine\Common\DataFixtures\Purger\ORMPurger; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Tools\DsnParser; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Exception\ORMException; @@ -71,8 +72,9 @@ protected function _setUp() require_once $dir . "/CircularRelations/C.php"; require_once $dir . '/EntityWithUuid.php'; + $dsnParser = new DsnParser(); $this->em = new EntityManager( - DriverManager::getConnection(['url' => 'sqlite:///:memory:']), + DriverManager::getConnection($dsnParser->parse('sqlite3:///:memory:')), ORMSetup::createAttributeMetadataConfiguration([$dir], true) ); @@ -438,7 +440,7 @@ public function testRefresh() $this->assertSame($original, $this->module->grabEntityFromRepository(PlainEntity::class, ['id' => $id])); // Here comes external change: - $this->em->getConnection()->executeUpdate('UPDATE PlainEntity SET name = ? WHERE id = ?', ['b', $id]); + $this->em->getConnection()->executeStatement('UPDATE PlainEntity SET name = ? WHERE id = ?', ['b', $id]); // Our original entity still has old data: $this->assertSame('a', $original->getName()); @@ -468,7 +470,7 @@ public function testRefreshingMultipleEntities() $b = new PlainEntity; $this->module->haveInRepository($b, ['name' => 'b']); - $this->em->getConnection()->executeUpdate('UPDATE PlainEntity SET name = ?', ['c']); + $this->em->getConnection()->executeStatement('UPDATE PlainEntity SET name = ?', ['c']); $this->assertSame('a', $a->getName()); $this->assertSame('b', $b->getName()); From 50725526fe74af06dfe9f8cbb91f5bdca2bf0afd Mon Sep 17 00:00:00 2001 From: Viktor Truhanovich Date: Mon, 4 Sep 2023 16:41:24 +0300 Subject: [PATCH 07/12] Changed use of deprecated doctrine/orm connect method to use getNativeConnection method --- src/Codeception/Module/Doctrine2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Codeception/Module/Doctrine2.php b/src/Codeception/Module/Doctrine2.php index fa98e9b..fc7225e 100644 --- a/src/Codeception/Module/Doctrine2.php +++ b/src/Codeception/Module/Doctrine2.php @@ -257,7 +257,7 @@ protected function retrieveEntityManager(): void ); } - $this->em->getConnection()->connect(); + $this->em->getConnection()->getNativeConnection(); } /** From 6142e75f6ff0ff96f26b8c01b440d3fb94c142d3 Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 8 Feb 2024 13:55:15 +0100 Subject: [PATCH 08/12] Simplify DBAL connection parameters --- tests/unit/Codeception/Module/Doctrine2Test.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/unit/Codeception/Module/Doctrine2Test.php b/tests/unit/Codeception/Module/Doctrine2Test.php index a965e7e..ea645bd 100644 --- a/tests/unit/Codeception/Module/Doctrine2Test.php +++ b/tests/unit/Codeception/Module/Doctrine2Test.php @@ -13,7 +13,6 @@ use Doctrine\Common\DataFixtures\Loader; use Doctrine\Common\DataFixtures\Purger\ORMPurger; use Doctrine\DBAL\DriverManager; -use Doctrine\DBAL\Tools\DsnParser; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Exception\ORMException; @@ -72,9 +71,8 @@ protected function _setUp() require_once $dir . "/CircularRelations/C.php"; require_once $dir . '/EntityWithUuid.php'; - $dsnParser = new DsnParser(); $this->em = new EntityManager( - DriverManager::getConnection($dsnParser->parse('sqlite3:///:memory:')), + DriverManager::getConnection(['driver' => 'sqlite3', 'memory' => true]), ORMSetup::createAttributeMetadataConfiguration([$dir], true) ); From 9d5bca804d09e914a8a7b04a754dd16a61bccbe6 Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 15 Feb 2024 16:03:05 +0100 Subject: [PATCH 09/12] Drop PHP 8.0 --- .github/workflows/main.yml | 2 +- composer.json | 2 +- src/Codeception/Module/Doctrine2.php | 5 +---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 240c0b0..6a1a23d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - php: [8.0, 8.1, 8.2, 8.3] + php: [8.1, 8.2, 8.3] steps: - name: Checkout code diff --git a/composer.json b/composer.json index 095520c..07da4d9 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ ], "homepage": "https://codeception.com/", "require": { - "php": "^8.0", + "php": "^8.1", "ext-json": "*", "ext-pdo": "*", "codeception/codeception": "^5.0.0-alpha2" diff --git a/src/Codeception/Module/Doctrine2.php b/src/Codeception/Module/Doctrine2.php index fc7225e..b699772 100644 --- a/src/Codeception/Module/Doctrine2.php +++ b/src/Codeception/Module/Doctrine2.php @@ -401,10 +401,7 @@ public function haveFakeRepository(string $className, array $methods = []): void $reflectedRepositoryFactory = new ReflectionClass($repositoryFactory); - // Do not call $reflectedRepositoryFactory->isReadOnly() directly because - // phpstan will complain about a non-existing method when using PHP 8.0. - // isReadOnly() is available as-of PHP 8.1. - if ($reflectedRepositoryFactory->hasMethod('isReadOnly') && $reflectedRepositoryFactory->getMethod('isReadOnly')->invoke(null)) { + if ($repositoryFactoryProperty->isReadOnly()) { $this->debugSection( 'Warning', 'Repository can\'t be mocked, the EntityManager\'s repositoryFactory is readonly' From 04fbcfdee3262e19b6afb27358bcfdc39bb6dbe3 Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 15 Feb 2024 16:18:25 +0100 Subject: [PATCH 10/12] Test against lowest dependency versions --- .github/workflows/main.yml | 3 ++- composer.json | 17 +++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6a1a23d..9697a7c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,6 +9,7 @@ jobs: strategy: matrix: php: [8.1, 8.2, 8.3] + composer_flags: [ '', '--prefer-lowest' ] steps: - name: Checkout code @@ -25,7 +26,7 @@ jobs: run: composer validate - name: Install dependencies - run: composer install --prefer-dist --no-progress --no-interaction + run: composer update --prefer-dist --no-progress --no-interaction ${{ matrix.composer_flags }} - name: Run test suite run: php vendor/bin/codecept run diff --git a/composer.json b/composer.json index 07da4d9..d94028a 100644 --- a/composer.json +++ b/composer.json @@ -20,19 +20,16 @@ "php": "^8.1", "ext-json": "*", "ext-pdo": "*", - "codeception/codeception": "^5.0.0-alpha2" + "codeception/codeception": "^5.1" }, "require-dev": { - "codeception/stub": "^4.0", - "doctrine/data-fixtures": "^1.5", + "codeception/stub": "^4.1.3", + "doctrine/data-fixtures": "^1.7", "doctrine/orm": "^2.14 || ^3.0", - "phpstan/phpstan": "^1.0", - "symfony/cache": "^4.4 || ^5.4 || ^6.0 || ^7.0", - "symfony/doctrine-bridge": "^5.4 || ^6.4 || ^7.0", - "symfony/uid": "^5.4 || ^6.4 || ^7.0" - }, - "conflict": { - "codeception/codeception": "<5.0" + "phpstan/phpstan": "^1.10.58", + "symfony/cache": "^5.4.35 || ^6.4.3 || ^7.0", + "symfony/doctrine-bridge": "^5.4.35 || ^6.4.3 || ^7.0", + "symfony/uid": "^5.4.35 || ^6.4.3 || ^7.0" }, "minimum-stability": "dev", "autoload": { From edcaebb4e844cfaf77ea3d22563793190c9c4de9 Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 15 Feb 2024 16:35:27 +0100 Subject: [PATCH 11/12] Use attributes and annotations in tests --- composer.json | 1 + .../doctrine2_entities/CircularRelations/A.php | 10 ++++++++++ .../doctrine2_entities/CircularRelations/B.php | 10 ++++++++++ .../doctrine2_entities/CircularRelations/C.php | 12 ++++++++++++ .../CompositePrimaryKeyEntity.php | 12 ++++++++++++ .../EntityWithConstructorParameters.php | 17 +++++++++++++++++ .../EntityWithEmbeddable.php | 12 ++++++++++++ .../data/doctrine2_entities/EntityWithUuid.php | 9 +++++++++ tests/data/doctrine2_entities/JoinedEntity.php | 6 ++++++ .../doctrine2_entities/JoinedEntityBase.php | 12 ++++++++++++ .../MultilevelRelations/A.php | 12 ++++++++++++ .../MultilevelRelations/B.php | 16 ++++++++++++++++ .../MultilevelRelations/C.php | 14 ++++++++++++++ .../NonTypicalPrimaryKeyEntity.php | 7 +++++++ tests/data/doctrine2_entities/PlainEntity.php | 11 +++++++++++ .../QuirkyFieldName/Association.php | 11 +++++++++++ .../QuirkyFieldName/AssociationHost.php | 14 ++++++++++++++ .../QuirkyFieldName/Embeddable.php | 6 ++++++ .../QuirkyFieldName/EmbeddableHost.php | 14 ++++++++++++++ .../doctrine2_entities/SampleEmbeddable.php | 6 ++++++ .../unit/Codeception/Module/Doctrine2Test.php | 18 ++++++++++++++---- 21 files changed, 226 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index d94028a..3d73a3c 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ }, "require-dev": { "codeception/stub": "^4.1.3", + "doctrine/annotations": "^2.0.1", "doctrine/data-fixtures": "^1.7", "doctrine/orm": "^2.14 || ^3.0", "phpstan/phpstan": "^1.10.58", diff --git a/tests/data/doctrine2_entities/CircularRelations/A.php b/tests/data/doctrine2_entities/CircularRelations/A.php index ebfba13..6563430 100644 --- a/tests/data/doctrine2_entities/CircularRelations/A.php +++ b/tests/data/doctrine2_entities/CircularRelations/A.php @@ -6,10 +6,19 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Entity + * @ORM\Table(name="circular_a") + */ #[ORM\Entity] #[ORM\Table(name: 'circular_a')] class A { + /** + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue + */ #[ORM\Id] #[ORM\Column(type: 'integer')] #[ORM\GeneratedValue] @@ -17,6 +26,7 @@ class A /** * @var ArrayCollection + * @ORM\OneToMany(targetEntity="C", mappedBy="a") */ #[ORM\OneToMany(targetEntity: C::class, mappedBy: 'a')] private Collection $cs; diff --git a/tests/data/doctrine2_entities/CircularRelations/B.php b/tests/data/doctrine2_entities/CircularRelations/B.php index 3f95d3d..f7a1ba0 100644 --- a/tests/data/doctrine2_entities/CircularRelations/B.php +++ b/tests/data/doctrine2_entities/CircularRelations/B.php @@ -6,10 +6,19 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Entity + * @ORM\Table(name="circular_b") + */ #[ORM\Entity] #[ORM\Table(name: 'circular_b')] class B { + /** + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue + */ #[ORM\Id] #[ORM\Column(type: 'integer')] #[ORM\GeneratedValue] @@ -17,6 +26,7 @@ class B /** * @var ArrayCollection + * @ORM\OneToMany(targetEntity="C", mappedBy="b") */ #[ORM\OneToMany(targetEntity: C::class, mappedBy: 'b')] private Collection $cs; diff --git a/tests/data/doctrine2_entities/CircularRelations/C.php b/tests/data/doctrine2_entities/CircularRelations/C.php index 98cb35c..da6e662 100644 --- a/tests/data/doctrine2_entities/CircularRelations/C.php +++ b/tests/data/doctrine2_entities/CircularRelations/C.php @@ -4,14 +4,26 @@ use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Entity + * @ORM\Table(name="circular_c") + */ #[ORM\Entity] #[ORM\Table(name: 'circular_c')] class C { + /** + * @ORM\Id + * @ORM\ManyToOne(targetEntity="A", inversedBy="cs", cascade={"persist"}) + */ #[ORM\Id] #[ORM\ManyToOne(targetEntity: A::class, inversedBy: 'cs', cascade: ['persist'])] private ?A $a; + /** + * @ORM\Id + * @ORM\ManyToOne(targetEntity="B", inversedBy="cs", cascade={"persist"}) + */ #[ORM\Id] #[ORM\ManyToOne(targetEntity: B::class, inversedBy: 'cs', cascade: ['persist'])] private ?B $b; diff --git a/tests/data/doctrine2_entities/CompositePrimaryKeyEntity.php b/tests/data/doctrine2_entities/CompositePrimaryKeyEntity.php index 184560a..2cd5ba8 100644 --- a/tests/data/doctrine2_entities/CompositePrimaryKeyEntity.php +++ b/tests/data/doctrine2_entities/CompositePrimaryKeyEntity.php @@ -2,13 +2,25 @@ use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Entity + */ #[ORM\Entity] class CompositePrimaryKeyEntity { + /** + * @ORM\Id + * @ORM\Column(type="integer") + */ #[ORM\Id] #[ORM\Column(type: 'integer')] private int $integerPart; + /** + * + * @ORM\Id + * @ORM\Column(type="string") + */ #[ORM\Id] #[ORM\Column(type: 'string')] private string $stringPart; diff --git a/tests/data/doctrine2_entities/EntityWithConstructorParameters.php b/tests/data/doctrine2_entities/EntityWithConstructorParameters.php index c4caa5c..4c75794 100644 --- a/tests/data/doctrine2_entities/EntityWithConstructorParameters.php +++ b/tests/data/doctrine2_entities/EntityWithConstructorParameters.php @@ -2,20 +2,37 @@ use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Entity + */ #[ORM\Entity] class EntityWithConstructorParameters { + /** + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue + */ #[ORM\Id] #[ORM\Column(type: 'integer')] #[ORM\GeneratedValue] private int $id; + /** + * @ORM\Column(type="string", nullable=true) + */ #[ORM\Column(type: 'string', nullable: true)] private ?string $name = null; + /** + * @ORM\Column(type="string", nullable=true) + */ #[ORM\Column(type: 'string', nullable: true)] private ?string $foo = null; + /** + * @ORM\Column(type="string") + */ #[ORM\Column(type: 'string')] private string $bar = ''; diff --git a/tests/data/doctrine2_entities/EntityWithEmbeddable.php b/tests/data/doctrine2_entities/EntityWithEmbeddable.php index 11d98d7..f2bf24c 100644 --- a/tests/data/doctrine2_entities/EntityWithEmbeddable.php +++ b/tests/data/doctrine2_entities/EntityWithEmbeddable.php @@ -2,14 +2,26 @@ use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Entity + */ #[ORM\Entity] class EntityWithEmbeddable { + /** + * + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue + */ #[ORM\Id] #[ORM\Column(type: 'integer')] #[ORM\GeneratedValue] private int $id; + /** + * @ORM\Embedded(class="SampleEmbeddable") + */ #[ORM\Embedded(class: SampleEmbeddable::class)] private SampleEmbeddable $embed; diff --git a/tests/data/doctrine2_entities/EntityWithUuid.php b/tests/data/doctrine2_entities/EntityWithUuid.php index fef889f..eb401a3 100644 --- a/tests/data/doctrine2_entities/EntityWithUuid.php +++ b/tests/data/doctrine2_entities/EntityWithUuid.php @@ -4,9 +4,18 @@ use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator; use Symfony\Component\Uid\Uuid; +/** + * @ORM\Entity + */ #[ORM\Entity] class EntityWithUuid { + /** + * @ORM\Id + * @ORM\Column(type="uuid", unique=true) + * @ORM\GeneratedValue(strategy="CUSTOM") + * @ORM\CustomIdGenerator(class="Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator") + */ #[ORM\Id] #[ORM\Column(type: 'uuid', unique: true)] #[ORM\GeneratedValue(strategy: 'CUSTOM')] diff --git a/tests/data/doctrine2_entities/JoinedEntity.php b/tests/data/doctrine2_entities/JoinedEntity.php index 1eb7241..48cc5b0 100644 --- a/tests/data/doctrine2_entities/JoinedEntity.php +++ b/tests/data/doctrine2_entities/JoinedEntity.php @@ -2,9 +2,15 @@ use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Entity + */ #[ORM\Entity] class JoinedEntity extends JoinedEntityBase { + /** + * @ORM\Column(type="string", nullable=true) + */ #[ORM\Column(type: 'string', nullable: true)] private ?string $own = null; } diff --git a/tests/data/doctrine2_entities/JoinedEntityBase.php b/tests/data/doctrine2_entities/JoinedEntityBase.php index c7d0170..c7a54f8 100644 --- a/tests/data/doctrine2_entities/JoinedEntityBase.php +++ b/tests/data/doctrine2_entities/JoinedEntityBase.php @@ -2,15 +2,27 @@ use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Entity + * @ORM\InheritanceType("JOINED") + */ #[ORM\Entity] #[ORM\InheritanceType('JOINED')] class JoinedEntityBase { + /** + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue + */ #[ORM\Id] #[ORM\Column(type: 'integer')] #[ORM\GeneratedValue] private int $id; + /** + * @ORM\Column(type="string", nullable=true) + */ #[ORM\Column(type: 'string', nullable: true)] private ?string $inherited = null; } diff --git a/tests/data/doctrine2_entities/MultilevelRelations/A.php b/tests/data/doctrine2_entities/MultilevelRelations/A.php index a3c2bc1..c6c67cf 100644 --- a/tests/data/doctrine2_entities/MultilevelRelations/A.php +++ b/tests/data/doctrine2_entities/MultilevelRelations/A.php @@ -6,19 +6,31 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Entity + */ #[ORM\Entity] class A { + /** + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue + */ #[ORM\Id] #[ORM\Column(type: 'integer')] #[ORM\GeneratedValue] private int $id; + /** + * @ORM\Column(type="string", nullable=true) + */ #[ORM\Column(type: 'string', nullable: true)] private ?string $name = null; /** * @var Collection|B[] + * @ORM\OneToMany(targetEntity="B", mappedBy="a") */ #[ORM\OneToMany(targetEntity: B::class, mappedBy: 'a')] private Collection $b; diff --git a/tests/data/doctrine2_entities/MultilevelRelations/B.php b/tests/data/doctrine2_entities/MultilevelRelations/B.php index e6378f5..acdc608 100644 --- a/tests/data/doctrine2_entities/MultilevelRelations/B.php +++ b/tests/data/doctrine2_entities/MultilevelRelations/B.php @@ -6,22 +6,38 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Entity + */ #[ORM\Entity] class B { + /** + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue + */ #[ORM\Id] #[ORM\Column(type: 'integer')] #[ORM\GeneratedValue] private int $id; + /** + * @ORM\Column(type="string", nullable=true) + */ #[ORM\Column(type: 'string', nullable: true)] private ?string $name = null; + /** + * @ORM\ManyToOne(targetEntity="A") + */ #[ORM\ManyToOne(targetEntity: A::class)] private ?A $a = null; /** * @var Collection|C[] + * + * @ORM\OneToMany(targetEntity="C", mappedBy="b") */ #[ORM\OneToMany(targetEntity: C::class, mappedBy: 'b')] private Collection $c; diff --git a/tests/data/doctrine2_entities/MultilevelRelations/C.php b/tests/data/doctrine2_entities/MultilevelRelations/C.php index d874fb5..2dc65ec 100644 --- a/tests/data/doctrine2_entities/MultilevelRelations/C.php +++ b/tests/data/doctrine2_entities/MultilevelRelations/C.php @@ -4,17 +4,31 @@ use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Entity + */ #[ORM\Entity] class C { + /** + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue + */ #[ORM\Id] #[ORM\Column(type: 'integer')] #[ORM\GeneratedValue] private int $id; + /** + * @ORM\Column(type="string", nullable=true) + */ #[ORM\Column(type: 'string', nullable: true)] private ?string $name = null; + /** + * @ORM\ManyToOne(targetEntity="B") + */ #[ORM\ManyToOne(targetEntity: B::class)] private ?B $b = null; diff --git a/tests/data/doctrine2_entities/NonTypicalPrimaryKeyEntity.php b/tests/data/doctrine2_entities/NonTypicalPrimaryKeyEntity.php index f756769..29b4df7 100644 --- a/tests/data/doctrine2_entities/NonTypicalPrimaryKeyEntity.php +++ b/tests/data/doctrine2_entities/NonTypicalPrimaryKeyEntity.php @@ -2,9 +2,16 @@ use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Entity + */ #[ORM\Entity] class NonTypicalPrimaryKeyEntity { + /** + * @ORM\Id + * @ORM\Column(type="string") + */ #[ORM\Id] #[ORM\Column(type: 'string')] private string $primaryKey; diff --git a/tests/data/doctrine2_entities/PlainEntity.php b/tests/data/doctrine2_entities/PlainEntity.php index 54eece6..42e2d6b 100644 --- a/tests/data/doctrine2_entities/PlainEntity.php +++ b/tests/data/doctrine2_entities/PlainEntity.php @@ -2,14 +2,25 @@ use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Entity + */ #[ORM\Entity] class PlainEntity { + /** + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue + */ #[ORM\Id] #[ORM\Column(type: 'integer')] #[ORM\GeneratedValue] private ?int $id = null; + /** + * @ORM\Column(type="string", nullable=true) + */ #[ORM\Column(type: 'string', nullable: true)] private ?string $name = null; diff --git a/tests/data/doctrine2_entities/QuirkyFieldName/Association.php b/tests/data/doctrine2_entities/QuirkyFieldName/Association.php index daa9427..0604e6c 100644 --- a/tests/data/doctrine2_entities/QuirkyFieldName/Association.php +++ b/tests/data/doctrine2_entities/QuirkyFieldName/Association.php @@ -4,14 +4,25 @@ use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Entity + */ #[ORM\Entity] class Association { + /** + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue + */ #[ORM\Id] #[ORM\Column(type: 'integer')] #[ORM\GeneratedValue] private ?int $id = null; + /** + * @ORM\Column(type="string", nullable=true) + */ #[ORM\Column(type: 'string', nullable: true)] private ?string $val = null; diff --git a/tests/data/doctrine2_entities/QuirkyFieldName/AssociationHost.php b/tests/data/doctrine2_entities/QuirkyFieldName/AssociationHost.php index d071ab7..a902bf5 100644 --- a/tests/data/doctrine2_entities/QuirkyFieldName/AssociationHost.php +++ b/tests/data/doctrine2_entities/QuirkyFieldName/AssociationHost.php @@ -4,17 +4,31 @@ use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Entity + */ #[ORM\Entity] class AssociationHost { + /** + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue + */ #[ORM\Id] #[ORM\Column(type: 'integer')] #[ORM\GeneratedValue] private ?int $id = null; + /** + * @ORM\OneToOne(targetEntity="Association") + */ #[ORM\OneToOne(targetEntity: Association::class)] private ?Association $assoc = null; + /** + * @ORM\Column(type="string", nullable=true) + */ #[ORM\Column(type: 'string', nullable: true)] private ?string $_assoc_val = null; diff --git a/tests/data/doctrine2_entities/QuirkyFieldName/Embeddable.php b/tests/data/doctrine2_entities/QuirkyFieldName/Embeddable.php index c60c555..12639b7 100644 --- a/tests/data/doctrine2_entities/QuirkyFieldName/Embeddable.php +++ b/tests/data/doctrine2_entities/QuirkyFieldName/Embeddable.php @@ -4,9 +4,15 @@ use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Embeddable + */ #[ORM\Embeddable] class Embeddable { + /** + * @ORM\Column(type="string", nullable=true) + */ #[ORM\Column(type: 'string', nullable: true)] private ?string $val = null; } diff --git a/tests/data/doctrine2_entities/QuirkyFieldName/EmbeddableHost.php b/tests/data/doctrine2_entities/QuirkyFieldName/EmbeddableHost.php index 22ee2b7..28ad95d 100644 --- a/tests/data/doctrine2_entities/QuirkyFieldName/EmbeddableHost.php +++ b/tests/data/doctrine2_entities/QuirkyFieldName/EmbeddableHost.php @@ -4,17 +4,31 @@ use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Entity + */ #[ORM\Entity] class EmbeddableHost { + /** + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue + */ #[ORM\Id] #[ORM\Column(type: 'integer')] #[ORM\GeneratedValue] private int $id; + /** + * @ORM\Embedded(class="Embeddable") + */ #[ORM\Embedded(class: Embeddable::class)] private Embeddable $embed; + /** + * @ORM\Column(type="string", nullable=true) + */ #[ORM\Column(type: 'string', nullable: true)] private ?string $embedval = null; diff --git a/tests/data/doctrine2_entities/SampleEmbeddable.php b/tests/data/doctrine2_entities/SampleEmbeddable.php index 12264c1..b5c8352 100644 --- a/tests/data/doctrine2_entities/SampleEmbeddable.php +++ b/tests/data/doctrine2_entities/SampleEmbeddable.php @@ -2,9 +2,15 @@ use Doctrine\ORM\Mapping as ORM; +/** + * @ORM\Embeddable + */ #[ORM\Embeddable] class SampleEmbeddable { + /** + * @ORM\Column(type="string", nullable=true) + */ #[ORM\Column(type: 'string', nullable: true)] private ?string $val = null; } diff --git a/tests/unit/Codeception/Module/Doctrine2Test.php b/tests/unit/Codeception/Module/Doctrine2Test.php index ea645bd..45b8cf5 100644 --- a/tests/unit/Codeception/Module/Doctrine2Test.php +++ b/tests/unit/Codeception/Module/Doctrine2Test.php @@ -71,10 +71,20 @@ protected function _setUp() require_once $dir . "/CircularRelations/C.php"; require_once $dir . '/EntityWithUuid.php'; - $this->em = new EntityManager( - DriverManager::getConnection(['driver' => 'sqlite3', 'memory' => true]), - ORMSetup::createAttributeMetadataConfiguration([$dir], true) - ); + $connection = DriverManager::getConnection(['driver' => 'sqlite3', 'memory' => true]); + + if (version_compare(InstalledVersions::getVersion('doctrine/orm'), '3', '>=')) { + $this->em = new EntityManager( + $connection, + ORMSetup::createAttributeMetadataConfiguration([$dir], true) + ); + } else { + $this->em = new EntityManager( + $connection, + // @phpstan-ignore-next-line + ORMSetup::createAnnotationMetadataConfiguration([$dir], true) + ); + } (new SchemaTool($this->em))->createSchema([ $this->em->getClassMetadata(CompositePrimaryKeyEntity::class), From 5d6921a22b45dd86afbc88e7f686a37fc5e67a3c Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 15 Feb 2024 16:53:20 +0100 Subject: [PATCH 12/12] Skip phpstan if executed with lowest dependencies to avoid false-positives --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9697a7c..1525e16 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,4 +32,6 @@ jobs: run: php vendor/bin/codecept run - name: Run source code analysis + if: "${{ matrix.composer_flags == '' }}" run: php vendor/bin/phpstan +