Skip to content

v1.1.0

Choose a tag to compare

@github-actions github-actions released this 13 Oct 19:08
· 11 commits to master since this release
a15b09c
  • Changed. A forwarding double of a class now runs the real bodies on
    itself instead of proxying them to the instance: the state that instance held
    is copied onto the double when forwarding() is called, and an unmatched
    call executes the parent implementation with $this still the double. A
    self-call inside real code therefore re-enters the double — it meets stubs,
    an armed protocol and the call log — which is what makePartial() ports
    needed and what the standing limitation ("understudy proxies an object; it
    does not instrument one") described. An interface double has no bodies to
    reach and proxies exactly as before. Five consequences in a suite that
    already forwards class doubles: a self-call now counts toward
    expect(...)->times(n) and can fill a step of an armed protocol;
    callOriginal() on such a double runs on the double rather than on the
    instance, over the state the double holds; static::class inside a real
    body names the generated class; a real body that hands out a new static
    is refused with OriginalReturnTypeViolation (an object no context knows,
    where a clone $this is adopted while the body runs and comes back
    working); and the instance stops receiving the calls, so a test asserting
    on it afterwards sees the state as of the moment forwarding() ran. That
    copy is shallow, which is the same reach the instance had before: an
    object-valued property is the same object on both, so writes through it
    still land on the donor's collaborators, and a closure the constructor
    bound to the donor still runs with $this on the donor. Inline needs the instance to be exactly
    the doubled class — a subclass instance keeps the proxy form, so its own
    overrides answer — and an inline double cannot be re-pointed at a second
    instance, because a readonly property cannot be copied onto it twice
    (ForwardingTargetMismatch). Adopting a clone asks for a copy of the double
    whose body is running, holding its state: one generated class serves every
    double of a type, so a body that clones another double it was handed — and a
    clone $double the test writes in its own answers() closure, which a real
    body can reach — gets a fresh double of that class, the documented rule for
    clone $double, rather than real bodies over a state nothing copied. Two
    doubles of one class in the same state are indistinguishable, because
    __clone() is handed no reference to its source: a copy of one of those is
    adopted and answers for real, over the state it already holds. No name,
    signature or readonly field of the public API changed. (#150)
  • Changed. Dispatch between overlapping specifications now runs in two
    tiers: one that pins at least one argument to something narrower than
    "anything" — a literal, any matcher except Arg::any(), or a tail pinned
    empty by Arg::none() — is tried before one that says nothing about any
    argument (Arg::any() in every position, an unspelled optional parameter,
    Arg::rest()/remaining()), whichever order the two were declared in.
    Within a tier, most-recently-registered still wins, and two specifics are
    never compared for narrowness. The trap this removes (#136): a catch-all
    registered after a specific stub used to take every call, leaving the
    specific one unreachable and undiagnosed — that ordering mistake can no
    longer be written. This is a behaviour change to the documented layering
    semantics: a suite that relied on a catch-all overriding a narrower stub
    declared earlier now sees the narrow one answer. No name, signature or
    readonly field of the public API changed. (#152)
  • Added. where(): a predicate over the whole argument list, narrowing a
    specification by a constraint no positional matcher can express —
    when(fn () => $ledger->transfer(Arg::any(), Arg::any()))->where(fn ($from, $to) => $from <= $to)->returns(true). The closure receives the arguments
    positionally and is asked only after every position matched; a call it
    refuses falls through to broader expectations. expect() takes one through
    the same verb, verify() through its where: parameter. One guard per
    expectation (a second is refused), description: names it in failure
    messages, and a guard that refused a positionally-matching call is marked
    as the refusing part. The Mockery migration table gains its
    withArgs(closure) row. (#151)
  • Added. Understudy::verifyAll() returns int<0, max> — how many checks
    it verified — instead of void, so runner adapters count real assertions
    instead of a flat one per test. One check is: an expectation carrying a
    claim (expect(), or times() on a stub); a plain stub under
    strictStubs, where its use is what is checked; an ordering constraint
    over expectations that declared one; an armed protocol, whose completeness
    is checked here. Checks verify() made earlier answered at their own call
    sites and are not recounted. Source-compatible for every existing caller:
    the method answered nothing before, and Understudy is final. The
    compatibility policy now says a return type may be widened in a minor
    release where no caller can observe the change. (#153)