Skip to content

Commit

Permalink
Merge branch '2.9.x' into 2.10.x
Browse files Browse the repository at this point in the history
* 2.9.x:
  Run PHP 8.1 CI with stable dependencies (doctrine#9058)
  Duplicate testTwoIterateHydrations (doctrine#9048)
  Add PHP 8.1 to CI (doctrine#9006)
  Fix locking non-existing entity (doctrine#9053)

Signed-off-by: Alexander M. Turek <[email protected]>
  • Loading branch information
derrabus committed Oct 2, 2021
2 parents 7a8c086 + 5f76874 commit 5fde232
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 5 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ jobs:
- "7.3"
- "7.4"
- "8.0"
- "8.1"
dbal-version:
- "default"
include:
- php-version: "8.0"
dbal-version: "2.13"
# To be merged with the previous job as soon as https://github.com/doctrine/dbal/pull/4818 is released.
- php-version: "8.1"
dbal-version: "2.13.4@dev"
dbal-version: "2.13"
- php-version: "8.1"
dbal-version: "3.2@dev"

Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,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;

Expand Down
65 changes: 65 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\Tests\OrmFunctionalTestCase;
use Generator;

class DDC309Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(DDC309Country::class),
Expand All @@ -23,6 +25,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();
Expand Down Expand Up @@ -52,6 +66,57 @@ public function testTwoIterateHydrations(): void

self::assertEquals(2, $c[0]->id);
self::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<int, DDC309Country> $q */
$q = $this->_em->createQuery('SELECT c FROM Doctrine\Tests\ORM\Functional\Ticket\DDC309Country c')->toIterable();
$c = $q->current();

self::assertEquals(1, $c->id);

/** @var Generator<int, DDC309User> $r */
$r = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\ORM\Functional\Ticket\DDC309User u')->toIterable();
$u = $r->current();

self::assertEquals(1, $u->id);

$q->next();
$r->next();
$c = $q->current();
$u = $r->current();

self::assertEquals(2, $c->id);
self::assertEquals(2, $u->id);

do {
$q->next();
} while ($q->valid());

do {
$r->next();
} while ($r->valid());
}
}

Expand Down
62 changes: 62 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH8663Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\DBAL\LockMode;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Version;
use Doctrine\Tests\OrmFunctionalTestCase;

class GH8663Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

$this->_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;
}

0 comments on commit 5fde232

Please sign in to comment.