# PHPUnit Enhancement Plugin Intentions

**Intentions** run tests, generate mock method stubs, create constructor mocks, and insert expected exception assertions directly from the editor.

---

## Run PHPUnit test from class or method scope

**Feature ID:** `TestRunIntentionAction`  
**Feature Page:** [Run PHPUnit test from class or method scope](https://espend.de/phpstorm/plugin/phpunit#test-run-intention-action)  

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.

### Code Examples

```php
# Run from a test method or class:
class InvoiceServiceTest extends \PHPUnit\Framework\TestCase
{
    public function testCharge(): void
    {
        self::assertTrue(true);
    }
}
```

---

## Add PHPUnit mock method stub

**Feature ID:** `AddMockMethodIntention`  
**Feature Page:** [Add PHPUnit mock method stub](https://espend.de/phpstorm/plugin/phpunit#add-mock-method-intention)  

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

### Code Examples

```php
# Before:
$gateway = $this->createMock(PaymentGateway::class);
```

```php
# After selecting capture:
$gateway = $this->createMock(PaymentGateway::class);
$gateway->method('capture')->willReturn();
```

---

## Generate constructor mocks

**Feature ID:** `ConstructorMockIntention`  
**Feature Page:** [Generate constructor mocks](https://espend.de/phpstorm/plugin/phpunit#constructor-mock-intention)  

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.

### Code Examples

```php
# Before:
$service = new CheckoutService();
```

```php
# After generating constructor mocks:
$service = new CheckoutService(
    $this->createMock(PaymentGateway::class),
    $this->createMock(LoggerInterface::class)
);
```

---

## Insert expected exception assertions

**Feature ID:** `MethodExceptionIntentionAction`  
**Feature Page:** [Insert expected exception assertions](https://espend.de/phpstorm/plugin/phpunit#method-exception-intention-action)  

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.

### Code Examples

```php
# Before:
public function testFailure(): void
{
    $gateway = new PaymentGateway();
    $gateway->charge();
}
```

```php
# After inserting the expected exception:
public function testFailure(): void
{
    $this->expectException(PaymentFailedException::class);

    $gateway = new PaymentGateway();
    $gateway->charge();
}
```

---

