考虑以下测试用例:
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);
}
因为在$this->foo
setUp
中实例化了Foo
PhpStorm并未在后续测试方法中将其识别为bar
的实例。结果,很多IDE电源丢失(失去完成查找等)。 PhpStorm甚至抱怨$this->foo
不是setUp
的方法,即使它是。{/ p>
是否有一种有效的方法让PhpStorm识别__construct
中定义的实例;就像在app.directive('languagePicker', function() {
return {
template : '<ui-select ng-model="**PARENT'S NGMODEL**" multiple search-enabled="true" theme="select2" style="width: 300px;"><ui-select-match >{{$item.name}}</ui-select-match><ui-select-choices repeat="lang.id as lang in langs | filter: { name : $select.search }"><div ng-bind-html="lang.name | highlight: $select.search"></div></ui-select-choices></ui-select>',
restrict : 'E',
require : 'ngModel',
replace : true,
scope: {
ngModel: "=ngModel"
}
...
};
});
中定义它们一样?也许我缺少一整套PhpStorm功能?或者只是一个hacky工作?
答案 0 :(得分:2)
PHPStorm读取标准PHPDOC,例如您可以定义为:
class CustomerHelperTest extends \PHPUnit_Framework_TestCase{
/**
* @var \Acme\DemoBundle\Service\CustomerHelper
*/
protected $customerHelper;
protected function setUp()
{
$this->customerHelper = new CustomerHelper(
);
}