0
1

More than 3 years have passed since last update.

Mockeryで警告出まくり!PHPStormで特定のブロックの特定の警告を無視する

Last updated at Posted at 2020-05-08

image.png

ぎゃー!

環境

  • 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);
        }
    }
0
1
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
0
1