Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test coverage for passing optimistic lock version as string #8533

Merged
merged 1 commit into from Mar 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 20 additions & 4 deletions tests/Doctrine/Tests/ORM/Functional/Locking/LockTest.php
Expand Up @@ -32,8 +32,10 @@ protected function setUp(): void
/**
* @group DDC-178
* @group locking
* @testWith [false]
* [true]
*/
public function testLockVersionedEntity(): void
public function testLockVersionedEntity(bool $useStringVersion): void
{
$article = new CmsArticle();
$article->text = 'my article';
Expand All @@ -42,16 +44,26 @@ public function testLockVersionedEntity(): void
$this->_em->persist($article);
$this->_em->flush();

$this->_em->lock($article, LockMode::OPTIMISTIC, $article->version);
$lockVersion = $article->version;
if ($useStringVersion) {
// NOTE: Officially, the lock method (and callers) do not accept a string argument. Calling code should
// cast the version to (int) as per the docs. However, this is not currently enforced. This may change in
// a future release.
$lockVersion = (string) $lockVersion;
}

$this->_em->lock($article, LockMode::OPTIMISTIC, $lockVersion);

$this->addToAssertionCount(1);
}

/**
* @group DDC-178
* @group locking
* @testWith [false]
* [true]
*/
public function testLockVersionedEntityMismatchThrowsException(): void
public function testLockVersionedEntityMismatchThrowsException(bool $useStringVersion): void
{
$article = new CmsArticle();
$article->text = 'my article';
Expand All @@ -61,8 +73,12 @@ public function testLockVersionedEntityMismatchThrowsException(): void
$this->_em->flush();

$this->expectException(OptimisticLockException::class);
$lockVersion = $article->version + 1;
if ($useStringVersion) {
$lockVersion = (string) $lockVersion;
}

$this->_em->lock($article, LockMode::OPTIMISTIC, $article->version + 1);
$this->_em->lock($article, LockMode::OPTIMISTIC, $lockVersion);
}

/**
Expand Down