Links
Features
Completion
Completion PHP Phpunit Mock
Completes mocked class methods inside PHPUnit mock API strings. The plugin resolves the mocked class from createMock(), getMockBuilder()->getMock(), legacy getMock(), getMockForAbstractClass(), getMockForTrait(), and invocation mocker method() calls.
Completion inside method():
class InvoiceServiceTest extends \PHPUnit\Framework\TestCase
{
public function testTotal(): void
{
$gateway = $this->createMock(PaymentGateway::class);
$gateway->method('<caret>')->willReturn(true);
}
}
Completion after getMockBuilder():
$gateway = $this->getMockBuilder(PaymentGateway::class)
->disableOriginalConstructor()
->getMock();
$gateway->method('<caret>')->willReturn(true);
Completion PHP Phpunit Mock
Completes method names in the second argument of createPartialMock(). The same reference target is reused for navigation and rename support, so partial mocks stay connected to the original class methods.
Partial mock method array:
class ReportBuilderTest extends \PHPUnit\Framework\TestCase
{
public function testPartial(): void
{
$builder = $this->createPartialMock(ReportBuilder::class, ['<caret>']);
$builder->method('build')->willReturn('ready');
}
}
Completion PHP Mockery Mock
Completes method strings for Mockery expectations in allows(), expects(), shouldReceive(), shouldNotReceive(), shouldHaveReceived(), shouldNotHaveReceived(), array syntax, and generated partial mock declarations.
Expectation method strings:
$repository = \Mockery::mock(UserRepository::class);
$repository->allows('<caret>')->andReturns($user);
$repository->expects('<caret>')->once();
Array and generated partial syntax:
$repository->shouldReceive(['find' => $user, '<caret>' => []]);
$partial = \Mockery::mock(UserRepository::class . '[<caret>]');
Type Resolution
Type PHP Phpunit Mock
Resolves PHPUnit mock variables back to the mocked class, so normal PhpStorm method completion, navigation, and static analysis work on generated mocks. This covers createMock(), legacy getMock(), getMockClass(), getMockForAbstractClass(), getMockForTrait(), and getMockBuilder()->getMock() chains.
createMock() and getMockBuilder() return the mocked class type:
$gateway = $this->createMock(PaymentGateway::class);
$gateway->capture();
$builderMock = $this->getMockBuilder(PaymentGateway::class)
->disableOriginalConstructor()
->getMock();
$builderMock->refund();
Type PHP Phpunit Mock Type
Treats setUp() as the constructor-like setup scope for PHPUnit test classes. Mock assignments to $this fields are propagated to later test methods, so property mocks retain the generated mock type throughout the test case.
Mock created in setUp() and used in a test:
class CheckoutServiceTest extends \PHPUnit\Framework\TestCase
{
private PaymentGateway $gateway;
protected function setUp(): void
{
$this->gateway = $this->createMock(PaymentGateway::class);
}
public function testCharge(): void
{
$this->gateway->capture();
}
}
Type PHP Phpunit Prophecy Type
Resolves Prophecy doubles from prophesize() to the prophesized class and maps mocked method calls to Prophecy\Prophecy\MethodProphecy. reveal() is resolved back to the original class type, so both prophecy setup and revealed objects remain navigable.
Prophecy method and reveal() type resolution:
use Prophecy\Argument;
class PaymentGatewayTest extends \PHPUnit\Framework\TestCase
{
public function testCapture(): void
{
$gateway = $this->prophesize(PaymentGateway::class);
$gateway->capture(Argument::any())->willReturn(true);
$realGateway = $gateway->reveal();
$realGateway->capture(new PaymentRequest());
}
}
Type PHP Phpunit Prophecy Type
Improves types for Prophecy argument matchers. Argument::any() and Argument::cetera() inherit the parameter type from the prophesized method, and bundled PhpStorm meta support keeps Argument::type() aligned with the requested class.
Matcher arguments inherit the mocked method parameter type:
use Prophecy\Argument;
$gateway = $this->prophesize(PaymentGateway::class);
$gateway->capture(Argument::type(PaymentRequest::class))->willReturn(true);
$gateway->capture(Argument::any())->willReturn(true);
Type PHP Mockery Mock Type
Makes Mockery's newer fluent syntax usable in PhpStorm. After allows(), expects(), shouldReceive(), shouldNotReceive(), or shouldHaveReceived(), the next method call is treated as a method of the mocked class and the resulting expectation resolves to Mockery\Expectation.
Fluent Mockery syntax:
$repository = \Mockery::mock(UserRepository::class);
$repository->allows()->find(42)->andReturns($user);
$repository->expects()->save($user)->once();
Navigation
Navigation PHP Phpunit Mock Find Usages
Turns method strings in PHPUnit mock APIs into real references to the mocked class method. That enables go to declaration, find usages, and method rename refactoring from inside method(), setMethods(), and legacy PHPUnit mock builder strings.
Navigate from method string to class method:
$gateway = $this->createMock(PaymentGateway::class);
$gateway->method('capt<caret>ure')->willReturn(true);
Navigation PHP Phpunit Mock Find Usages
Method names inside createPartialMock() arrays are references to the original class. Rename a class method and the partial mock declaration is updated with the rest of the project.
Partial mock method reference:
$partial = $this->createPartialMock(PaymentGateway::class, ['capt<caret>ure']);
$partial->method('capture')->willReturn(true);
Navigation PHP Mockery Mock Find Usages
Adds references for Mockery method strings in parameter, array, and generated partial mock syntax. The contributor supports aliases, overloads, proxies, spies, runtime partial mocks, generated partial mocks, and class-string concatenation.
References in expectation strings and arrays:
$repository = \Mockery::mock(UserRepository::class);
$repository->expects('fi<caret>nd')->andReturns($user);
$repository->shouldReceive(['fi<caret>nd' => $user]);
References in generated partial mocks:
$partial = \Mockery::mock(UserRepository::class . '[fi<caret>nd]');
$partial = \Mockery::mock('App\\Repository\\UserRepository[sa<caret>ve]');
Linemarker
Inspections
Highlights method strings that cannot be resolved against the mocked class. PHPUnit and Mockery strings warn when the target method is missing; Mockery also warns for private methods and discourages protected method mocking.
Warnings for unknown or inaccessible mocked methods:
$gateway = $this->createMock(PaymentGateway::class);
$gateway->method('missingMethod');
$repository = \Mockery::mock(UserRepository::class);
$repository->expects('privateMethod');
$repository->allows('protectedMethod');
Reports mocked method strings that point to deprecated class methods. The inspection covers both normal PHPUnit method() mocks and createPartialMock() method arrays.
Deprecated method used by PHPUnit mocks:
final class PaymentGateway
{
/** @deprecated use authorize() */
public function capture(): bool
{
return true;
}
}
$gateway = $this->createMock(PaymentGateway::class);
$gateway->method('capture');
$partial = $this->createPartialMock(PaymentGateway::class, ['capture']);
Detects legacy shouldReceive() and shouldNotReceive() chains and offers a quick fix to convert them to modern Mockery syntax. The inspection can prefer array notation, multiple statements, string notation, or fluent allows()->method() notation.
Legacy shouldReceive() converted to allows():
$repository->shouldReceive('find')->with(42)->andReturn($user);
$repository->allows('find')->with(42)->andReturns($user);
once() expectations become expects():
$repository->shouldReceive('save')->once();
$repository->expects('save');
Optional fluent Mockery target style:
$repository->shouldReceive('find')->with(42)->andReturn($user);
$repository->allows()->find(42)->andReturns($user);
Intentions
Provides a PHPUnit run intention when the caret is inside a PHPUnit test method or test class. It delegates to PhpStorm's PHPUnit runner and starts the run/debug action from the current scope.
Run from a test method or class:
class InvoiceServiceTest extends \PHPUnit\Framework\TestCase
{
public function testCharge(): void
{
self::assertTrue(true);
}
}
Collects public, non-static, non-final methods from the mocked class and inserts method()->willReturn() statements for the selected methods. It works on mock variables, fields, and assignments created through createMock() or getMockBuilder().
Before:
$gateway = $this->createMock(PaymentGateway::class);
After selecting capture:
$gateway = $this->createMock(PaymentGateway::class);
$gateway->method('capture')->willReturn();
Adds missing constructor arguments in PHPUnit tests by creating mocks for class-typed parameters and safe placeholder values for primitive parameters. The intention also inserts imports where needed before rewriting the new expression.
Before:
$service = new CheckoutService();
After generating constructor mocks:
$service = new CheckoutService(
$this->createMock(PaymentGateway::class),
$this->createMock(LoggerInterface::class)
);
Scans method calls in the current PHPUnit test method, collects thrown exception classes from PhpStorm's exception analyzer, and inserts the selected expectException() assertion near the test start.
Before:
public function testFailure(): void
{
$gateway = new PaymentGateway();
$gateway->charge();
}
After inserting the expected exception:
public function testFailure(): void
{
$this->expectException(PaymentFailedException::class);
$gateway = new PaymentGateway();
$gateway->charge();
}
Other
Other PHP Phpunit Legacy
Keeps support for legacy helper APIs from the original PHPUnit Autocomplete Assistant fork. Method and property strings in MethodMock and PHPUnit_Helper helpers receive completion, references, and validation against the target class.
Legacy helper method and property strings:
MethodMock::mockMethodResult(PaymentGateway::class, 'capture', true);
MethodMock::callProtectedMethod(PaymentGateway::class, 'buildPayload', []);
PHPUnit_Helper::getProtectedPropertyValue($service, 'gateway');
PHPUnit_Helper::callProtectedMethod($service, 'buildPayload', []);