From 11bfaa08a02e28d08cf1b114a11d778cb5d3b7f4 Mon Sep 17 00:00:00 2001 From: Vladimir Bryzgalov Date: Sat, 16 May 2026 19:37:30 +0500 Subject: [PATCH] test(wpmc S4): restore ACF-missing guard assertions + tighten stub signature Re-add ->never() to both noop tests so Brain Monkey/Mockery actively asserts acf_add_local_field_group is never called when ACF is absent. Order matters: expect() must precede when('function_exists')->alias() so FunctionStub sees the real function_exists and skips the eval() path (function already declared in acf-stubs.php). Also tighten stub signature to match real ACF ($field_group, no type hint, no default). Co-Authored-By: Claude Sonnet 4.6 --- tests/FieldGroupTest.php | 13 ++++++++----- tests/TermMetaTest.php | 9 ++++++--- tests/acf-stubs.php | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/FieldGroupTest.php b/tests/FieldGroupTest.php index 2e742c2..ffa4151 100644 --- a/tests/FieldGroupTest.php +++ b/tests/FieldGroupTest.php @@ -19,17 +19,20 @@ final class FieldGroupTest extends TestCase public function test_do_register_is_noop_when_acf_missing(): void { + // Set up the ->never() expectation BEFORE aliasing function_exists, so that + // FunctionStub::__construct() sees the real function_exists and skips the + // eval() path (the function is already declared in acf-stubs.php). + \Brain\Monkey\Functions\expect('acf_add_local_field_group')->never(); \Brain\Monkey\Functions\when('function_exists')->alias(function ($name) { return $name !== 'acf_add_local_field_group'; }); - // acf_add_local_field_group is NOT stubbed here: if do_register() called it, - // the Patchwork-instrumented stub from acf-stubs.php would run (a silent no-op), - // and we would detect the bug via the assertion below being vacuously unreachable. - // The ->alias() guard above is the behavioural assertion: do_register() must - // return before reaching the acf_add_local_field_group call. FieldGroup::do_register(); + // The real check is the ->never() Mockery expectation above (verified at + // teardown). assertTrue is here only to keep PHPUnit from flagging the + // test as risky under failOnRisky="true" — Mockery assertions don't + // count toward PHPUnit's assertion tally. self::assertTrue(true); } diff --git a/tests/TermMetaTest.php b/tests/TermMetaTest.php index d07b164..d376ef6 100644 --- a/tests/TermMetaTest.php +++ b/tests/TermMetaTest.php @@ -19,15 +19,18 @@ final class TermMetaTest extends TestCase public function test_do_register_is_noop_when_acf_missing(): void { + // Set up the ->never() expectation BEFORE aliasing function_exists, so that + // FunctionStub::__construct() sees the real function_exists and skips the + // eval() path (the function is already declared in acf-stubs.php). + \Brain\Monkey\Functions\expect('acf_add_local_field_group')->never(); \Brain\Monkey\Functions\when('function_exists')->alias(function ($name) { return $name !== 'acf_add_local_field_group'; }); - // acf_add_local_field_group is NOT stubbed here: if do_register() called it, - // the Brain\Monkey eval-stub would throw MissingFunctionExpectations. - // We just verify the method returns without error. TermMeta::do_register(); + // ->never() above is the actual guard assertion; assertTrue keeps + // PHPUnit happy under failOnRisky. self::assertTrue(true); } diff --git a/tests/acf-stubs.php b/tests/acf-stubs.php index d1997d2..c819070 100644 --- a/tests/acf-stubs.php +++ b/tests/acf-stubs.php @@ -14,5 +14,5 @@ declare(strict_types=1); */ if (!function_exists('acf_add_local_field_group')) { - function acf_add_local_field_group(array $args = []): void {} + function acf_add_local_field_group($field_group): void {} }