PhpStorm plugin to provide smart autocomplete, code navigation and refactoring features for mocked class methods. Supported all versions of PhpStorm since 2017.1
| Key | Value |
|---|---|
| Plugin Url | https://plugins.jetbrains.com/plugin/9674 |
| ID | de.espend.idea.php.phpunit |
| Changelog | CHANGELOG |
| Build and Deployment | MAINTENANCE |
| Origin Fork | maxfilatov/phpuaca |
Stable version, JetBrains repository:
- Go to
PhpStorm -> Preferences... -> Plugins -> Browse repositories ...and search for PHPUnit Enhancement plugin - Restart PhpStorm
- method autocomplete for class, abstract class and trait mock objects;
- type providers:
getMock,getMockForAbstractClass, etc. will return mock object with methods of mocking class andPHPUnit_Framework_MockObject_MockObject; - supported PHPUnit methods:
PHPUnit_Framework_MockObject_MockBuilder::setMethodsPHPUnit_Framework_TestCase::getMockPHPUnit_Framework_TestCase::getMockClassPHPUnit_Framework_TestCase::getMockForAbstractClassPHPUnit_Framework_TestCase::getMockForTraitPHPUnit_Framework_MockObject_Builder_InvocationMocker::method
- type providers:
- code navigation (go to declaration, find usages, etc.) and refactoring (rename methods);
- highlighting of incorrect method usages;
- Prophecy support.
/** @var $x \PHPUnit\Framework\TestCase */
$x->createMock(Foo::class)->bar();/** @var $x \PHPUnit\Framework\TestCase */
$x->prophesize(Foo::class)->bar();class Foo extends \PHPUnit\Framework\TestCase
{
public function foobar()
{
$foo = $this->createMock(Foo::class);
$foo->method('<caret>')
}
}class Foo extends \PHPUnit\Framework\TestCase
{
public function setUp()
{
$this->foo = $this->createMock('Foo\Bar');
}
public function foobar()
{
$this->foo->method('<caret>');
}
}class FooTest extends \PHPUnit\Framework\TestCase
{
public function setUp()
{
$this->foo = $this->prophesize(Foo::class);
}
public function testFoobar()
{
$this->foo->getBar()->willReturn();
}
}class FooTest extends \PHPUnit\Framework\TestCase
{
public function setUp()
{
$this->foo = $this->getMockBuilder(\Foo::class);
}
public function testFoobar()
{
$this->foo->getMock()->bar();
}
}class FooTest extends \PHPUnit\Framework\TestCase
{
public function testFoobar()
{
$foo = $this->prophesize(Foo::class);
$foo->getBar()->willReturn();
}
}class FooTest extends \PHPUnit\Framework\TestCase
{
public function setUp()
{
$this->foo = $this->prophesize(Foo::class);
}
public function testFoobar()
{
$this->foo->getBar()->willReturn();
}
}class FooTest extends \PHPUnit\Framework\TestCase
{
public function testFoobar()
{
$foo = $this->prophesize(Foo::class);
$foo->reveal()->getBar();
}
}Use intention / generator to add new method mocks. Every caret position inside a mock object is detected
$foo = $this->getMockBuilder(Foobar::class)->getMock();
$foo->method('getFoobar')->willReturn();
$foo = $this->createMock(Foobar::class);
$foo->method('getFoobar')->willReturn();$this->foobar = $this->getMockBuilder(Foobar::class)->getMock();
// ...
$this->foobar->method('getFoobar')->willReturn();
$this->foobar = $this->createMock(Foobar::class);
// ...
$this->foobar->method('getFoobar')->willReturn();new Foobar();
// ...
new Foobar(
$this->createMock(Foo::class),
$this->createMock(FooBar::class)
);/**
* @expectedException \Foo\FooException
*/
public function testExpectedException()
{
$foo = new FooBar();
$foo->throwFooException();
}




