From ef1bfbf2362cd069494cfc829e5897116d511c14 Mon Sep 17 00:00:00 2001 From: Aaron Gustavo Nieves <64917965+TavoNiievez@users.noreply.github.com> Date: Sat, 17 Feb 2024 17:09:09 -0500 Subject: [PATCH] Support doctrine/orm v3 + doctrine/dbal v4 (#26) * Allow doctrine/orm v3 * Replace ramsey/uuid-doctrine with symfony/doctrine-bridge and symfony/uuid * Compatibility with doctrine/dbal v4 * Changed use of deprecated doctrine/orm connect method to use getNativeConnection method * Simplify DBAL connection parameters * Drop PHP 8.0 * Test against lowest dependency versions * Use attributes and annotations in tests * Skip phpstan if executed with lowest dependencies to avoid false-positives --------- Co-authored-by: W0rma Co-authored-by: Viktor Truhanovich --- .github/workflows/main.yml | 7 ++- composer.json | 22 +++++---- src/Codeception/Module/Doctrine2.php | 13 ++++-- .../CircularRelations/A.php | 6 +++ .../CircularRelations/B.php | 6 +++ .../CircularRelations/C.php | 6 +++ .../CompositePrimaryKeyEntity.php | 5 +++ .../EntityWithConstructorParameters.php | 7 +++ .../EntityWithEmbeddable.php | 5 +++ .../doctrine2_entities/EntityWithUuid.php | 17 ++++--- .../data/doctrine2_entities/JoinedEntity.php | 2 + .../doctrine2_entities/JoinedEntityBase.php | 6 +++ .../MultilevelRelations/A.php | 6 +++ .../MultilevelRelations/B.php | 7 +++ .../MultilevelRelations/C.php | 6 +++ .../NonTypicalPrimaryKeyEntity.php | 3 ++ tests/data/doctrine2_entities/PlainEntity.php | 5 +++ .../QuirkyFieldName/Association.php | 5 +++ .../QuirkyFieldName/AssociationHost.php | 6 +++ .../QuirkyFieldName/Embeddable.php | 2 + .../QuirkyFieldName/EmbeddableHost.php | 6 +++ .../doctrine2_entities/SampleEmbeddable.php | 2 + .../unit/Codeception/Module/Doctrine2Test.php | 45 ++++++++++++------- 23 files changed, 154 insertions(+), 41 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 240c0b0..1525e16 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,8 @@ jobs: strategy: matrix: - php: [8.0, 8.1, 8.2, 8.3] + php: [8.1, 8.2, 8.3] + composer_flags: [ '', '--prefer-lowest' ] steps: - name: Checkout code @@ -25,10 +26,12 @@ 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 - name: Run source code analysis + if: "${{ matrix.composer_flags == '' }}" run: php vendor/bin/phpstan + diff --git a/composer.json b/composer.json index 1cc878a..3d73a3c 100644 --- a/composer.json +++ b/composer.json @@ -17,22 +17,20 @@ ], "homepage": "https://codeception.com/", "require": { - "php": "^8.0", + "php": "^8.1", "ext-json": "*", "ext-pdo": "*", - "codeception/codeception": "^5.0.0-alpha2" + "codeception/codeception": "^5.1" }, "require-dev": { - "codeception/stub": "^4.0", - "doctrine/annotations": "^1.13", - "doctrine/data-fixtures": "^1.5", - "doctrine/orm": "^2.10", - "phpstan/phpstan": "^1.0", - "ramsey/uuid-doctrine": "^1.6", - "symfony/cache": "^4.4 || ^5.4 || ^6.0" - }, - "conflict": { - "codeception/codeception": "<5.0" + "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", + "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": { diff --git a/src/Codeception/Module/Doctrine2.php b/src/Codeception/Module/Doctrine2.php index e46a0b3..b699772 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(); } /** @@ -401,7 +401,12 @@ public function haveFakeRepository(string $className, array $methods = []): void $reflectedRepositoryFactory = new ReflectionClass($repositoryFactory); - if ($reflectedRepositoryFactory->hasProperty('repositoryList')) { + if ($repositoryFactoryProperty->isReadOnly()) { + $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 +420,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/data/doctrine2_entities/CircularRelations/A.php b/tests/data/doctrine2_entities/CircularRelations/A.php index 4ba59e5..6563430 100644 --- a/tests/data/doctrine2_entities/CircularRelations/A.php +++ b/tests/data/doctrine2_entities/CircularRelations/A.php @@ -10,6 +10,8 @@ * @ORM\Entity * @ORM\Table(name="circular_a") */ +#[ORM\Entity] +#[ORM\Table(name: 'circular_a')] class A { /** @@ -17,12 +19,16 @@ class A * @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..f7a1ba0 100644 --- a/tests/data/doctrine2_entities/CircularRelations/B.php +++ b/tests/data/doctrine2_entities/CircularRelations/B.php @@ -10,6 +10,8 @@ * @ORM\Entity * @ORM\Table(name="circular_b") */ +#[ORM\Entity] +#[ORM\Table(name: 'circular_b')] class B { /** @@ -17,12 +19,16 @@ class B * @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..da6e662 100644 --- a/tests/data/doctrine2_entities/CircularRelations/C.php +++ b/tests/data/doctrine2_entities/CircularRelations/C.php @@ -8,18 +8,24 @@ * @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..2cd5ba8 100644 --- a/tests/data/doctrine2_entities/CompositePrimaryKeyEntity.php +++ b/tests/data/doctrine2_entities/CompositePrimaryKeyEntity.php @@ -5,12 +5,15 @@ /** * @ORM\Entity */ +#[ORM\Entity] class CompositePrimaryKeyEntity { /** * @ORM\Id * @ORM\Column(type="integer") */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] private int $integerPart; /** @@ -18,5 +21,7 @@ class CompositePrimaryKeyEntity * @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..4c75794 100644 --- a/tests/data/doctrine2_entities/EntityWithConstructorParameters.php +++ b/tests/data/doctrine2_entities/EntityWithConstructorParameters.php @@ -5,6 +5,7 @@ /** * @ORM\Entity */ +#[ORM\Entity] class EntityWithConstructorParameters { /** @@ -12,21 +13,27 @@ class EntityWithConstructorParameters * @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..f2bf24c 100644 --- a/tests/data/doctrine2_entities/EntityWithEmbeddable.php +++ b/tests/data/doctrine2_entities/EntityWithEmbeddable.php @@ -5,6 +5,7 @@ /** * @ORM\Entity */ +#[ORM\Entity] class EntityWithEmbeddable { /** @@ -13,11 +14,15 @@ class EntityWithEmbeddable * @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..eb401a3 100644 --- a/tests/data/doctrine2_entities/EntityWithUuid.php +++ b/tests/data/doctrine2_entities/EntityWithUuid.php @@ -1,28 +1,33 @@ id = Uuid::uuid4(); + $this->id = Uuid::v4(); } - public function getId(): UuidInterface + public function getId(): Uuid { return $this->id; } diff --git a/tests/data/doctrine2_entities/JoinedEntity.php b/tests/data/doctrine2_entities/JoinedEntity.php index 15ef7cf..48cc5b0 100644 --- a/tests/data/doctrine2_entities/JoinedEntity.php +++ b/tests/data/doctrine2_entities/JoinedEntity.php @@ -5,10 +5,12 @@ /** * @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..c7a54f8 100644 --- a/tests/data/doctrine2_entities/JoinedEntityBase.php +++ b/tests/data/doctrine2_entities/JoinedEntityBase.php @@ -6,6 +6,8 @@ * @ORM\Entity * @ORM\InheritanceType("JOINED") */ +#[ORM\Entity] +#[ORM\InheritanceType('JOINED')] class JoinedEntityBase { /** @@ -13,10 +15,14 @@ class JoinedEntityBase * @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..c6c67cf 100644 --- a/tests/data/doctrine2_entities/MultilevelRelations/A.php +++ b/tests/data/doctrine2_entities/MultilevelRelations/A.php @@ -9,6 +9,7 @@ /** * @ORM\Entity */ +#[ORM\Entity] class A { /** @@ -16,17 +17,22 @@ class A * @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..acdc608 100644 --- a/tests/data/doctrine2_entities/MultilevelRelations/B.php +++ b/tests/data/doctrine2_entities/MultilevelRelations/B.php @@ -9,6 +9,7 @@ /** * @ORM\Entity */ +#[ORM\Entity] class B { /** @@ -16,16 +17,21 @@ class B * @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; /** @@ -33,6 +39,7 @@ class B * * @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..2dc65ec 100644 --- a/tests/data/doctrine2_entities/MultilevelRelations/C.php +++ b/tests/data/doctrine2_entities/MultilevelRelations/C.php @@ -7,6 +7,7 @@ /** * @ORM\Entity */ +#[ORM\Entity] class C { /** @@ -14,16 +15,21 @@ class C * @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..29b4df7 100644 --- a/tests/data/doctrine2_entities/NonTypicalPrimaryKeyEntity.php +++ b/tests/data/doctrine2_entities/NonTypicalPrimaryKeyEntity.php @@ -5,11 +5,14 @@ /** * @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..42e2d6b 100644 --- a/tests/data/doctrine2_entities/PlainEntity.php +++ b/tests/data/doctrine2_entities/PlainEntity.php @@ -5,6 +5,7 @@ /** * @ORM\Entity */ +#[ORM\Entity] class PlainEntity { /** @@ -12,11 +13,15 @@ class PlainEntity * @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..0604e6c 100644 --- a/tests/data/doctrine2_entities/QuirkyFieldName/Association.php +++ b/tests/data/doctrine2_entities/QuirkyFieldName/Association.php @@ -7,6 +7,7 @@ /** * @ORM\Entity */ +#[ORM\Entity] class Association { /** @@ -14,11 +15,15 @@ class Association * @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..a902bf5 100644 --- a/tests/data/doctrine2_entities/QuirkyFieldName/AssociationHost.php +++ b/tests/data/doctrine2_entities/QuirkyFieldName/AssociationHost.php @@ -7,6 +7,7 @@ /** * @ORM\Entity */ +#[ORM\Entity] class AssociationHost { /** @@ -14,16 +15,21 @@ class AssociationHost * @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..12639b7 100644 --- a/tests/data/doctrine2_entities/QuirkyFieldName/Embeddable.php +++ b/tests/data/doctrine2_entities/QuirkyFieldName/Embeddable.php @@ -7,10 +7,12 @@ /** * @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..28ad95d 100644 --- a/tests/data/doctrine2_entities/QuirkyFieldName/EmbeddableHost.php +++ b/tests/data/doctrine2_entities/QuirkyFieldName/EmbeddableHost.php @@ -7,6 +7,7 @@ /** * @ORM\Entity */ +#[ORM\Entity] class EmbeddableHost { /** @@ -14,16 +15,21 @@ class EmbeddableHost * @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..b5c8352 100644 --- a/tests/data/doctrine2_entities/SampleEmbeddable.php +++ b/tests/data/doctrine2_entities/SampleEmbeddable.php @@ -5,10 +5,12 @@ /** * @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..45b8cf5 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; @@ -11,11 +12,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; @@ -23,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 { @@ -48,10 +50,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,11 +71,20 @@ 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) - ); + $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), @@ -421,13 +428,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() @@ -441,7 +448,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()); @@ -471,7 +478,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()); @@ -568,6 +575,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, [