测试用例添加 setUp()方法之后执行错误?
ProductTest文件
<?php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Product;
class ProductTest extends TestCase
{
public $product;
public function setUp()
{
parent::setUp();
$this->product = new Product('xiaocai', 59);
}
/**
* A basic unit test example.
*
* @return void
*/
public function testName()
{
$this->assertEquals('xiaocai', $this->product->name());
}
public function testPrice()
{
$this->assertEquals(59, $this->product->price());
}
}
执行./vendor/bin/phpunit --filter ProductTest之后出现如下错误
$ ./vendor/bin/phpunit --filter ProductTest
PHP Fatal error: Declaration of Tests\Unit\ProductTest::setUp() must be compatible with Illuminate\Foundation\Testing\TestCase::setUp(): void in D:\study\XAMPP\htdocs\laravel-phpunit\tests\Unit\ProductTest.php on line 33
Fatal error: Declaration of Tests\Unit\ProductTest::setUp() must be compatible with Illuminate\Foundation\Testing\TestCase::setUp(): void in D:\study\XAMPP\htdocs\laravel-phpunit\tests\Unit\ProductTest.php on line 33
哦,你用的5.8啊,5.8要求setUp tearDown的返回类型为void