-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[11.x] Skip the number of connections transacting while testing to ru…
…n callbacks (#53377) * Skip the number of connections transacting while testing to run callbacks The testing DatabaseTransactionsManager was hardcoding the number of connections to skip as 1. In a multi-db context, it must skip the same number of connections transacting defined on the tests. * Pass the connection names array instead of the number of connections * Fix tests for the testing DatabaseTransactionsManager * Fix DatabaseTransactions trait * [11.x] Test Improvements Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Adds tests for afterCommit callbacks when using multi-dbs * Update DatabaseTransactionsManager.php --------- Signed-off-by: Mior Muhammad Zaki <[email protected]> Co-authored-by: Mior Muhammad Zaki <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
4500be3
commit 4cd413b
Showing
6 changed files
with
105 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...abase/EloquentTransactionWithAfterCommitUsingRefreshDatabaseOnMultipleConnectionsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Database; | ||
|
||
use Illuminate\Support\Facades\DB; | ||
use Orchestra\Testbench\Attributes\WithConfig; | ||
|
||
use function Orchestra\Testbench\artisan; | ||
|
||
#[WithConfig('database.connections.second', ['driver' => 'sqlite', 'database' => ':memory:', 'foreign_key_constraints' => false])] | ||
class EloquentTransactionWithAfterCommitUsingRefreshDatabaseOnMultipleConnectionsTest extends EloquentTransactionWithAfterCommitUsingRefreshDatabaseTest | ||
{ | ||
/** {@inheritDoc} */ | ||
protected function connectionsToTransact() | ||
{ | ||
return [null, 'second']; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
protected function afterRefreshingDatabase() | ||
{ | ||
artisan($this, 'migrate', ['--database' => 'second']); | ||
} | ||
|
||
public function testAfterCommitCallbacksAreCalledCorrectlyWhenNoAppTransaction() | ||
{ | ||
$called = false; | ||
|
||
DB::afterCommit(function () use (&$called) { | ||
$called = true; | ||
}); | ||
|
||
$this->assertTrue($called); | ||
} | ||
|
||
public function testAfterCommitCallbacksAreCalledWithWrappingTransactionsCorrectly() | ||
{ | ||
$calls = []; | ||
|
||
DB::transaction(function () use (&$calls) { | ||
DB::afterCommit(function () use (&$calls) { | ||
$calls[] = 'first transaction callback'; | ||
}); | ||
|
||
DB::connection('second')->transaction(function () use (&$calls) { | ||
DB::connection('second')->afterCommit(function () use (&$calls) { | ||
$calls[] = 'second transaction callback'; | ||
}); | ||
}); | ||
}); | ||
|
||
$this->assertEquals([ | ||
'second transaction callback', | ||
'first transaction callback', | ||
], $calls); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters