Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

nivseb
Copy link
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
40 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants