/** * After an it() spec we need to tear down the test case. * * @param Spec $spec */ public function afterSpec(Spec $spec) { $time = 0; if ($spec->isFailed()) { self::$result->addFailure(self::$test, new PHPUnit_Framework_AssertionFailedError($spec->exception), $time); } elseif ($spec->isIncomplete()) { self::$result->addFailure(self::$test, new PHPUnit_Framework_IncompleteTestError($spec->exception), $time); } self::$testCase->tearDown(); self::$result->endTest(self::$test, $time); }
/** * Ran after an individual spec. May be used to display the results of that * particular spec. * * @param Spec $spec The spec after which to run this method */ public function afterSpec(Spec $spec) { if ($spec->getResult() === Spec::FAILED) { $this->failedSpecs[] = $spec; $title = $this->formatter->red($spec); } else { if ($spec->getResult() === Spec::INCOMPLETE) { $this->incompleteSpecs[] = $spec; $title = $this->formatter->cyan($spec); } else { $title = $this->formatter->grey($spec); } } $this->console->writeLn($title); }
/** * Ran after an individual spec. May be used to display the results of that * particular spec. * * @param Spec $spec The spec after which to run this method */ public function afterSpec(Spec $spec) { if ($spec->isFailed()) { $this->failedSpecs[] = $spec; $this->console->writeLn("##teamcity[testFailed name='" . $spec . "' message='" . $this->formatter->red('failed') . "' details='" . str_replace("\n", ' ', $spec->exception) . "']"); } else { if ($spec->isIncomplete()) { $this->incompleteSpecs[] = $spec; } else { if ($spec->isPending()) { $this->pendingSpecs[] = $spec; } } } $this->console->writeLn("##teamcity[testFinished name='" . $spec . "']"); }
/** * Ran after an individual spec. * * @param Spec $spec The spec after which to run this method */ public function afterSpec(Spec $spec) { $this->lineLength += 1; if ($spec->getResult() === Spec::FAILED) { $this->failedSpecs[] = $spec; $failure = $this->formatter->red('F'); $this->console->write($failure); } else { if ($spec->getResult() === Spec::INCOMPLETE) { $this->incompleteSpecs[] = $spec; $incomplete = $this->formatter->cyan('I'); $this->console->write($incomplete); } else { $this->console->write('.'); } } }
/** * Ran after an individual spec. May be used to display the results of that * particular spec. * * @param Spec $spec The spec after which to run this method */ public function afterSpec(Spec $spec) { if ($spec->isFailed()) { $this->failedSpecs[] = $spec; $title = $this->formatter->red($spec); } else { if ($spec->isIncomplete()) { $this->incompleteSpecs[] = $spec; $title = $this->formatter->cyan($spec); } else { if ($spec->isPending()) { $this->pendingSpecs[] = $spec; $title = $this->formatter->yellow($spec); } else { $title = $this->formatter->grey($spec); } } } $this->console->writeLn($title); }
/** * Ran after an individual spec. * * @param Spec $spec The spec after which to run this method */ public function afterSpec(Spec $spec) { $this->lineLength += 1; if ($spec->isFailed()) { $this->failedSpecs[] = $spec; $failure = $this->formatter->red('F'); $this->console->write($failure); } else { if ($spec->isIncomplete()) { $this->incompleteSpecs[] = $spec; $incomplete = $this->formatter->cyan('I'); $this->console->write($incomplete); } else { if ($spec->isPending()) { $this->pendingSpecs[] = $spec; $pending = $this->formatter->yellow('P'); $this->console->write($pending); } else { $this->console->write('.'); } } } }
/** * Ran after an individual spec. May be used to display the results of that * particular spec. * * @param Spec $spec The spec after which to run this method */ public function afterSpec(Spec $spec) { $leftPad = str_repeat(' ', self::TAB_SIZE * $this->depth); if ($spec->isFailed()) { $this->failedSpecs[] = $spec; $title = $this->formatter->red($spec->getTitle()); } else { if ($spec->isIncomplete()) { $this->incompleteSpecs[] = $spec; $title = $this->formatter->cyan($spec->getTitle()); } else { if ($spec->isPending()) { $this->pendingSpecs[] = $spec; $title = $this->formatter->yellow($spec->getTitle()); } else { $title = $this->formatter->grey($spec->getTitle()); } } } $this->console->writeLn($leftPad . $title); }
/** * Ran after an individual spec. May be used to display the results of that * particular spec. * * @param Spec $spec The spec after which to run this method */ public function afterSpec(Spec $spec) { $leftPad = str_repeat(' ', self::TAB_SIZE * $this->depth); if ($spec->getResult() === Spec::FAILED) { $this->failedSpecs[] = $spec; $title = $this->formatter->red($spec->getTitle()); } else { if ($spec->getResult() === Spec::INCOMPLETE) { $this->incompleteSpecs[] = $spec; $title = $this->formatter->cyan($spec->getTitle()); } else { $title = $this->formatter->grey($spec->getTitle()); } } $this->console->writeLn($leftPad . $title); }
$title = $console->formatter->grey($spec->getTitle()); expect($afterSpec)->toPrint($title . PHP_EOL); }); it('prints the spec title in red if it failed', function () use(&$console, &$spec) { $suite = new Suite('test', function () { }); $spec = new Spec('testspec', function () { throw new \Exception('test'); }, $suite); $spec->run(); $afterSpec = function () use($console, $spec) { $reporter = new SpecReporter($console); $reporter->afterSpec($spec); }; $specTitle = $console->formatter->red($spec->getTitle()); expect($afterSpec)->toPrint($specTitle . PHP_EOL); }); it('prints the spec title in cyan if incomplete', function () use(&$console, $spec) { $suite = new Suite('test', function () { }); $spec = new Spec('testspec', null, $suite); $spec->run(); $afterSpec = function () use($console, $spec) { $reporter = new SpecReporter($console); $reporter->afterSpec($spec); }; $specTitle = $console->formatter->cyan($spec->getTitle()); expect($afterSpec)->toPrint($specTitle . PHP_EOL); }); }); });
/** * Constructs a new Spec, adding it to the list of specs in the current * suite and mark it as pending. * * @param string $title A title to be associated with the spec * @param \Closure $closure The closure to invoke when the spec is ran */ public function xit($title, \Closure $closure = null) { $spec = new Spec($title, $closure, $this->current); $spec->setPending(); $this->current->addSpec($spec); }
expect($afterSpec)->toPrint($specTitle . PHP_EOL); }); it('prints the full spec string in cyan if incomplete', function () { $suite = new Suite('test', function () { }); $spec = new Spec('testspec', null, $suite); $spec->run(); $afterSpec = function () use($spec) { $reporter = new ListReporter($this->console); $reporter->afterSpec($spec); }; $console = $this->console; $specTitle = $console->formatter->cyan($this->spec); expect($afterSpec)->toPrint($specTitle . PHP_EOL); }); it('prints the full spec string in yellow if pending', function () { $suite = new Suite('test', function () { }); $spec = new Spec('testspec', null, $suite); $spec->setPending(); $spec->run(); $afterSpec = function () use($spec) { $reporter = new ListReporter($this->console); $reporter->afterSpec($spec); }; $console = $this->console; $specTitle = $console->formatter->yellow($this->spec); expect($afterSpec)->toPrint($specTitle . PHP_EOL); }); }); });
context('getResult', function () use(&$suite) { it('returns PASSED if no exception was thrown', function () use(&$suite) { $closure = function () { }; $spec = new Spec('spec', $closure, $suite); $spec->run(); expect($spec->getResult())->toBe(Spec::PASSED); }); it('returns FAILED if an exception was thrown', function () use(&$suite) { $closure = function () { throw new \Exception('exception'); }; $spec = new Spec('spec', $closure, $suite); $spec->run(); expect($spec->getResult())->toBe(Spec::FAILED); }); it('returns INCOMPLETE if no closure was ran', function () use(&$suite) { $spec = new Spec('spec', null, $suite); $spec->run(); expect($spec->getResult())->toBe(Spec::INCOMPLETE); }); }); context('__toString', function () use(&$suite) { it('returns the suite title followed by the spec title', function () use(&$suite) { $closure = function () { }; $spec = new Spec('SpecTitle', $closure, $suite); expect((string) $spec)->toEqual('TestSuite SpecTitle'); }); }); });
$spec->run(); expect($spec->isFailed())->toBe(false); }); }); describe('isIncomplete', function () { it('returns true when the spec is incomplete', function () { $spec = new Spec('SpecTitle', null, $this->suite); $spec->run(); expect($spec->isIncomplete())->toBe(true); }); it('returns false when the spec is not incomplete', function () { $spec = new Spec('SpecTitle', function () { }, $this->suite); $spec->run(); expect($spec->isIncomplete())->toBe(false); }); }); describe('isPending', function () { it('returns true when the spec is pending', function () { $spec = new Spec('SpecTitle', null, $this->suite); $spec->setPending(); expect($spec->isPending())->toBe(true); }); it('returns false when the spec is not pending', function () { $spec = new Spec('SpecTitle', function () { }, $this->suite); $spec->run(); expect($spec->isPending())->toBe(false); }); }); });