# PHPUnit Enhancement Plugin Types

**Types** features improve type inference for PHPUnit mocks, `setUp()` property mocks, Prophecy doubles, Prophecy argument matchers, and Mockery fluent expectations.

---

## PHPUnit mock object type inference

**Feature ID:** `PhpUnitMockTypeProvider`  
**Feature Page:** [PHPUnit mock object type inference](https://espend.de/phpstorm/plugin/phpunit#php-unit-mock-type-provider)  

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.

### Code Examples

```php
# createMock() and getMockBuilder() return the mocked class type:
$gateway = $this->createMock(PaymentGateway::class);
$gateway->capture();

$builderMock = $this->getMockBuilder(PaymentGateway::class)
    ->disableOriginalConstructor()
    ->getMock();

$builderMock->refund();
```

---

## setUp() property mock type propagation

**Feature ID:** `PhpUnitSetUpPropertyTypeProvider`  
**Feature Page:** [setUp() property mock type propagation](https://espend.de/phpstorm/plugin/phpunit#php-unit-set-up-property-type-provider)  

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.

### Code Examples

```php
# 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();
    }
}
```

---

## Prophecy type inference

**Feature ID:** `ProphecyTypeProvider`  
**Feature Page:** [Prophecy type inference](https://espend.de/phpstorm/plugin/phpunit#prophecy-type-provider)  

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.

### Code Examples

```php
# 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());
    }
}
```

---

## Prophecy argument matcher type propagation

**Feature ID:** `ProphecyArgumentTypeProvider`  
**Feature Page:** [Prophecy argument matcher type propagation](https://espend.de/phpstorm/plugin/phpunit#prophecy-argument-type-provider)  

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.

### Code Examples

```php
# 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);
```

---

## Mockery fluent expectation type inference

**Feature ID:** `MockeryFluentTypeProvider`  
**Feature Page:** [Mockery fluent expectation type inference](https://espend.de/phpstorm/plugin/phpunit#mockery-fluent-type-provider)  

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`.

### Code Examples

```php
# Fluent Mockery syntax:
$repository = \Mockery::mock(UserRepository::class);
$repository->allows()->find(42)->andReturns($user);
$repository->expects()->save($user)->once();
```

---

