[11.x] Skip the number of connections transacting while testing to run callbacks#53377
Merged
taylorotwell merged 10 commits intoNov 11, 2024
Merged
Conversation
…acks 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.
Contributor
Author
|
@crynobone could you take a look at the changes here as well, pls? The mentioned discussion has some examples: <?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class ExampleTest extends TestCase
{
protected array $connectionsToTransact = ['sqlite', 'second'];
use RefreshDatabase;
public function test_with_nested_transaction_on_default_connection(): void
{
$executed = false;
// Works as expected...
DB::transaction(function () use (&$executed) {
DB::afterCommit(function () use (&$executed) {
$executed = true;
});
});
$this->assertTrue($executed); // SUCCEEDS!
}
public function test_without_nested_transaction_on_default_connection(): void
{
$executed = false;
// Should execute right away, since there are no application-level
// transactions (only the two from the tests), but it doesn't...
DB::afterCommit(function () use (&$executed) {
$executed = true;
});
$this->assertTrue($executed); // FAILS!
}
} |
crynobone
reviewed
Nov 4, 2024
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Member
|
@tonysm I added Wondering if there any good tests we can add to cover using multiple database connection. |
Contributor
Author
|
@crynobone I've added some tests, can't think of any other useful examples |
crynobone
approved these changes
Nov 5, 2024
crynobone
reviewed
Nov 5, 2024
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changed
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.
related PRs: #48523
resolves #53334