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

fixing expectsTable bug #3

Closed
wants to merge 1 commit into from
Closed

fixing expectsTable bug #3

wants to merge 1 commit into 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' form 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]);
    });

Copy link

github-actions bot commented Nov 9, 2023

Thank you for your pull request. However, you have submitted this PR on the Illuminate organization which is a read-only sub split of laravel/framework. Please submit your PR on the https://github.com/laravel/framework repository.

Thanks!

@github-actions github-actions bot closed this Nov 9, 2023
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