Record that a successful assertion occurred.

@param EventCollection $events The events.

@return EventCollection The result.
977279
public function createSuccessFromEventCollection(
        EventCollection $events
    ): EventCollection {
        Assert::assertThat(true, Assert::isTrue());

        return $events;
    }
769212
public function processAssertions(ArrayCollection $assertions) : ArrayCollection
    {
        $processed = new ArrayCollection();
        foreach ($assertions->getIterator() as $assertion) {
            $processed->add($this->process($assertion));
        }

        return $processed;
    }
873160
public function expectsEvents($events)
    {
        $events = is_array($events) ? $events : func_get_args();

        $this->withoutEvents();

        $this->beforeApplicationDestroyed(function () use ($events) {
            $fired = $this->getFiredEvents($events);

            $this->assertEmpty(
                $eventsNotFired = array_diff($events, $fired),
                'These expected events were not fired: ['.implode(', ', $eventsNotFired).']'
            );
        });

        return $this;
    }
126067
public function checkInOrder(...$events): ?EventCollection
    {
        if (!count($events)) {
            return null;
        }

        $isMatch = true;
        $matchingEvents = [];
        $earliestEvent = null;

        foreach ($events as $event) {
            if ($event instanceof Event) {
                if (
                    !$earliestEvent ||
                    $event->sequenceNumber() > $earliestEvent->sequenceNumber()
                ) {
                    $matchingEvents[] = $earliestEvent = $event;

                    continue;
                }
            } elseif ($event instanceof EventCollection) {
                if (!$event->hasEvents()) {
                    throw new InvalidArgumentException(
                        'Cannot verify event order with empty results.'
                    );
                }

                foreach ($event->allEvents() as $subEvent) {
                    if (
                        !$earliestEvent ||
                        (
                            $subEvent->sequenceNumber() >
                            $earliestEvent->sequenceNumber()
                        )
                    ) {
                        $matchingEvents[] = $earliestEvent = $subEvent;

                        continue 2;
                    }
                }
            } else {
                throw new InvalidArgumentException(
                    sprintf(
                        'Cannot verify event order with supplied value %s.',
                        $this->assertionRenderer->renderValue($event)
                    )
                );
            }

            $isMatch = false;

            break;
        }

        if ($isMatch) {
            return $this->assertionRecorder->createSuccess($matchingEvents);
        }

        return null;
    }
142899
private function eventsShouldExistInStore(DomainEvent ...$events) {
        $expected = array_map(function (DomainEvent $event) {
            return $this->serializer->serialize($event);
        }, $events);

        $existing = $this->eventStore->getEvents()->map(function(DomainEvent $event) {
            return $this->serializer->serialize($event);
        })->toArray();

        $notFound = array_filter($expected, function($expectedEvent) use ($existing) {
            return ! in_array($expectedEvent, $existing);
        });

        if (empty($notFound)) return;

        throw new FailureException($this->missingEventExceptionMessage($notFound));
    }
1024874
public function recordThat(DomainEvent $event)
    {
        $this->bumpVersion();

        if (is_null($this->uncommittedEvents)) {
            $this->uncommittedEvents = new UncommittedEvents($this->getIdentity());
        }

        $this->uncommittedEvents->append($event);
        $this->when($event);

        return $this;
    }
486198
public function checkReturned($value = null): ?EventCollection
    {
        $cardinality = $this->resetCardinality();

        $calls = $this->spy->allCalls();
        $matchingEvents = [];
        $totalCount = count($calls);
        $matchCount = 0;

        if (0 === func_num_args()) {
            foreach ($calls as $call) {
                if (!$responseEvent = $call->responseEvent()) {
                    continue;
                }

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

                if (!$exception) {
                    $matchingEvents[] = $responseEvent;
                    ++$matchCount;
                }
            }
        } else {
            $value = $this->matcherFactory->adapt($value);

            foreach ($calls as $call) {
                if (!$responseEvent = $call->responseEvent()) {
                    continue;
                }

                list($exception, $returnValue) = $call->response();

                if (!$exception && $value->matches($returnValue)) {
                    $matchingEvents[] = $responseEvent;
                    ++$matchCount;
                }
            }
        }

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

        return null;
    }
1004740
public function checkReturned($value = null): ?EventCollection
    {
        $cardinality = $this->resetCardinality();

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

        $matchingEvents = [];
        $matchCount = 0;

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

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

                if (!$exception) {
                    $matchingEvents[] = $endEvent;
                    ++$matchCount;
                }
            }
        } else {
            $value = $this->matcherFactory->adapt($value);

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

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

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

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

        return null;
    }
675281
public function extractRecordedEvents()
    {
        $eventCollection = $this->eventCollection();
        $eventStream = $eventCollection->stream();
        $eventCollection->commit();
        $this->committedVersion = $eventCollection->committedSequence();

        return $eventStream;
    }
588297
protected static function eventsToBeRecorded(): Collection
    {
        if (isset(static::$recordEvents)) {
            return collect(static::$recordEvents);
        }

        $events = collect([
            'created',
            'updated',
            'deleted',
        ]);

        if (collect(class_uses_recursive(static::class))->contains(SoftDeletes::class)) {
            $events->push('restored');
        }

        return $events;
    }
1154853
public function hasMany(array $events)
    {
        foreach ($events as $event) {
            if (!$this->has($event)) {
                return false;
            }
        }

        return true;
    }
403415
public function checkCompleted(): ?EventCollection
    {
        $cardinality = $this->resetCardinality()->assertSingular();
        $endEvent = $this->call->endEvent();

        list($matchCount, $matchingEvents) =
            $this->matchIf($endEvent, $endEvent);

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

        return null;
    }
738248
public function withErrors(array $errors = []): CollectionElement
    {
        $this->allErrors = $errors;

        array_walk(
            $this->elements,
            function (ElementInterface $element) use ($errors) {
                $name = $element->name();
                if (isset($errors[$name]) && $element instanceof ErrorAwareInterface) {
                    $element->withErrors($errors);
                    unset($errors[$name]);
                }
            }
        );

        // assign errors without matches to the collection itself.
        $this->errors = $errors;

        return $this;
    }
1246630
public function createSuccessFromEventCollection(
        EventCollection $events
    ): EventCollection {
        $suiteClass = $this->suiteClass;
        $suiteClass::current()->assert($this->successConfig);

        return $events;
    }
302273
public static function checkAnyOrder(...$events): ?EventCollection
    {
        $container = self::$globals::$container;

        return $container->eventOrderVerifier->checkAnyOrder(...$events);
    }
535309
public function detach(\Zend_EventManager_EventCollection $events)
    {
        foreach($this->listeners as $index => $listener) {
            if($events->detach($listener)) {
                unset($this->listeners[$index]);
            }
        }
    }
739844
public function onlyExpectsEvents($events)
    {
        $events = is_array($events) ? $events : func_get_args();

        $this->withoutEvents();

        $this->beforeApplicationDestroyed(function () use ($events) {
            $fired = $this->getFiredEvents($events);

            if ($eventsNotFired = array_diff($events, $fired)) {
                throw new Exception(
                    'These expected events were not fired: ['.implode(', ', $eventsNotFired).']'
                );
            }

            if ($eventsFired = array_diff(array_map('get_class', $this->firedEvents), $events)) {
                throw new Exception(
                    'These unexpected events were fired: ['.implode(', ', $eventsFired).']'
                );
            }
        });

        return $this;
    }