Laravel artisan命令测试输出“+----+----------+------------+----------------------+&引用;没有印刷
我正在尝试测试artisan命令,该命令将给定客户id的db表作为输出。 在拉威尔8号Laravel artisan命令测试输出“+----+----------+------------+----------------------+&引用;没有印刷,laravel,unit-testing,testing,laravel-artisan,Laravel,Unit Testing,Testing,Laravel Artisan,我正在尝试测试artisan命令,该命令将给定客户id的db表作为输出。 在拉威尔8号 php artisan get:report "1" +----+----------+------------+---------------------+ | id | customer | date | value | +----+----------+------------+---------------------+ | 1 | 1
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);
}
}
我的问题是:
如何与命令输出交互?
这是执行此类测试的正确方法吗?
我是否需要一个函数来测试每个可能的输入
⨯ 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▕