У меня есть несколько тестовых функций в Laravel 7:
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;
class ReadThreadsTest extends TestCase
{
use DatabaseMigrations;
public function setUp()
{
parent::setUp();
$this->thread = factory('App\Thread')->create();
}
public function test_a_user_can_view_all_threads()
{
$response = $this->get('/threads');
$response->assertSee($this->thread->title);
}
Когда я запускаю phpunit, я получаю:
PHP Fatal error: Declaration of Tests\Feature\ReadThreadsTest::setUp() must be compatible with Illuminate\Foundation\Testing\TestCase::setUp(): void in C:\xampp\htdocs\forum\tests\Feature\ReadThreadsTest.php on line 9
PHP Stack trace:
PHP 1. {main}() C:\xampp\htdocs\forum\vendor\phpunit\phpunit\phpunit:0
PHP 2. PHPUnit\TextUI\Command::main() C:\xampp\htdocs\forum\vendor\phpunit\phpunit\phpunit:61
PHP 3. PHPUnit\TextUI\Command->run() C:\xampp\htdocs\forum\vendor\phpunit\phpunit\src\TextUI\Command.php:163
PHP 4. PHPUnit\TextUI\Command->handleArguments() C:\xampp\htdocs\forum\vendor\phpunit\phpunit\src\TextUI\Command.php:171
PHP 5. PHPUnit\Util\Configuration->getTestSuiteConfiguration() C:\xampp\htdocs\forum\vendor\phpunit\phpunit\src\TextUI\Command.php:929
PHP 6. PHPUnit\Util\Configuration->getTestSuite() C:\xampp\htdocs\forum\vendor\phpunit\phpunit\src\Util\Configuration.php:881
PHP 7. PHPUnit\Framework\TestSuite->addTestFiles() C:\xampp\htdocs\forum\vendor\phpunit\phpunit\src\Util\Configuration.php:1005
PHP 8. PHPUnit\Framework\TestSuite->addTestFile() C:\xampp\htdocs\forum\vendor\phpunit\phpunit\src\Framework\TestSuite.php:452
PHP 9. PHPUnit\Util\FileLoader::checkAndLoad() C:\xampp\htdocs\forum\vendor\phpunit\phpunit\src\Framework\TestSuite.php:354
PHP 10. PHPUnit\Util\FileLoader::load() C:\xampp\htdocs\forum\vendor\phpunit\phpunit\src\Util\FileLoader.php:47
PHP 11. include_once() C:\xampp\htdocs\forum\vendor\phpunit\phpunit\src\Util\FileLoader.php:59
Fatal error: Declaration of Tests\Feature\ReadThreadsTest::setUp() must be compatible with Illuminate\Foundation\Testing\TestCase::setUp(): void in C:\xampp\htdocs\forum\tests\Feature\ReadThreadsTest.php on line 9
Я делаю что-то не так с parent :: setUp , но что? Я попытался добавить: void (), но это изменило только ошибку на:
PHP Parse error: syntax error, unexpected ':' in c:\xampp\htdocs\forum\tests\Feature\ReadThreadsTest.php
Любой совет?
С уважением,
Hubert