Skip to content

StrictStubs ​

Rasuvaeff\Understudy\StrictStubs

Class — Package: rasuvaeff/understudy — Source — Version: v1.2.3-1-g736abde

Switches strict stubs — verifyAll(strictStubs: true), where a stub configured but never called fails the test — for one test class or one test method:

php
#[StrictStubs]
final class CheckoutTest
{
    #[StrictStubs(false)]
    public function legacyPath(): void }
}

The engine only declares it; a runner bridge reads it through StrictStubs::resolve() and passes the answer to verifyAll(). One attribute for every bridge, so a test reads the same under each of them.

The method wins over its class, the nearest class in the hierarchy over a more distant one, and any attribute over the bridge's own default.

Constructor ​

php
__construct(
    bool $enabled = true,
)
ParameterTypeDefaultDescription
$enabledbooltruefalse turns strict stubs off where a wider scope turned them on

Methods ​

resolve() ​

php
static resolve(
    class-string $class,
    non-empty-string|null $method = NULL,
    bool $default = false,
): bool

Whether strict stubs apply to a test: the method's attribute, else the nearest class carrying one — the test class first, then its parents — else $default, which is the bridge's own setting.

  • $class — the test class
  • $method — the test method, when known
  • $default — the bridge's own setting

A method that does not exist on the class is not an error: the class level still answers. A bridge may ask before it knows the method.