PhpStorm plugin to provide smart autocomplete, code navigation and refactoring features for mocked class methods. Supported all versions of PhpStorm since 2020.1
| Key | Value |
|---|---|
| Plugin Url | https://plugins.jetbrains.com/plugin/14672-phpunit-helper |
| ID | com.dimabdc.idea.php.phpunit |
| Changelog | CHANGELOG |
| Build and Deployment | MAINTENANCE |
| Origin Fork | Haehnchen/idea-php-phpunit-plugin |
Stable version, JetBrains repository:
- Go to
PhpStorm -> Preferences... -> Plugins -> Install Plugin from Disk ...and select PHPUnit Helper 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\MockObject\MockBuilder::onlyMethodsPHPUnit\Framework\MockObject\MockBuilder::addMethodsPHPUnit\Framework\MockObject\TestCase::getMockPHPUnit\Framework\MockObject\TestCase::getMockClassPHPUnit\Framework\MockObject\TestCase::getMockForAbstractClassPHPUnit\Framework\MockObject\TestCase::getMockForTraitPHPUnit\Framework\MockObject\Builder\InvocationMocker::methodPHPUnit\Framework\MockObject\MockObject::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 Foo extends \PHPUnit\Framework\TestCase { public function setUp() { $this->foo = $this->createMock('Foo\Bar'); } public function foobar() { $this->foo->bar(); } }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->getMockBuilder(\Foo::class) ->onlyMethods([ 'getFoobar', ]) ->addMethods([ 'getFoobaz', ]) ->getMock(); $foo->expects($this->once()) ->method('<caret>'); } }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(); }






