mageekguy\atoum\report\fields\test\event\tap::handleEvent PHP Method

handleEvent() public method

public handleEvent ( $event, mageekguy\atoum\observable $observable )
$observable mageekguy\atoum\observable
    public function handleEvent($event, atoum\observable $observable)
    {
        $eventHandled = parent::handleEvent($event, $observable);
        if ($eventHandled === true) {
            switch ($this->event) {
                case runner::runStart:
                    $this->testPoint = 0;
                    $this->testLine = '';
                    break;
                case test::success:
                    $this->testLine = 'ok ' . ++$this->testPoint . PHP_EOL;
                    $this->testLine .= '# ' . $observable->getClass() . '::' . $observable->getCurrentMethod() . '()' . PHP_EOL;
                    break;
                case test::error:
                    $lastError = $observable->getScore()->getLastErroredMethod();
                    $this->testLine = 'not ok ' . ++$this->testPoint . ' - ' . trim($lastError['class']) . '::' . trim($lastError['method']) . '()' . PHP_EOL;
                    $this->testLine .= $this->renderErrors($observable, trim($lastError['class']), trim($lastError['method']));
                    break;
                case test::fail:
                    $lastFailAssertion = $observable->getScore()->getLastFailAssertion();
                    $this->testLine = 'not ok ' . ++$this->testPoint . ' - ' . trim($lastFailAssertion['class']) . '::' . trim($lastFailAssertion['method']) . '()' . PHP_EOL . '# ' . str_replace(PHP_EOL, PHP_EOL . '# ', trim($lastFailAssertion['fail'])) . PHP_EOL;
                    $this->testLine .= '# ' . $lastFailAssertion['file'] . ':' . $lastFailAssertion['line'] . PHP_EOL;
                    $this->testLine .= $this->renderErrors($observable, trim($lastFailAssertion['class']), trim($lastFailAssertion['method']));
                    break;
                case test::void:
                    $lastVoidMethod = $observable->getScore()->getLastVoidMethod();
                    $this->testLine = 'not ok ' . ++$this->testPoint . ' # TODO ' . trim($lastVoidMethod['class']) . '::' . trim($lastVoidMethod['method']) . '()' . PHP_EOL;
                    $this->testLine .= '# ' . $lastVoidMethod['file'] . PHP_EOL;
                    $this->testLine .= $this->renderErrors($observable, trim($lastVoidMethod['class']), trim($lastVoidMethod['method']));
                    break;
                case test::uncompleted:
                    $lastUncompleteMethod = $observable->getScore()->getLastUncompleteMethod();
                    $lastError = $observable->getScore()->getLastErroredMethod();
                    $this->testLine = 'not ok ' . ++$this->testPoint . ' - ' . trim($lastUncompleteMethod['class']) . '::' . trim($lastUncompleteMethod['method']) . '()' . PHP_EOL;
                    if ($lastError['class'] === $lastUncompleteMethod['class'] && $lastError['method'] === $lastUncompleteMethod['method']) {
                        $this->testLine .= '# ' . $lastError['type'] . ' : ' . str_replace(PHP_EOL, PHP_EOL . '# ', trim($lastError['message'])) . PHP_EOL;
                    } else {
                        $this->testLine .= '# ' . str_replace(PHP_EOL, PHP_EOL . '# ', trim($lastUncompleteMethod['output']) ?: 'uncomplete method') . PHP_EOL;
                    }
                    $this->testLine .= '# ' . $lastUncompleteMethod['file'] . PHP_EOL;
                    break;
                case test::skipped:
                    $lastSkippedMethod = $observable->getScore()->getLastSkippedMethod();
                    $this->testLine = 'ok ' . ++$this->testPoint . ' # SKIP ' . trim($lastSkippedMethod['class']) . '::' . trim($lastSkippedMethod['method']) . '()' . PHP_EOL . '# ' . str_replace(PHP_EOL, PHP_EOL . '# ', trim($lastSkippedMethod['message'])) . PHP_EOL;
                    $this->testLine .= '# ' . $lastSkippedMethod['file'] . ':' . $lastSkippedMethod['line'] . PHP_EOL;
                    break;
                case test::exception:
                    $lastException = $observable->getScore()->getLastException();
                    $this->testLine = 'not ok ' . ++$this->testPoint . ' - ' . trim($lastException['class']) . '::' . trim($lastException['method']) . '()' . PHP_EOL . '# ' . str_replace(PHP_EOL, PHP_EOL . '# ', trim($lastException['value'])) . PHP_EOL;
                    $this->testLine .= '# ' . $lastException['file'] . ':' . $lastException['line'] . PHP_EOL;
                    break;
                case test::runtimeException:
                    $lastRuntimeException = $observable->getScore()->getLastRuntimeException();
                    $this->testLine = 'Bail out!' . ($lastRuntimeException->getMessage() ? ' ' . trim($lastRuntimeException->getMessage()) : '') . PHP_EOL;
                    break;
            }
        }
        return $eventHandled;
    }

Usage Example

Beispiel #1
0
 public function test__toStringWithRuntimeException()
 {
     $this->mockGenerator->shunt('__construct')->if($score = new \mock\atoum\test\score())->and($test = new \mock\mageekguy\atoum\test())->and($this->calling($test)->getScore = $score)->and($this->calling($test)->getClass = $class = uniqid())->and($this->calling($test)->getCurrentMethod = $method = uniqid())->and($this->calling($score)->getLastRuntimeException = new exceptions\runtime())->and($field = new testedClass())->then->castToString($field)->isEmpty()->if($field->handleEvent(atoum\runner::runStart, $test))->then->castToString($field)->isEmpty()->if($field->handleEvent(atoum\test::runtimeException, $test))->then->castToString($field)->isEqualTo('Bail out!' . PHP_EOL)->if($this->calling($score)->getLastRuntimeException = new exceptions\runtime($message = uniqid()))->and($field->handleEvent(atoum\test::runtimeException, $test))->then->castToString($field)->isEqualTo('Bail out! ' . $message . PHP_EOL);
 }