---
title: "lint/phpunit/prefer-expect-exception"
pagination: false
---

{/* Generated by scripts/gen-rule-docs.py. Edit mapping.toml, not this file. */}

<RuleId id="lint/phpunit/prefer-expect-exception" />

In the [`lint-strict`](/docs/rules/presets/lint-strict) preset. In Rector's [`rector-phpunit/composer-based`](/docs/rules/sets/rector-phpunit/composer-based) set. Needs the [`phpunit` extension](/docs/configuration/pun-toml#extensions). Unsafe fix: it can change behavior.

## What it does

Replace setExpectedException*() with expectException*().

## Configuration

```toml title="pun.toml"
[lint.rules]
"phpunit/prefer-expect-exception" = "error"
```

To skip it in some files, add an [override](/docs/configuration/pun-toml#lint) or a [`@pun-ignore-file`](/docs/configuration/ignore-comments) comment.

## Options

| Name | Type | Allowed values | Default | Upstream name |
| --- | --- | --- | --- | --- |
| `target` | `enum` | `5.2`, `5.6`, `8.4`, `newest` | `"newest"` | `target` |

## Replaces

- [`php_unit_expectation`](https://cs.symfony.com/doc/rules/php_unit/php_unit_expectation.html) (php-cs-fixer, risky)
- [`DelegateExceptionArguments`](https://getrector.com/rule-detail/delegate-exception-arguments-rector) (rector-phpunit)

[More lint/phpunit rules](/docs/rules/lint/phpunit) · [Edit this page](https://github.com/shipfastlabs/pun/edit/main/crates/pun-config/rules/mapping.toml)
