1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 
<?php
namespace Peridot\Reporter;
use Peridot\Core\Suite;
use Peridot\Core\Test;
use Peridot\Core\TestResult;
use Peridot\Runner\Context;
class SpecReporter extends AbstractBaseReporter
{
    
    protected $column = 0;
    
    protected $root;
    
    public function init()
    {
        $this->root = Context::getInstance()->getCurrentSuite();
        $this->eventEmitter->on('runner.start', [$this, 'onRunnerStart']);
        $this->eventEmitter->on('suite.start', [$this, 'onSuiteStart']);
        $this->eventEmitter->on('suite.end', [$this, 'onSuiteEnd']);
        $this->eventEmitter->on('test.passed', [$this, 'onTestPassed']);
        $this->eventEmitter->on('test.failed', [$this, 'onTestFailed']);
        $this->eventEmitter->on('test.pending', [$this, 'onTestPending']);
        $this->eventEmitter->on('runner.end', [$this, 'onRunnerEnd']);
    }
    public function onRunnerStart()
    {
        $this->output->writeln("");
    }
    
    public function onSuiteStart(Suite $suite)
    {
        if ($suite != $this->root) {
            ++$this->column;
            $this->output->writeln(sprintf('%s%s', $this->indent(), $suite->getDescription()));
        }
    }
    public function onSuiteEnd()
    {
        --$this->column;
        if ($this->column == 0) {
            $this->output->writeln("");
        }
    }
    
    public function onTestPassed(Test $test)
    {
        $this->output->writeln(sprintf(
            "  %s%s %s",
            $this->indent(),
            $this->color('success', $this->symbol('check')),
            $this->color('muted', $test->getDescription())
        ));
    }
    
    public function onTestFailed(Test $test)
    {
        $this->output->writeln(sprintf(
            "  %s%s",
            $this->indent(),
            $this->color('error', sprintf("%d) %s", count($this->errors), $test->getDescription()))
        ));
    }
    
    public function onTestPending(Test $test)
    {
        $this->output->writeln(sprintf(
            $this->color('pending', "  %s- %s"),
            $this->indent(),
            $test->getDescription()
        ));
    }
    
    public function onRunnerEnd($time, TestResult $result)
    {
        $this->footer();
        $this->warnings($result);
    }
    
    public function indent()
    {
        return implode('  ', array_fill(0, $this->column + 1, ''));
    }
}