Skip to content
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] Database testing traits has impact to artisan calls #54458

Open
wants to merge 1 commit into
base: 11.x
Choose a base branch
from

Conversation

nivseb
Copy link

@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
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.

1 participant