Reputation: 1200
Make PhpStorm autocomplete fields defined in phpUnit's setUp method.
If I define a mock in setUp method:
public function setUp()
{
$this->testRepo = $this->getMockBuilder(TestRepository::class)
->disableOriginalConstructor()
->getMock();
}
When I want to use this mock in other methods:
public function testExample()
{
$this->testRepo->.... at this point phpStorm does not show autocomplete options
}
I understand that phpStorm doesn't know that setUp method is run before each other test method but maybe there's a way to fix this behavior.
I also don't want to add phpDoc to each property defined. I find this pretty robust and ugly:
/**
* @var PHPUnit_Framework_MockObject_MockObject
*/
protected $testRepo;
PS: Stackoverflow editor is s**t
Upvotes: 1
Views: 425
Reputation: 39390
Change the PHPDoc annotation as follow:
/**
* @var \PHPUnit_Framework_MockObject_MockObject|TestRepository
*/
protected $testRepo;
hope this help
Upvotes: 2