dongqiao1964 2015-04-28 09:29
浏览 70
已采纳

使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?

  • 写回答

1条回答 默认 最新

  • dousao2186 2015-04-28 09:36
    关注

    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(
            );
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vc6.0中想运行代码的时候总是提示无法打开文件是怎么回事
  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题