forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for doctrine#7068: EntityManager::find() with pessimistic lock sh…
…ould check for transaction
- Loading branch information
Showing
2 changed files
with
72 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\DBAL\LockMode; | ||
use Doctrine\ORM\Annotation as ORM; | ||
use Doctrine\ORM\TransactionRequiredException; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
final class GH7068Test extends OrmFunctionalTestCase | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function setUp() : void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setUpEntitySchema( | ||
[ | ||
SomeEntity::class, | ||
] | ||
); | ||
} | ||
|
||
public function testLockModeIsRespected() : void | ||
{ | ||
$entity = new SomeEntity(); | ||
$this->em->persist($entity); | ||
$this->em->flush(); | ||
$this->em->clear(); | ||
|
||
$this->em->find(SomeEntity::class, 1); | ||
|
||
$this->expectException(TransactionRequiredException::class); | ||
$this->em->find(SomeEntity::class, 1, LockMode::PESSIMISTIC_WRITE); | ||
} | ||
} | ||
|
||
/** @ORM\Entity */ | ||
final class SomeEntity | ||
{ | ||
/** @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue */ | ||
public $id; | ||
} |