The Wayback Machine - https://web.archive.org/web/20231128091738/https://github.com/laravel/framework/pull/48955
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

[10.x] ExpectsTable fails if new table prompt method is used #48955

Draft
wants to merge 1 commit into
base: 10.x
Choose a base branch
from

Conversation

jcergolj
Copy link

@jcergolj jcergolj commented Nov 9, 2023

This PR tries to fix the following bug:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use function Laravel\Prompts\table;

class DemoCommand extends Command
{
    protected $signature = 'run-demo-command';

    protected $description = 'Command description';

    public function handle(): void
    {
        table(['name', 'email'], [['joe doe', 'joe.doe@example.com']]);
    }
}

// test file
namespace Tests\Feature;

use Tests\TestCase;

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     */
    public function test_demo_command(): void
    {
        $this->artisan('run-demo-command')
            ->expectsTable(['name', 'email'], [['joe doe', 'joe.doe@example.com']]);
    }
}

// There was 1 failure:

// 1) Tests\Feature\ExampleTest::test_demo_command
// Output "+---------+---------------------+" was not printed

Based on my understanding, when a table is rendered, the method 'write' from the OutputStyle class is called and not 'doWrite' from BufferedOutput. That's why the expectation fails.

I tried to fix it, but I don't know what to pass to the mock here for the $table variable:

$mock->shouldReceive('write')
    ->once()
    ->ordered()
    ->with($table, Mockery::any())
    ->andReturnUsing(function () use ($i) {
        unset($this->test->expectedTables[$i]);
    });
@jcergolj jcergolj marked this pull request as draft November 9, 2023 11:04
@crynobone crynobone changed the title ExpectsTable fails if new table prompt method is used [10.x] ExpectsTable fails if new table prompt method is used Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant