src/Verification/GeneratorVerifier.php
public function checkThrew($type = null): ?EventCollection
    {
        $cardinality = $this->resetCardinality();

        if ($this->subject instanceof Call) {
            $cardinality->assertSingular();
        }

        $matchingEvents = [];
        $matchCount = 0;
        $isTypeSupported = false;

        if (!$type) {
            $isTypeSupported = true;

            foreach ($this->calls as $call) {
                if (!$call->isGenerator() || !$endEvent = $call->endEvent()) {
                    continue;
                }

                list($exception) = $call->generatorResponse();

                if ($exception) {
                    $matchingEvents[] = $endEvent;
                    ++$matchCount;
                }
            }
        } elseif (is_string($type)) {
            $isTypeSupported = true;

            foreach ($this->calls as $call) {
                if (!$call->isGenerator() || !$endEvent = $call->endEvent()) {
                    continue;
                }

                list($exception) = $call->generatorResponse();

                if ($exception && is_a($exception, $type)) {
                    $matchingEvents[] = $endEvent;
                    ++$matchCount;
                }
            }
        } elseif (is_object($type)) {
            if ($type instanceof InstanceHandle) {
                $type = $type->get();
            }

            if ($type instanceof Throwable) {
                $isTypeSupported = true;
                $type = $this->matcherFactory->equalTo($type, true);
            } elseif ($this->matcherFactory->isMatcher($type)) {
                $isTypeSupported = true;
                $type = $this->matcherFactory->adapt($type);
            }

            if ($isTypeSupported) {
                foreach ($this->calls as $call) {
                    if (
                        !$call->isGenerator() ||
                        !$endEvent = $call->endEvent()
                    ) {
                        continue;
                    }

                    list($exception) = $call->generatorResponse();

                    if ($exception && $type->matches($exception)) {
                        $matchingEvents[] = $endEvent;
                        ++$matchCount;
                    }
                }
            }
        }

        if (!$isTypeSupported) {
            throw new InvalidArgumentException(
                sprintf(
                    'Unable to match exceptions against %s.',
                    $this->assertionRenderer->renderValue($type)
                )
            );
        }

        if ($cardinality->matches($matchCount, $this->callCount)) {
            return $this->assertionRecorder->createSuccess($matchingEvents);
        }

        return null;
    }
public function checkThrew($type = null): ?EventCollection
    {
        $cardinality = $this->resetCardinality();

        if ($this->subject instanceof Call) {
            $cardinality->assertSingular();
        }

        $matchingEvents = [];
        $matchCount = 0;
        $isTypeSupported = false;

        if (!$type) {
            $isTypeSupported = true;

            foreach ($this->calls as $call) {
                if (!$call->isGenerator() || !$endEvent = $call->endEvent()) {
                    continue;
                }

                list($exception) = $call->generatorResponse();

                if ($exception) {
                    $matchingEvents[] = $endEvent;
                    ++$matchCount;
                }
            }
        } elseif (is_string($type)) {
            $isTypeSupported = true;

            foreach ($this->calls as $call) {
                if (!$call->isGenerator() || !$endEvent = $call->endEvent()) {
                    continue;
                }

                list($exception) = $call->generatorResponse();

                if ($exception && is_a($exception, $type)) {
                    $matchingEvents[] = $endEvent;
                    ++$matchCount;
                }
            }
        } elseif (is_object($type)) {
            if ($type instanceof InstanceHandle) {
                $type = $type->get();
            }

            if ($type instanceof Throwable) {
                $isTypeSupported = true;
                $type = $this->matcherFactory->equalTo($type, true);
            } elseif ($this->matcherFactory->isMatcher($type)) {
                $isTypeSupported = true;
                $type = $this->matcherFactory->adapt($type);
            }

            if ($isTypeSupported) {
                foreach ($this->calls as $call) {
                    if (
                        !$call->isGenerator() ||
                        !$endEvent = $call->endEvent()
                    ) {
                        continue;
                    }

                    list($exception) = $call->generatorResponse();

                    if ($exception && $type->matches($exception)) {
                        $matchingEvents[] = $endEvent;
                        ++$matchCount;
                    }
                }
            }
        }

        if (!$isTypeSupported) {
            throw new InvalidArgumentException(
                sprintf(
                    'Unable to match exceptions against %s.',
                    $this->assertionRenderer->renderValue($type)
                )
            );
        }

        if ($cardinality->matches($matchCount, $this->callCount)) {
            return $this->assertionRecorder->createSuccess($matchingEvents);
        }

        return null;
    }
public function checkThrew ( $ type = null ) : ? EventCollection { $ cardinality = $ this -> resetCardinality ( ) ; if ( $ this -> subject instanceof Call ) { $ cardinality -> assertSingular ( ) ; } $ matchingEvents = [ ] ; $ matchCount = 0 ; $ isTypeSupported = false ; if ( ! $ type ) { $ isTypeSupported = true ; foreach ( $ this -> calls as $ call ) { if ( ! $ call -> isGenerator ( ) || ! $ endEvent = $ call -> endEvent ( ) ) { continue ; } list ( $ exception ) = $ call -> generatorResponse ( ) ; if ( $ exception ) { $ matchingEvents [ ] = $ endEvent ; ++ $ matchCount ; } } } elseif ( is_string ( $ type ) ) { $ isTypeSupported = true ; foreach ( $ this -> calls as $ call ) { if ( ! $ call -> isGenerator ( ) || ! $ endEvent = $ call -> endEvent ( ) ) { continue ; } list ( $ exception ) = $ call -> generatorResponse ( ) ; if ( $ exception && is_a ( $ exception , $ type ) ) { $ matchingEvents [ ] = $ endEvent ; ++ $ matchCount ; } } } elseif ( is_object ( $ type ) ) { if ( $ type instanceof InstanceHandle ) { $ type = $ type -> get ( ) ; } if ( $ type instanceof Throwable ) { $ isTypeSupported = true ; $ type = $ this -> matcherFactory -> equalTo ( $ type , true ) ; } elseif ( $ this -> matcherFactory -> isMatcher ( $ type ) ) { $ isTypeSupported = true ; $ type = $ this -> matcherFactory -> adapt ( $ type ) ; } if ( $ isTypeSupported ) { foreach ( $ this -> calls as $ call ) { if ( ! $ call -> isGenerator ( ) || ! $ endEvent = $ call -> endEvent ( ) ) { continue ; } list ( $ exception ) = $ call -> generatorResponse ( ) ; if ( $ exception && $ type -> matches ( $ exception ) ) { $ matchingEvents [ ] = $ endEvent ; ++ $ matchCount ; } } } } if ( ! $ isTypeSupported ) { throw new InvalidArgumentException ( sprintf ( 'Unable to match exceptions against %s.' , $ this -> assertionRenderer -> renderValue ( $ type ) ) ) ; } if ( $ cardinality -> matches ( $ matchCount , $ this -> callCount ) ) { return $ this -> assertionRecorder -> createSuccess ( $ matchingEvents ) ; } return null ; }
Checks if an exception of the supplied type was thrown from a generator.

@param Matcher|Throwable|string|null $type An exception to match, the type of exception, or null for any exception.

@return EventCollection|null     The result.
@throws InvalidArgumentException If the type is invalid.
Checks if an exception of the supplied type was thrown from a generator .