assert($exception->getTraceString() === 'this is a trace'); }); it('uses ->getTraceAsString if nothing manually set', function () { $e = null; try { throw new Exception('message'); } catch (Exception $ex) { $e = $ex; } assert($e->getTraceString() === $e->getTraceAsString()); }); it('prefers the manually set trace string', function () { $e = null; try { throw new Exception('message'); } catch (Exception $ex) { $e = $ex; } $e->setTraceString('trace'); assert($e->getTraceString() === 'trace'); }); }); describe('type accessors', function () { it('can access a string type', function () { $e = new Exception('message'); $e->setType('RuntimeException'); $type = $e->getType(); assert($type === 'RuntimeException'); }); }); });
}); it('should output time', function () { $time = PHP_Timer::secondsToTimeString($this->reporter->getTime()); assert(strstr($this->contents, $time) !== false, 'should contain time text'); }); it('should output failure text', function () { assert(strstr($this->contents, '1 failing') !== false, 'should contain failure text'); }); it('should output pending count', function () { assert(strstr($this->contents, '1 pending') !== false, 'should contain pending text'); }); it('should display exception stacks and messages', function () { $expectedExceptionMessage = " ooops" . PHP_EOL . " nextline"; assert(strstr($this->contents, $expectedExceptionMessage) !== false, "should include exception message"); $trace = preg_replace('/^#/m', " #", $this->exception->getTraceAsString()); assert(strstr($this->contents, $trace) !== false, "should include exception stack"); }); it('should honor peridot exception traces', function () { $output = new BufferedOutput(); $emitter = new EventEmitter(); $reporter = new SpecReporter($output, $emitter, Context::getInstance()); $exception = new PeridotException('message'); $exception->setTraceString('trace!!'); $emitter->emit('test.failed', new Test('failing test', function () { }), $exception); $reporter->footer(); $contents = $output->fetch(); assert(strstr($contents, 'trace!!') !== false, 'should contain manually set trace'); }); }); });