LoginSignup
5
2

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-01-15

状況

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;
}
5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2