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 <noreply@anthropic.com>
This commit is contained in:
Vladimir Bryzgalov
2026-05-16 19:37:30 +05:00
parent 494061e39f
commit 11bfaa08a0
3 changed files with 15 additions and 9 deletions
+8 -5
View File
@@ -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);
}