# Diagnostics

This page lists every analyzer diagnostic that `friendsofmago/mago-mockery` emits or filters.

## Extension diagnostics

| Code | Level | Default | Summary |
| --- | --- | --- | --- |
| [`mockery/unknown-mocked-method`](<#mockeryunknown-mocked-method>) | error | Off | A literal or higher-order method name in an expectation or verification call does not exist on the mocked class. |

---

## `mockery/unknown-mocked-method`

| Property | Value |
| --- | --- |
| Level | `error` |
| Default | Off. Set `MAGO_MOCKERY_STRICT_METHODS` to `1`, `true`, `yes`, or `on` in `[extension-hosts.mockery] environment`, or pass `strictMockedMethods: true` to `MockeryExtension::plugins()`. |
| Source | `StrictMockedMethodHook::ISSUE_CODE` (`unknown-mocked-method`), registered under the `mockery` plugin. |

### Reported

- `shouldReceive()` or `shouldNotReceive()` on `Mockery\Mock`, `Mockery\MockInterface`, `Mockery\LegacyMockInterface`, or `Mockery\CompositeExpectation`, given a missing literal string or a finite union of literal strings.
- `allows()`, `expects()`, `shouldHaveReceived()`, or `shouldNotHaveReceived()` on `Mockery\Mock`, `Mockery\MockInterface`, or `Mockery\LegacyMockInterface`, given a missing literal string or finite union as the first argument.
- Quick definition map keys passed to expectation factories, such as `$mock->allows(['missing' => 1])` or `$mock->shouldReceive(['missing' => 1])`.
- The root method name of a Demeter chain string, such as `'missing->name'`, when `missing` does not exist on the mocked type.
- A non-magic method name called on `Mockery\HigherOrderMessage` or `Mockery\ExpectsHigherOrderMessage`, such as `$mock->shouldReceive()->missing()`.

### Not reported

- Targets that declare or inherit `__call()` or `__callStatic()`.
- Targets that declare a `@mixin` tag or have an incomplete class hierarchy.
- Methods documented with `@method` on the target type, whether instance or static.
- Mocks whose intersection includes `stdClass`.
- Anonymous mocks from `Mockery::mock()`, or receivers that do not narrow to a single named-object intersection.
- Dynamic method names typed as `string`, `mixed`, or a union that includes a non-literal type.
- Magic method names that start with `__` in higher-order calls.
- Methods allowed by a dominating `shouldAllowMockingMethod()` call on the same local variable or straight-line `$this->property`.

### Example

```
<?php

declare(strict_types=1);

interface Greeter
{
    public function greet(string $name): string;
}

// Reported (with MAGO_MOCKERY_STRICT_METHODS=1):
$mock = Mockery::mock(Greeter::class);
$mock->shouldReceive('doesNotExist');
$mock->shouldReceive()->doesNotExist();

// Fine:
$mock->shouldReceive('greet')->andReturn('hello');
$mock->shouldReceive()->greet('Ada')->andReturn('hello');
```

### Suppression

Suppress per call:

```
// @mago-ignore analysis:mockery/unknown-mocked-method
$mock->shouldReceive('dynamicName');
```

Suppress across a directory or project in `mago.toml`:

```
[analyzer]
ignore = [
    { code = "mockery/unknown-mocked-method", in = "tests/Legacy/" },
]
```

## Filtered Mago diagnostics

| Code | Filter class | Behavior |
| --- | --- | --- |
| `direct-trait-constant-access` | `TraitMockConstantIssueFilter` | Removes the issue when flow analysis proves that the receiver is a Mockery mock on every reachable path. Keeps the issue on non-mock trait constant reads. |
