From 61b8b3d1de1277f9391a383f751dd9f61db09a92 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Fri, 20 Dec 2024 23:58:58 +0400 Subject: [PATCH] test: add a transact() test --- tests/src/Functional/ActiveRecordTest.php | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/src/Functional/ActiveRecordTest.php b/tests/src/Functional/ActiveRecordTest.php index f7b4ad4..a8e09ca 100644 --- a/tests/src/Functional/ActiveRecordTest.php +++ b/tests/src/Functional/ActiveRecordTest.php @@ -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); + } }