src/Client.php
public function on(RequestMatcher $requestMatcher, $result)
    {
        $callable = null;

        switch (true) {
            case is_callable($result):
                $callable = $result;

                break;
            case $result instanceof ResponseInterface:
                $callable = function () use ($result) {
                    return $result;
                };

                break;
            case $result instanceof \Exception:
                $callable = function () use ($result) {
                    throw $result;
                };

                break;
            default:
                throw new \InvalidArgumentException('Result must be either a response, an exception, or a callable');
        }
        $this->conditionalResults[] = [
            'matcher' => $requestMatcher,
            'callable' => $callable,
        ];
    }
public function on(RequestMatcher $requestMatcher, $result)
    {
        $callable = null;

        switch (true) {
            case is_callable($result):
                $callable = $result;

                break;
            case $result instanceof ResponseInterface:
                $callable = function () use ($result) {
                    return $result;
                };

                break;
            case $result instanceof \Exception:
                $callable = function () use ($result) {
                    throw $result;
                };

                break;
            default:
                throw new \InvalidArgumentException('Result must be either a response, an exception, or a callable');
        }
        $this->conditionalResults[] = [
            'matcher' => $requestMatcher,
            'callable' => $callable,
        ];
    }
public function on ( RequestMatcher $ requestMatcher , $ result ) { $ callable = null ; switch ( true ) { case is_callable ( $ result ) : $ callable = $ result ; break ; case $ result instanceof ResponseInterface : $ callable = function ( ) use ( $ result ) { return $ result ; } ; break ; case $ result instanceof \ Exception : $ callable = function ( ) use ( $ result ) { throw $ result ; } ; break ; default : throw new \ InvalidArgumentException ( 'Result must be either a response, an exception, or a callable' ) ; } $ this -> conditionalResults [ ] = [ 'matcher' => $ requestMatcher , 'callable' => $ callable , ] ; }
Adds an exception to be thrown or response to be returned if the request
matcher matches.

For more complex logic, pass a callable as $result. The method is given
the request and MUST either return a ResponseInterface or throw an
exception that implements the PSR-18 / HTTPlug exception interface.

@param ResponseInterface|Exception|ClientExceptionInterface|callable $result
Adds an exception to be thrown or response to be returned if the request matcher matches .