When setting up a new site using PHPUnit 8.x and PHP 7.2, I got the error message:
setUp() must be compatible with PHPUnit\Framework\TestCase::setUp
Because we can now define the method as returning no value (with :void
) and this is part of the method definition starting in PHPUnit 8.0.0, we need to add this in our code, as well. In other words, cut and paste from my old project didn’t work. 😀
Code I Was Trying to use
protected function setUp() {
parent::setUp();
Monkey\setUp();
}
protected function tearDown() {
Monkey\tearDown();
parent::tearDown();
}
Code I Needed to Use
protected function setUp(): void {
parent::setUp();
Monkey\setUp();
}
protected function tearDown(): void {
Monkey\tearDown();
parent::tearDown();
}
it saved me time 😉
thanks!
Legend thanks for this!
Heaps useful! Thanks
my code shows this error:
Declaration of Illuminate\Foundation\Testing\TestCase::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp()
so I need to modify the file inside vendor folder?
Thank you!