Skip to content

InvalidSpecificationArgument ​

Rasuvaeff\Understudy\Exception\InvalidSpecificationArgument

Class — Package: rasuvaeff/understudy — Source — Version: v1.1.0-1-g6ed023f

Extends: InvalidArgumentException

Implements: Stringable, Throwable, Exception\UnderstudyError

A VALUE inside a specification that no run could act on: a maximum call count below its minimum, a negative count, returns() with nothing to return, a matcher range whose maximum sits below its minimum, a pattern PCRE cannot compile, Arg::instanceOf() naming a type that is not loadable.

The line between this class and Exception\InvalidCallSpecification: that one is about the SHAPE of a specification — what is called, where, how many times — and this one about a number, a pattern or a name given to it. It extends \InvalidArgumentException because that is the SPL type these paths have always been, and a user's catch (\InvalidArgumentException $e) around them keeps working; it implements UnderstudyError because that interface is implemented by every exception this library throws.

Methods ​

unknownArgument() ​

php
static unknownArgument(
    non-empty-string $method,
    int|string $parameter,
    array<int,non-empty-string> $known,
): self

Invocation::arg() asked for a parameter the method does not declare.

  • $method — the method the call was made on
  • $parameter — the position or name that was asked for
  • $known — the contract's own parameter names, in order

maximumBelowMinimum() ​

php
static maximumBelowMinimum(int $minimum, int $maximum): self

A cardinality whose upper bound is below its lower one: no number of calls satisfies both.

  • $minimum — the lower bound as written
  • $maximum — the upper bound as written, below the lower one

negativeCount() ​

php
static negativeCount(int $count): self

A call count below zero, which no run can produce.

  • $count — the count as written

noReturnValues() ​

php
static noReturnValues(): self

returns() with no arguments: there is nothing for the double to return, and the chain would answer the next call with nothing at all.

returnValueOfWrongType() ​

php
static returnValueOfWrongType(
    non-empty-string $label,
    non-empty-string $method,
    non-empty-string $declared,
    non-empty-string $given,
): self

A returns() value the declared return type cannot hold. Refused where it was written: left to the engine it surfaced as a TypeError naming the generated class, from wherever in the code under test the call was.

  • $label — the double, as a refusal names it
  • $method — the method whose return type refused the value
  • $declared — the return type as the contract declares it
  • $given — the value's type, as get_debug_type() reports it

unknownType() ​

php
static unknownType(string $type): self

Arg::instanceOf() naming a class or interface that is not loadable — a matcher nothing can ever satisfy, which would otherwise report itself only as an expectation that was never met.

  • $type — the name as written

invertedBounds() ​

php
static invertedBounds(
    non-empty-string $matcher,
    int|float $minimum,
    int|float $maximum,
): self

A range matcher whose maximum sits below its minimum, so it describes an empty range and could never match.

  • $matcher — the factory that was called, without Arg::
  • $minimum — the lower bound as it was given
  • $maximum — the upper bound as it was given

invalidPattern() ​

php
static invalidPattern(non-empty-string $pattern, non-empty-string|null $reason): self

A pattern handed to Arg::string() that PCRE cannot compile.

  • $pattern — the pattern as it was written
  • $reason — what PCRE said, when it said anything