ぎゃー!
環境
- PHPStorm 2020.1.1
- mockery/mockery 1.3.1
概要
先日PHPStormを最新版にアップグレードしたところ、
Mockeryを使ってmockを作っている箇所が画像のように警告出まくり!まっ黄っ黄になっています!
原因はmockery内のアノテーション。
/**
* Expected argument setter for the expectation
*
* @param mixed|mixed[] ...$args
* @return self
*/
特に規則はないものの、可変引数の形式に配列を含めると、IDE側は引数に配列を期待してしまうようです。
解決策
プルリクしましょう。
4日前にすでにプルリクエストが出ていますので、そのうち改善するかと思います。
回避策
取り急ぎすぐにこの警告を無視したい場合、以下のように特定のブロックで警告を無視しておきましょうか。
(無関係の箇所で警告をオフにしたくないため)
public function test()
{
/**
* @noinspection PhpParamsInspection
* Mockeryが改善されるまで警告を無視
*/
{
$model = Mockery::mock(ExampleModel::class);
$model->shouldReceive('a')->once()->with('a')->andReturn($model);
$model->shouldReceive('b')->once()->withNoArgs()->andReturn($model);
$model->shouldReceive('c')->once()->with(Mockery::on(function ($arg) {
if ($arg instanceof Closure) {
$arg();
return true;
}
return false;
}))->andReturn($model);
}
}