Help us understand the problem. What is going on with this article?

Declaration of <クラス名>::<メソッド名> should be compatible with <クラス名>::<メソッド名>

状況

phpunitのsetUp()メソッドを設定した時に、タイトルのエラーが発生

エラー内容と対象方法

setUp()メソッドは親クラスのメソッドをオーバーライドしているのですが、
オーバーライド元とオーバーライド先でメソッドの引数または戻り値が異なる場合にエラーが発生します。

この場合、親クラスの戻り値が以下の通りvoidとなっているため、
オーバーライド先でも同様の指定が必要となります。

TestCase.php
/**
* Setup the test environment.
*
* @return void
*/
protected function setUp(): void
{
    if (! $this->app) {
        $this->refreshApplication();
    }

    $this->setUpTraits();

    foreach ($this->afterApplicationCreatedCallbacks as $callback) {
        $callback();
    }

    Facade::clearResolvedInstances();

    Model::setEventDispatcher($this->app['events']);

    $this->setUpHasRun = true;
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away