Files
unsupervised-scheduler/memory/feedback_brainmonkey.md
James Griffin ed49924f95
All checks were successful
CI / Coding Standards (push) Successful in 44s
CI / PHPStan (push) Successful in 49s
CI / Tests (PHP 8.1) (push) Successful in 54s
CI / Tests (PHP 8.2) (push) Successful in 51s
CI / Tests (PHP 8.3) (push) Successful in 39s
CI / No Debug Code (push) Successful in 3s
Fix all PHPCS coding standards violations
- Add phpcs.xml.dist: excludes PSR-4 file naming, camelCase naming,
  short array syntax, and redundant per-method/property docblocks
- Fix wp_unslash() on all $_POST reads (LoginPage, AvailabilityController)
- Add phpcs:ignore for password field (must not be sanitized)
- Fix Yoda conditions throughout (AvailabilityRepository, AvailabilityEndpoint,
  BookingEndpoint, AvailabilityController)
- Fix inline comments to end with full stops (AdminMenu)
- Replace short ternary ?: with explicit full ternary (BookingEndpoint)
- Rename $namespace param to $route_namespace (reserved keyword warning)
- Add short descriptions to doc blocks that had tag-only blocks
- Add nonce suppression comment in handleFormAction (nonce verified by caller)
- Update composer.json and CI to use phpcs.xml.dist

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 16:20:49 -03:00

1.9 KiB

name, description, type
name description type
Brain\Monkey testing patterns Specific Brain\Monkey 2.x API quirks that caused test failures — use these patterns to avoid repeating mistakes feedback

Use Functions\when('fn')->alias(fn() => ...) for closure-based stubs. NOT returnUsing() (doesn't exist).

Why: Discovered during initial test scaffold — returnUsing() throws "Call to undefined method".

How to apply: Any time a WP function needs to return different values based on arguments (e.g. get_role returning different values per role), use Functions\when()->alias().


Use Functions\when() instead of Functions\expect() when routing by argument.

Why: Chaining two Functions\expect('get_role')->with(A) / Functions\expect('get_role')->with(B) caused the second expectation to silently override the first rather than adding an alternative route, leading to unexpected "0 calls" failures.

How to apply: When a function needs to return different values for different args, use Functions\when()->alias(fn($arg) => match($arg) { ... }). Use Functions\expect() only when asserting call count/args.


Mockery matchers don't work inside plain PHP arrays in with().

Why: ->with('init', [\Mockery::type(Foo::class), 'method']) never matched because Mockery can't evaluate matchers nested in arrays this way.

How to apply: Use \Mockery::any() or \Mockery::on(fn($arr) => ...) for the entire array argument instead.


TestCase::setUp() must call Monkey\Functions\stubTranslationFunctions() and Monkey\Functions\stubEscapeFunctions().

Why: WP i18n functions (__, _e, etc.) are not auto-stubbed — they don't exist in the test environment. Without explicit stubs, PHP throws "Call to undefined function" as soon as any WP code path hits __().

How to apply: Already done in tests/Unit/TestCase.php. Don't remove these calls.