Skip to content

Commit

Permalink
failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusjatenee committed Oct 30, 2023
1 parent 800e264 commit 8052b38
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/Integration/Database/DatabaseTransactionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Illuminate\Tests\Integration\Database;

use Illuminate\Support\Facades\DB;

class DatabaseTransactionsTest extends DatabaseTestCase
{
public function testTransactionCallbacksDoNotInterfereWithOneAnother()
{
[$firstObject, $secondObject, $thirdObject] = [
new TestObjectForTransactions(),
new TestObjectForTransactions(),
new TestObjectForTransactions(),
];

DB::transaction(function () use ($thirdObject, $secondObject, $firstObject) { // Adds a transaction @ level 1
DB::transaction(function () use ($firstObject) { // Adds a transaction @ level 2
DB::afterCommit(fn () => $firstObject->handle()); // Adds a callback to be executed after transaction level 2 is committed
});

DB::afterCommit(fn () => $secondObject->handle()); // Adds a callback to be executed after transaction 1 @ lvl 1

try {
DB::transaction(function () use ($thirdObject) { // Adds a transaction 3 @ level 2
DB::afterCommit(fn () => $thirdObject->handle());
throw new \Exception();
});
} catch (\Exception) {}
});

$this->assertTrue($firstObject->ran);
$this->assertTrue($secondObject->ran);
$this->assertFalse($thirdObject->ran);
}
}

class TestObjectForTransactions
{
public bool $ran = false;

public function handle()
{
$this->ran = true;
}
}

0 comments on commit 8052b38

Please sign in to comment.