简体   繁体   English

如何使用phpspec获取代码自动完成功能

[英]How to get code auto-completion with phpspec

I've just started learning phpspec with a view to replacing PHPUnit. 我刚刚开始学习phpspec以取代PHPUnit。 Unfortunately, I've got rather hooked on using the PHPStorm editor's code completion feature, which makes even PHPUnit's verbose mock interface very quick to type. 不幸的是,我更喜欢使用PHPStorm编辑器的代码完成功能,这使得即使是PHPUnit的详细模拟界面也可以非常快速地输入。

No such luck with phpspec. phpspec没有这样的运气。 Given a class like this: 鉴于这样的类:

<?php

namespace spec\MyVendor\MyClass;

use PhpSpec\ObjectBehavior;

class MyClassSpec extends ObjectBehavior
{
    function it_is_initializable()
    {
        $this->shouldHaveType('MyVendor\MyClass');
    }

    function it_should_do_something()
    {
        $this->???
    }
}

Firstly, shouldHaveType is showing the 'method not found' highlight, and secondly, if I try to autocomplete at the ??? 首先, shouldHaveType显示'找不到方法'突出显示,其次,如果我尝试自动完成在??? point, my options are limited to the few methods in ObjectBehaviour . 点,我的选项仅限于ObjectBehaviour的几个方法。 I would want to see things like shouldHaveType , shouldImplement , and many more. 我想看看像shouldHaveTypeshouldImplement等等。

I've found this phpspec-stubs repository on Github, but it seems to only have one method defined, and requires extending a wrapper class. 我在Github上找到了这个phpspec-stubs存储库,但它似乎只定义了一个方法,并且需要扩展一个包装类。

There's also a PHPStorm plugin but it's not clear to me if this should provide auto-complete, and the current version gives me a NullPointerException in PHPStorm immediately on entering any PHP file. 还有一个PHPStorm插件,但我不清楚这是否应该提供自动完成,并且当前版本在输入任何PHP文件时立即在PHPStorm中给我一个NullPointerException。

So, are all you phpspec users typing a lot, or is there another solution? 那么,你们所有的phpspec用户都打字很多,还是有另一种解决方案?

Update : PhpStorm has a built in support for PhpSpec since 2016.3 . 更新自2016年以来, PhpStorm内置了对PhpSpec的支持。 We can only expect it will be improved with each new release. 我们只能期望每个新版本都会改​​进它。

The PhpStorm plugin for PhpSpec from the question is not really maintained, but you could try another solution. 来自问题的PhpSpec的PhpStorm插件并没有真正维护,但您可以尝试其他解决方案。 Since PhpStorm 7 it is possible to use the @mixin annotation: 从PhpStorm 7开始,可以使用@mixin注释:

<?php

namespace spec\MyVendor;

use MyVendor\MyClass;
use PhpSpec\ObjectBehavior;

/**
 * @mixin MyClass
 */
class MyClassSpec extends ObjectBehavior
{
    function it_is_initializable()
    {
        $this->shouldHaveType('MyVendor\MyClass');
    }

    function it_should_do_something()
    {
        $this->doSomething(':D');
    }
}

Sources: 资料来源:

For proper PhpSpec support in PHPStorm give your vote here : https://youtrack.jetbrains.com/issue/WI-22670 要获得PHPStorm中正确的PhpSpec支持,请在此处投票https//youtrack.jetbrains.com/issue/WI-22670

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM