Laravel-activitylog: >PHP7.2: Declaration of Orchestra\Testbench\TestCase::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp()

Created on 14 Feb 2019  路  23Comments  路  Source: spatie/laravel-activitylog

phpunit --coverage-text --coverage-clover=coverage.clover
PHP Fatal error: Declaration of Orchestra\Testbench\TestCase::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in /home/travis/build/spatie/laravel-activitylog/vendor/orchestra/testbench-core/src/TestCase.php on line 15

Most helpful comment

@AndresMatta in TestCase.php file add :void

public function setUp(): void

All 23 comments

Feel free to require PHP 7.2 and PHPUnit 8. Support for PHP 7.1, PHPUnit 7 may be dropped. We're doing this with all our other packages too whenever we touch them..

@freekmurze the problem was the global phpunit instead of our vendor/bin/phpunit.

馃憤

laravel 5.8 <, phpunit8<, I got same error. @freekmurze, how can I fix? @Gummibeer

@nanophp could you provide the precise versions you use? This will allow me to check what's going wrong and where we have to fix something.

Hi @Gummibeer, I got the same problem after upgrade Laravel version to 5.8
I added setUp() function to test files, but it can't resolve, still above error
public function setUp()
{
parent::setUp();
}

@haiphan2710 the same question could you provide the exact versions you are using (Laravel & phpunit & activitylog)?
composer show package/name

I use phpunit 8 and laravel 5.8
solved, thanks

I use phpunit 8 and laravel 5.8
solved, thanks

and how did you solved it?

@AndresMatta in TestCase.php file add :void

public function setUp(): void

I got the same problem with laravel 5.8 and phpunit 8. Thanks @nusendra

you're welcome @majorsabbir

: void

this works along with version 8 of phpunit. What is the :void for though?

@jordanboston yes, add :void to setUp()

Yes, :void it works, I was just not sure what it's doing. :)

@jordanboston void is the return type, meaning that the setUp method will return nothing.

The error was thrown because we're overriding the method from PHPUnit, so it must use exactly the same signature PHPUnit uses:

/**
 * This method is called before each test.
 */
protected function setUp(): void
{
}

See the docs for more info on return types.

i used laravel5.8 and enter :void but error the same why?

void

@shabancareer did you declare your method as protected? Can you share the code in for the method Tests\TestCase::setUp()?

@shabancareer did you solve this problem ?
I am also stuck here even after adding void still the same error.

My solution is to downgrade phpunit in the project composer.json to ^7.0 "phpunit/phpunit": "^7.0" and everything works because some packages still follows phunit7

Thanks @tigusigalpa now it works for me!

@AndresMatta in TestCase.php file add :void

public function setUp(): void

I had to login to like you, thank you so much

Was this page helpful?
0 / 5 - 0 ratings