Skip to content

Conversation

kevinb1989
Copy link
Contributor

@kevinb1989 kevinb1989 commented Feb 26, 2025

Similar to the following testing classes:

  • Illuminate\Testing\TestResponse
  • Illuminate\Mail\Mailable

I want to make the Illuminate\Testing\PendingCommand class tappable too. I find this useful when I have some logics around assertions, or want to assert against a set of items. So I can do all assertions in one go.

I got the following example:

use App\Models\Order;

function test_refunding()
{
    $paidOrders = Order::factory()
        ->count(3)
        ->paid()
        ->create();

    $unpaidOrders = Order::factory()
        ->count(3)
        ->unpaid()
        ->create();

    $this->artisan('orders:refunding', ['--ids' => $paidOrders->merge($unpaidOrders)->implode('id', ', ')])
        ->expectsOutput('Start Refunding...')
        ->tap(function ($command) use ($paidOrders, $unpaidOrders) {
            foreach ($paidOrders as $order) {
                $command->expectsOutput("Order $order->id has been refunded.");
            }

            foreach ($unpaidOrders as $order) {
                $command->expectsOutput("Order $order->id is not yet paid.");
            }
        });
}

@taylorotwell taylorotwell merged commit 2fbac93 into laravel:12.x Feb 26, 2025
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants