Kahlan\Reporter\Json::end PHP Method

end() public method

Callback called at the end of specs processing.
public end ( object $summary )
$summary object The execution summary instance.
    public function end($summary)
    {
        $toString = function ($instance) {
            return 'an instance of `' . get_class($instance) . '`';
        };
        foreach ($summary->logs() as $log) {
            if ($log->passed()) {
                continue;
            }
            switch ($log->type()) {
                case 'failed':
                    foreach ($log->children() as $log) {
                        if ($log->passed()) {
                            continue;
                        }
                        $data = [];
                        foreach ($log->data() as $key => $value) {
                            $data[$key] = Text::toString($value, ['object' => ['method' => $toString]]);
                        }
                        $this->_json['errors'][] = ['spec' => trim(implode(' ', $log->messages())), 'suite' => $log->file(), 'data' => $data];
                    }
                    break;
                case 'errored':
                    $exception = $log->exception();
                    $this->_json['errors'][] = ['spec' => trim(implode(' ', $log->messages())), 'suite' => $log->file(), 'exception' => '`' . get_class($exception) . '` Code(' . $exception->getCode() . ')', 'trace' => $exception->getMessage()];
                    break;
            }
        }
        $this->_json['summary'] = ['total' => $summary->total(), 'passed' => $summary->passed(), 'pending' => $summary->pending(), 'skipped' => $summary->skipped(), 'excluded' => $summary->excluded(), 'failed' => $summary->failed(), 'errored' => $summary->errored()];
        $this->write(json_encode($this->_json));
    }