Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions infection.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
]
},
"timeout": 10,
"minMsi": 90,
"minCoveredMsi": 90,
"minMsi": 98,
"minCoveredMsi": 98,
"testFramework": "testo",
"tmpDir": "runtime",
"logs": {
Expand Down
22 changes: 11 additions & 11 deletions tests/Acceptance/Common/ActiveRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,19 @@ public function groupActionsInStrictModeOutsideTransactionThrows(): never
#[Isolate(Isolation::None)]
public function groupActionsInIgnoreModeOutsideTransactionSucceeds(): void
{
// When outside a transaction, TransactionMode::Ignore (with strict: false) should work fine.
// The runner will ignore the lack of a transaction.
// If mutated to strict: true, this would throw RunnerException because there's no active transaction.
$result = ActiveRecord::groupActions(static function () use (&$created, &$deleted): string {
// Create and immediately delete an entity to generate commands without leaving side effects
# Two separate groups: saving and deleting in one group cancel out and run no command at all.
$user = ActiveRecord::groupActions(static function (): User {
$user = new User('TestUser');
$created = $user->save(); // Must succeed without transaction
$deleted = $user->delete(); // Must also succeed
return 'success';
$user->save();
return $user;
}, TransactionMode::Ignore);
Assert::same($result, 'success');
Assert::true($created);
Assert::true($deleted);
try {
Assert::notNull(User::query()->where('name', 'TestUser')->fetchOne());
} finally {
ActiveRecord::groupActions(static fn(): bool => $user->delete(), TransactionMode::Ignore);
}

Assert::null(User::query()->where('name', 'TestUser')->fetchOne());
}

public function deletesMultipleEntitiesInGroupActions(): void
Expand Down
16 changes: 16 additions & 0 deletions tests/Unit/FacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Cycle\Testing\ORM\Memory;
use Cycle\Tests\Unit\Stub\Container\ConfigurableContainer;
use Cycle\Tests\Unit\Stub\Container\ServiceNotFoundException;
use Cycle\Transaction\Internal\TransactionImpl;
use Cycle\Transaction\Transaction;
use Testo\Assert;
use Testo\Codecov\Covers;
use Testo\Expect;
Expand Down Expand Up @@ -130,6 +132,20 @@ public function cachesDatabaseManagerAfterFirstCall(): void
Assert::count($container->requested, 1);
}

public function cachesTransactionAfterFirstCall(): void
{
$transaction = new TransactionImpl($this->buildOrm(), DatabaseMemory::manager());
$container = ConfigurableContainer::returning(Transaction::class, $transaction);
Facade::setContainer($container);

$first = Facade::getTransaction();
$second = Facade::getTransaction();

Assert::same($first, $transaction);
Assert::same($second, $transaction);
Assert::same($container->requested, [Transaction::class]);
}

private function buildOrm(): ORMInterface
{
return Memory::orm();
Expand Down
Loading