From 2362aa1a7a43d1fb998d32c5c920371d206a00b2 Mon Sep 17 00:00:00 2001 From: Csupity Laszlo Date: Thu, 30 Sep 2021 23:29:34 +0200 Subject: [PATCH 1/4] Fix locking non-existing entity (#9053) --- lib/Doctrine/ORM/EntityManager.php | 4 +- .../ORM/Functional/Ticket/GH8663Test.php | 55 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH8663Test.php diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index ca858881a0b..775eceaabd4 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -473,7 +473,9 @@ public function find($className, $id, $lockMode = null, $lockVersion = null) case $lockMode === LockMode::OPTIMISTIC: $entity = $persister->load($sortedId); - $unitOfWork->lock($entity, $lockMode, $lockVersion); + if ($entity !== null) { + $unitOfWork->lock($entity, $lockMode, $lockVersion); + } return $entity; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8663Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8663Test.php new file mode 100644 index 00000000000..85b6960fb45 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8663Test.php @@ -0,0 +1,55 @@ +_schemaTool->createSchema([ + $this->_em->getClassMetadata(GH8663VersionedEntity::class), + ]); + } + + protected function tearDown(): void + { + $this->_schemaTool->dropSchema([ + $this->_em->getClassMetadata(GH8663VersionedEntity::class), + ]); + + parent::tearDown(); + } + + public function testDeletedEntity(): void + { + $result = $this->_em->find(GH8663VersionedEntity::class, 1, LockMode::OPTIMISTIC); + + $this->assertNull($result); + } +} + +/** + * @Entity + */ +class GH8663VersionedEntity +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + * @var int + */ + protected $id; + + /** + * @Version + * @Column(type="integer") + * @var int + */ + protected $version; +} From 70b0f50d13d88f7ecd6edb26798528d342c2c3df Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 2 Oct 2021 17:20:20 +0200 Subject: [PATCH 2/4] Add PHP 8.1 to CI (#9006) Signed-off-by: Alexander M. Turek --- .github/workflows/continuous-integration.yml | 6 ++++++ tests/Doctrine/Tests/ORM/Functional/Ticket/GH7941Test.php | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index bf30840bacd..9d911483d5a 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -19,6 +19,7 @@ jobs: - "7.3" - "7.4" - "8.0" + - "8.1" steps: - name: "Checkout" @@ -34,6 +35,11 @@ jobs: coverage: "pcov" ini-values: "zend.assertions=1" + # To be removed as soon as https://github.com/doctrine/dbal/pull/4818 is released. + - name: "Switch to dev dependencies" + if: "${{ matrix.php-version == '8.1' }}" + run: "composer config minimum-stability dev" + - name: "Install dependencies with Composer" uses: "ramsey/composer-install@v1" diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7941Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7941Test.php index 70c42914997..45b4d28fe1c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7941Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7941Test.php @@ -50,7 +50,9 @@ public function typesShouldBeConvertedForDQLFunctions(): void $result = $query->getSingleResult(); self::assertSame(6, $result['count']); - self::assertSame('325', $result['sales']); + + // While other drivers will return a string, pdo_sqlite returns an integer as of PHP 8.1 + self::assertEquals(325, $result['sales']); // Driver return type and precision is determined by the underlying php extension, most seem to return a string. // pdo_mysql and mysqli both currently return '54.1667' so this is the maximum precision we can assert. @@ -68,7 +70,7 @@ public function typesShouldBeConvertedForDQLFunctions(): void foreach ($query->getResult() as $i => $item) { $product = self::PRODUCTS[$i]; - self::assertSame(ltrim($product['price'], '-'), $item['absolute']); + self::assertEquals(ltrim($product['price'], '-'), $item['absolute']); self::assertSame(strlen($product['name']), $item['length']); // Driver return types for the `square_root` column are inconsistent depending on the underlying From 1d4e12bc6baa41773c297ad2ef5d258c45fc7803 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 2 Oct 2021 17:45:29 +0200 Subject: [PATCH 3/4] Duplicate testTwoIterateHydrations (#9048) --- .../ORM/Functional/Ticket/DDC309Test.php | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php index 159caeeeed9..b516ef873d8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php @@ -5,12 +5,14 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; use Doctrine\Tests\OrmFunctionalTestCase; +use Generator; class DDC309Test extends OrmFunctionalTestCase { protected function setUp(): void { parent::setUp(); + $this->_schemaTool->createSchema( [ $this->_em->getClassMetadata(DDC309Country::class), @@ -19,6 +21,18 @@ protected function setUp(): void ); } + protected function tearDown(): void + { + $this->_schemaTool->dropSchema( + [ + $this->_em->getClassMetadata(DDC309Country::class), + $this->_em->getClassMetadata(DDC309User::class), + ] + ); + + parent::tearDown(); + } + public function testTwoIterateHydrations(): void { $c1 = new DDC309Country(); @@ -48,6 +62,57 @@ public function testTwoIterateHydrations(): void $this->assertEquals(2, $c[0]->id); $this->assertEquals(2, $u[0]->id); + + do { + $q->next(); + } while ($q->valid()); + + do { + $r->next(); + } while ($r->valid()); + } + + public function testTwoToIterableHydrations(): void + { + $c1 = new DDC309Country(); + $c2 = new DDC309Country(); + $u1 = new DDC309User(); + $u2 = new DDC309User(); + + $this->_em->persist($c1); + $this->_em->persist($c2); + $this->_em->persist($u1); + $this->_em->persist($u2); + $this->_em->flush(); + $this->_em->clear(); + + /** @var Generator $q */ + $q = $this->_em->createQuery('SELECT c FROM Doctrine\Tests\ORM\Functional\Ticket\DDC309Country c')->toIterable(); + $c = $q->current(); + + $this->assertEquals(1, $c->id); + + /** @var Generator $r */ + $r = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\ORM\Functional\Ticket\DDC309User u')->toIterable(); + $u = $r->current(); + + $this->assertEquals(1, $u->id); + + $q->next(); + $r->next(); + $c = $q->current(); + $u = $r->current(); + + $this->assertEquals(2, $c->id); + $this->assertEquals(2, $u->id); + + do { + $q->next(); + } while ($q->valid()); + + do { + $r->next(); + } while ($r->valid()); } } From 5f768742a0461327bebe0fd11012bbd69e29a311 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 2 Oct 2021 19:37:08 +0200 Subject: [PATCH 4/4] Run PHP 8.1 CI with stable dependencies (#9058) --- .github/workflows/continuous-integration.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 9d911483d5a..b166f0b139a 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -35,11 +35,6 @@ jobs: coverage: "pcov" ini-values: "zend.assertions=1" - # To be removed as soon as https://github.com/doctrine/dbal/pull/4818 is released. - - name: "Switch to dev dependencies" - if: "${{ matrix.php-version == '8.1' }}" - run: "composer config minimum-stability dev" - - name: "Install dependencies with Composer" uses: "ramsey/composer-install@v1"