-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[11.x] Skip the number of connections transacting while testing to run callbacks #53377
Open
tonysm
wants to merge
9
commits into
laravel:11.x
Choose a base branch
from
tonysm:tm/multi-db-transactions-callbacks-on-tests
base: 11.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[11.x] Skip the number of connections transacting while testing to run callbacks #53377
tonysm
wants to merge
9
commits into
laravel:11.x
from
tonysm:tm/multi-db-transactions-callbacks-on-tests
+102
−13
Conversation
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
…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.
@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
src/Illuminate/Foundation/Testing/DatabaseTransactionsManager.php
Outdated
Show resolved
Hide resolved
Signed-off-by: Mior Muhammad Zaki <[email protected]>
Signed-off-by: Mior Muhammad Zaki <[email protected]>
@tonysm I added Wondering if there any good tests we can add to cover using multiple database connection. |
Signed-off-by: Mior Muhammad Zaki <[email protected]>
Signed-off-by: Mior Muhammad Zaki <[email protected]>
@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
...Database/EloquentTransactionWithAfterCommitUsingRefreshDatabaseOnMultipleConnectionsTest.php
Show resolved
Hide resolved
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