Skip to content

[11.x] Database testing traits has impact to artisan calls#54458

Merged
taylorotwell merged 1 commit intolaravel:11.xfrom
nivseb:clear-outputstyle-mock
Feb 5, 2025
Merged

[11.x] Database testing traits has impact to artisan calls#54458
taylorotwell merged 1 commit intolaravel:11.xfrom
nivseb:clear-outputstyle-mock

Conversation

@nivseb
Copy link
Copy Markdown
Contributor

@nivseb nivseb commented Feb 3, 2025

The PendingCommand creats a mock for OutputStyle and bind that mock to the app. This binding is only cleared if the app is cleared. The PendingCommand should cleare that Mock. This left over binding has inpact to tests and code.
This is especially unexpected when the test use one of the the traits DatabaseMigrations, DatabaseTrunctation or RefreshDatabase. That traits give the impression that they have inpact to console/artisan behavior.

<?php

namespace Tests;

use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Testing\DatabaseTruncation;
use Illuminate\Foundation\Testing\TestCase;
use Illuminate\Support\Facades\Artisan;
use Symfony\Component\Console\Output\BufferedOutput;

class DemoTest extends TestCase
{
    use DatabaseTruncation;

    public function createApplication(): Application
    {
        $app = require __DIR__.'/../bootstrap/app.php';

        $app->make(Kernel::class)->bootstrap();

        return $app;
    }

    public function testNumberOne() : void {
        $buffer     = new BufferedOutput();
        Artisan::call('inspire', [], $buffer);
        self::assertNotEmpty($buffer->fetch());
    }

    public function testNumberTwo() : void {
        $buffer     = new BufferedOutput();
        Artisan::call('inspire', [], $buffer);
        self::assertNotEmpty($buffer->fetch());
    }
}

@nivseb nivseb changed the title clear OutputStyle binding in PendingCommand Database testing traits has inpack to artisan calls Feb 3, 2025
@crynobone crynobone changed the title Database testing traits has inpack to artisan calls Database testing traits has impact to artisan calls Feb 4, 2025
@crynobone crynobone changed the title Database testing traits has impact to artisan calls [11.x] Database testing traits has impact to artisan calls Feb 4, 2025
@taylorotwell taylorotwell merged commit 062039b into laravel:11.x Feb 5, 2025
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