使PhpStorm识别PHPUnit setUp中定义的实例
Consider the following test case:
class FooTest extends \PHPUnit_Framework_TestCase
{
public $foo;
public function setUp()
{
$this->foo = new Foo();
}
public function testBar()
{
$expected = 42;
$actual = $this->foo->bar();
$this->assertEqual($expected, $actual);
}
Because $this->foo
is instantiated in setUp
PhpStorm doesn't recognize it as an instance of Foo
in the subsequent test methods. As a result a lot of the IDE power is lost (loosing completion lookups and such). PhpStorm even complains that bar
isn't a method of $this->foo
even though it is.
Is there an effective way of getting PhpStorm to recognize instances defined in setUp
; much like it would if they were defined in __construct
? Maybe there's a whole suite of PhpStorm functionality I'm missing? Or just a hacky work around?
考虑以下测试用例: p>
类FooTest extends \ PHPUnit_Framework_TestCase
{
public $ foo;
public function setUp()
{
$ this-> foo = new Foo();
}
公共函数testBar()
{
$ expected = 42;
$ actual = $ this-> foo-> bar();
$ this-> assertEqual($ expected,$ actual);
}
pre>
因为 $ this-> foo code>在 setUp code>中实例化PhpStorm不会将其识别为 Foo code>。 结果,很多IDE电源丢失(失去完成查找等)。 PhpStorm甚至抱怨 bar code>不是 $ this-> foo code>的方法,即使它是。 p>
是否有 让PhpStorm识别 setUp code>中定义的实例的有效方法; 很像它们是在 __ construct code>中定义的吗? 也许我缺少一整套PhpStorm功能? 或只是一个hacky工作? p>
div>
PHPStorm read the standard PHPDOC, as example you can define as:
class CustomerHelperTest extends \PHPUnit_Framework_TestCase{
/**
* @var \Acme\DemoBundle\Service\CustomerHelper
*/
protected $customerHelper;
protected function setUp()
{
$this->customerHelper = new CustomerHelper(
);
}