Skip to content

Commit

Permalink
Add method forUpdate (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
msmakouz authored Mar 29, 2024
1 parent 230dc9f commit 9ce5e6f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Select/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,12 @@ public function select(): Select
{
return clone $this->select;
}

public function forUpdate(): static
{
$repository = clone $this;
$repository->select->forUpdate();

return $repository;
}
}
16 changes: 16 additions & 0 deletions tests/ORM/Functional/Driver/SQLite/Select/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Cycle\ORM\Tests\Functional\Driver\SQLite\Select;

// phpcs:ignore
use Cycle\ORM\Tests\Fixtures\User;
use Cycle\ORM\Tests\Functional\Driver\Common\Select\RepositoryTest as CommonClass;

/**
Expand All @@ -14,4 +15,19 @@
class RepositoryTest extends CommonClass
{
public const DRIVER = 'sqlite';

/**
* This test does not need to be executed for each database driver.
*/
public function testForUpdate(): void
{
$repository = $this->orm->getRepository(User::class);

$this->assertFalse($repository->select()->getBuilder()->getQuery()->getTokens()['forUpdate']);

$forUpdate = $repository->forUpdate();

$this->assertTrue($forUpdate->select()->getBuilder()->getQuery()->getTokens()['forUpdate']);
$this->assertNotSame($repository, $forUpdate);
}
}

0 comments on commit 9ce5e6f

Please sign in to comment.