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

UseComponentPropertyWithinCommandsRector causes expectsOutput error in tests #301

Closed
trovster opened this issue Jan 29, 2025 · 1 comment

Comments

@trovster
Copy link

I ran the UseComponentPropertyWithinCommandsRector and the tests for my commands failed.

I have built a basic test case, which uses PHP 8.2 and PHPUnit 11.5.

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class MyCommand extends Command
{
    protected $signature = 'my-command';

    public function handle(): int
    {
        $this->info('Info Finished.');
        $this->components->info('Components Finished.');

        return Command::SUCCESS;
    }
}

And the test…

<?php

declare(strict_types=1);

namespace Tests\Feature\Commands;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;

#[Group('command')]
final class MyCommandTest extends TestCase
{
    #[Test]
    public function expectOutput(): void
    {
        $this->artisan('my-command')
            ->expectsOutput('Info Finished.')
            ->expectsOutput('Components Finished.')
            ->assertSuccessful();
    }
}

Gives the following error;

1) Tests\Feature\Commands\MyCommandTest::expectOutput
Output "Components Finished." was not printed.
@GeniJaho
Copy link
Collaborator

This happens because when using ->components it adds extra padding/styling to the output, so it will not be identical to just the text.
You need to use ->expectsOutputToContain() instead. Or not use components if you need exact text assertions 😄.

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

No branches or pull requests

2 participants