Skip to content

[12.x] Pipeline::withinTransaction() accepts connection #56550

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

Merged
merged 5 commits into from
Aug 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
tests
  • Loading branch information
cosmastech committed Aug 5, 2025
commit 710980989816e38027f789143bce982c3e5f53f2
2 changes: 1 addition & 1 deletion src/Illuminate/Pipeline/Pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Pipeline implements PipelineContract
/**
* Indicates whether to wrap the pipeline in a database transaction.
*
* @var string|false|null|\UnitEnum
* @var string|null|\UnitEnum|false
*/
protected $withinTransactions = false;

Expand Down
44 changes: 41 additions & 3 deletions tests/Pipeline/PipelineTransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Pipeline;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class PipelineTransactionTest extends TestCase
{
Expand All @@ -18,16 +19,48 @@ public function testPipelineTransaction()

$result = Pipeline::withinTransactions()
->send('some string')
->through([function ($value, $next) {
return $next($value);
}])
->through([
function ($value, $next) {
return $next($value);
}
])
->thenReturn();

$this->assertEquals('some string', $result);
Event::assertDispatched(TransactionBeginning::class);
Event::assertDispatched(TransactionCommitted::class);
}

public static function transactionConnectionDataProvider(): array
{
return [
'unit enum' => [EnumForPipelineTransactionTest::DEFAULT, 'testing'],
'string' => ['testing', 'testing'],
'null' => [null, 'testing2'],
];
}
#[DataProvider('transactionConnectionDataProvider')]
public function testConnection($connection, $connectionName)
{
Event::fake();
config(['database.connections.testing2' => config('database.connections.testing')]);
config(['database.default' => 'testing2']);

$result = Pipeline::withinTransactions($connection)
->send('some string')
->through([
function ($value, $next) {
return $next($value);
}
])
->thenReturn();

$this->assertEquals('some string', $result);
Event::dispatched(TransactionBeginning::class, function(TransactionBeginning $event) use ($connectionName) {
return $event->connection === $connectionName;
});
}

public function testExceptionThrownRollsBackTransaction()
{
Event::fake();
Expand All @@ -54,3 +87,8 @@ function ($value, $next) {
Event::assertDispatched(TransactionRolledBack::class);
}
}

enum EnumForPipelineTransactionTest: string
{
case DEFAULT = 'testing';
}
Loading