Validate if optimistic locks are released properly
By trying to update an entry using a different connection.
This commit is contained in:
parent
99df158fc8
commit
19fc91482e
@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
use Doctrine\DBAL\LockMode;
|
||||
use Doctrine\Tests\Models\Company\CompanyManager;
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
use Doctrine\Tests\TestUtil;
|
||||
|
||||
class DDC933Test extends OrmFunctionalTestCase
|
||||
{
|
||||
@ -20,6 +21,10 @@ class DDC933Test extends OrmFunctionalTestCase
|
||||
*/
|
||||
public function testLockCTIClass()
|
||||
{
|
||||
if ($this->_em->getConnection()->getDatabasePlatform()->getName() === 'sqlite') {
|
||||
self::markTestSkipped('It should not run on in-memory databases');
|
||||
}
|
||||
|
||||
$manager = new CompanyManager();
|
||||
$manager->setName('beberlei');
|
||||
$manager->setSalary(1234);
|
||||
@ -32,5 +37,33 @@ class DDC933Test extends OrmFunctionalTestCase
|
||||
$this->_em->beginTransaction();
|
||||
$this->_em->lock($manager, LockMode::PESSIMISTIC_READ);
|
||||
$this->_em->rollback();
|
||||
|
||||
// if lock hasn't been released we'd have an exception here
|
||||
$this->assertManagerCanBeUpdatedOnAnotherConnection($manager->getId(), 'Master of This Test');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param string $newName
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Doctrine\Common\Persistence\Mapping\MappingException
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
private function assertManagerCanBeUpdatedOnAnotherConnection(int $id, string $newName)
|
||||
{
|
||||
$em = $this->_getEntityManager(TestUtil::getConnection());
|
||||
|
||||
/** @var CompanyManager $manager */
|
||||
$manager = $em->find(CompanyManager::class, $id);
|
||||
$manager->setName($newName);
|
||||
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
|
||||
self::assertSame($newName, $em->find(CompanyManager::class, $id)->getName());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user