0

I am writing phpunit code for some console command (in laravel 9.x). The command will generate a report like:

    2023-05-08 16:14:30
    Some Awsome Batch
    
    Batch Status : SUCCESS
    Start Time : 2023-05-08 16:14:26
    End Time : 2023-05-08 16:14:27
    DryRun: yes
    Billing month:

In real env, the above text is displayed in green color, because it was produced by $this->info(), and $this is derived from Illuminate\Console\Command.

Now I am working on phpunit to verify that report, like following:

    public function testBadBillingMonth()
    {

        $cmd = $this->artisan('command:GasLimitedTimePointGrant', [
            '--billingMonth' => '20230a'
        ]); 
        $cmd->run();

        printf("\n=====\n%s\n", $cmd->test->getActualOutput() ); // I got blank here :(

    }

My trouble is that, the 'output' catched by phpunit is 'blank', my little green report is gone.

If I use printf instead of $this->info() to produce the report, I woule be able to grab the content of report by $cmd->test->getActualOutput(), but I can't modify my test target to fit my test code. And we also use $this->error(), $this->warn() respectively.

So can we grab the output made by $this->error(), $this->warn(), $this->info() in phpunit?

Thanks in advance.

grizzlybears
  • 492
  • 2
  • 9

0 Answers0