I've just started learning phpspec with a view to replacing 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.
No such luck with 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 ???
point, my options are limited to the few methods in ObjectBehaviour
. I would want to see things like shouldHaveType
, shouldImplement
, and many more.
I've found this phpspec-stubs repository on Github, but it seems to only have one method defined, and requires extending a wrapper class.
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.
So, are all you phpspec users typing a lot, or is there another solution?
Update: PhpStorm has a built in support for PhpSpec since 2016.3. 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. Since PhpStorm 7 it is possible to use the @mixin
annotation:
<?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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With