Skip to content

Commit

Permalink
test: add a transact() test
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Dec 20, 2024
1 parent 4cd3cef commit 61b8b3d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/src/Functional/ActiveRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,29 @@ public function it_runs_grouping_actions_without_transaction_inside_manually_ope
$savedUserTwo = $this->selectEntity(User::class, cleanHeap: true)->wherePK($userTwo->id)->fetchOne();
self::assertSame($savedUserTwo->name, $userTwo->name);
}

/**
* @throws \Throwable
*/
#[Test]
public function it_runs_transaction_calling_on_entity_class(): void
{
User::transact(static function () use (&$userOne, &$userTwo): void {
User::groupActions(static function () use (&$userOne, &$userTwo): void {
$userOne = new User('Foo');
$userOne->saveOrFail();

$userTwo = new User('Bar');
$userTwo->saveOrFail();
}, TransactionMode::Current);
});

self::assertCount(4, User::findAll());

$savedUserOne = $this->selectEntity(User::class, cleanHeap: true)->wherePK($userOne->id)->fetchOne();
self::assertSame($savedUserOne->name, $userOne->name);

$savedUserTwo = $this->selectEntity(User::class, cleanHeap: true)->wherePK($userTwo->id)->fetchOne();
self::assertSame($savedUserTwo->name, $userTwo->name);
}
}

0 comments on commit 61b8b3d

Please sign in to comment.