工匠命令测试输出“ + ---- + ---------- + ------------ + --------------- ------- +“未打印

时间:2020-10-14 16:55:56

标签: laravel unit-testing testing laravel-artisan

我正在尝试测试一个工匠命令,该命令为给定的客户ID提供一个db表作为输出。 在Laravel 8上。

php artisan get:report "1"
+----+----------+------------+---------------------+
| id | customer | date       | value               |
+----+----------+------------+---------------------+
| 1  | 1        | 01/04/2015 | EUR 55.201818920353 |
| 5  | 1        | 02/04/2015 | EUR 12.188561617614 |
| 6  | 1        | 02/04/2015 | EUR 1.00            |
| 7  | 1        | 03/04/2015 | EUR 14.050917779273 |
+----+----------+------------+---------------------+

所以我写了这个单元测试:

<?php

namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;


class GetReportTest extends TestCase
{
    
    protected $tableHeader=['id', 'customer', 'date','value'];
    protected $rows=[[1,'1','01/04/2015' , 'EUR 55.201818920353'],
                        [5,'1' ,'02/04/2015',' EUR 12.188561617614'],
                        [6,'1','02/04/2015','EUR 1.00' ],
                        [7,'1','03/04/2015','EUR 14.050917779273' ]  ];
  
    
     /** @test */
    public function getReportCommand()
    {
        $this->assertTrue(class_exists(\App\Console\Commands\GetClientReport::class));
    }
    
    /** @test */
    public function itCanGetReport()
    {
        $this->artisan('get:report "1"')->expectsTable($this->tableHeader,$this->rows)
        ->assertExitCode(0);
        $this->assertTrue(true);


    }
    
  
}

第一个测试(getReportCommand())有效,测试通过。 第二个不,给我这个错误:

⨯ it can get report

  ---

  • Tests\Unit\GetReportTest > it can get report
  Output "+----+----------+------------+----------------------+" was not printed.

  at tests/Unit/GetReportTest.php:29
     25▕     /** @test */
     26▕     public function itCanGetReport()
     27▕     {
     28▕         $this->artisan('get:report "1"')->expectsTable($this->tableHeader,$this->rows)
  ➜  29▕         ->assertExitCode(0);
     30▕                                 
     31▕                                 
     32▕ 
     33▕ 

我的问题是: 我如何与命令输出进行交互? 是执行此类测试的正确方法吗? 我需要一个功能来测试每个可能的输入吗?

0 个答案:

没有答案