nunomaduro / termwind

🍃 In short, it's like Tailwind CSS, but for the PHP command-line applications.
MIT License
2.29k stars 78 forks source link

Disable output during tests #174

Closed eleftrik closed 1 year ago

eleftrik commented 1 year ago

Maybe it's a dumb question, but I didn't find any solutions.

Is it possible to disable termwind output when tests are running? Let's say there is a simple command which outputs text with $this->info() and render():

    public function handle(): int
    {
        $this->info("Green text");
        render('<div class="text-red-500">Red text</div>');

        return self::SUCCESS;
    }

and a simple test (Pest):

<?php

use App\Console\Commands\TestCommand;

use function Pest\Laravel\artisan;

it('returns a successful response', function () {
    artisan(TestCommand::class)
        ->assertOk();
});

When tests are running, "Green text" will not show, while "Red text" will. I think both should not be rendered while tests are running.

What's the best way to make render() behave like standard output functions?

Thank you

xiCO2k commented 1 year ago

You can use renderUsing(new BufferedOutput).

eleftrik commented 1 year ago

Ok, now I've setup my Pest test like this:

<?php

use Symfony\Component\Console\Output\BufferedOutput;

use function Pest\Laravel\artisan;
use function Termwind\renderUsing;

beforeEach(fn() => renderUsing(new BufferedOutput()));

...and the output while tests are running is gone.

Thank you @xiCO2k!

xiCO2k commented 1 year ago

Awesome 💪

jdreesen commented 1 year ago

If you really don't need the output, there's also Symfony\Component\Console\Output\NullOutput.