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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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 {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user