LoginSignup
1
0

MockeryのshouldReceiveがvscode上でundefinedになり赤線が消えない

Posted at

現象

サンプルコード

class SampleTest extends TestCase
{
  public SampleRepositoryInterface $repository;

  public function setUp()
  {
    parent::setUp();
    $this->repository = \Mockery::mock(SampleRepositoryInterface::class);
  }
  
  public function test_sample()
  {
    $this->repository->shouldReceive('getAll')->andReturn([]);
  }
}

SampleRepositoryInterfaceshouldReceiveを定義していないので赤線が出る。
スクリーンショット 2023-05-21 22.00.01.png

解消方法

アノテーションで\Mockery\MockInterfaceを指定することでphp-intelephenseがshouldReceiveを認識できるようになる。

/**
 * @var SampleRepositoryInterface|\Mockery\MockInterface $repository
 * /
public SampleRepositoryInterface $repository;

スクリーンショット 2023-05-21 22.14.23.png

参考

https://github.com/bmewburn/vscode-intelephense/issues/1784#issuecomment-1208644051
https://github.com/bmewburn/intelephense-docs/blob/master/gettingStarted.md#type-declarations-and-annotations

1
0
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
1
0