# Writing tests Tests use [Brain\Monkey](https://brain-wp.github.io/BrainMonkey/) to stub WordPress functions without a full WP installation, and Mockery to mock `$wpdb` and other dependencies. All test classes extend `tests/Unit/TestCase.php`, which handles `Monkey\setUp()` / `Monkey\tearDown()` and stubs all WP translation/escape functions automatically. **Brain\Monkey API notes:** - `Functions\when('fn')->alias(fn() => ...)` — stub with a closure (NOT `returnUsing()`) - `Functions\when('fn')->justReturn($val)` — stub returning a fixed value - `Functions\expect('fn')->once()->with(...)` — assert call count and arguments - Use `Functions\when()` (not `Functions\expect()`) when you need argument-routing (e.g. `get_role` returning different values per argument) to avoid chaining ambiguity - Mockery matchers (e.g. `\Mockery::type()`) inside plain PHP arrays do not work with `with()` — use `\Mockery::on(fn($arr) => ...)` or `\Mockery::any()` instead - When mocking `$wpdb`, set `$mock->prefix = 'wp_'` explicitly — it is a public property, not a method