function it_should_creates_result_event(ExampleEvent $exampleEvent, SpecificationNode $specificationNode, CodeCoverageSession $coverageSession) { $exampleEvent->getResult()->shouldBeCalled()->willReturn(ExampleEvent::PASSED); $specificationNode->getTitle()->shouldBeCalled()->willReturn('SomeSpesification'); $coverageSession->stop()->shouldBeCalled(); $this->afterExample($exampleEvent); $this->getResults()->shouldHaveCount(1); }
function it_orders_an_array_of_specification_nodes(SpecificationNode $a, SpecificationNode $b, SpecificationNode $c) { $a->getTitle()->willReturn('foo1'); $b->getTitle()->willReturn('foo2'); $c->getTitle()->willReturn('foo3'); $nodes = [$a, $b, $c]; $expected = [$c, $b, $a]; $this->filter($nodes)->shouldReturn($expected); }
/** * @param string $locator * @param integer|null $line * * @return Suite */ public function load($locator, $line = null) { $suite = new Suite(); $specifications = []; foreach ($this->manager->locateResources($locator) as $resource) { if (!class_exists($resource->getSpecClassname()) && is_file($resource->getSpecFilename())) { require_once $resource->getSpecFilename(); } if (!class_exists($resource->getSpecClassname())) { continue; } $reflection = new ReflectionClass($resource->getSpecClassname()); if ($reflection->isAbstract()) { continue; } if (!$reflection->implementsInterface('PhpSpec\\SpecificationInterface')) { continue; } $spec = new Node\SpecificationNode($resource->getSrcClassname(), $reflection, $resource); $examples = []; foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { if (!preg_match('/^(it|its)[^a-zA-Z]/', $method->getName())) { continue; } if (null !== $line && !$this->lineIsInsideMethod($line, $method)) { continue; } $example = new Node\ExampleNode(str_replace('_', ' ', $method->getName()), $method); if ($this->methodAnalyser->reflectionMethodIsEmpty($method)) { $example->markAsPending(); } $examples[] = $example; } foreach ($this->filters as $filter) { if ($filter instanceof ExampleFilter) { $filter->setSpecificationTitle($spec->getTitle()); $examples = $filter->filter($examples); } } foreach ($examples as $example) { $spec->addExample($example); } unset($examples); $specifications[] = $spec; } foreach ($this->filters as $filter) { if ($filter instanceof SpecFilter) { $specifications = $filter->filter($specifications); } } foreach ($specifications as $spec) { $suite->addSpecification($spec); } unset($specifications); return $suite; }
function it_filters_specification_nodes_to_include_only_given_specs(SpecificationNode $a, SpecificationNode $b, SpecificationNode $c) { $a->getTitle()->willReturn('foo1'); $b->getTitle()->willReturn('foo2'); $c->getTitle()->willReturn('foo3'); $nodes = [$a, $b, $c]; $expected = [$b]; $this->setSpecs(['foo2']); $this->filter($nodes)->shouldReturn($expected); }
/** * @return string */ public function getTitle() { return $this->specification->getTitle(); }
function it_formats_specification_finish(IO $io, SpecificationNode $node) { $node->getTitle()->willReturn('Specification'); $io->write("##teamcity[testSuiteFinished name='Specification']\n")->shouldBeCalled(); $this->afterSpecification($this->specificationEvent($node)); }
private function addResult($result, SpecificationNode $spec, $title = null) { $map = array(ResultEvent::SUCCEED => 'Succeed: %title%', ResultEvent::FAILED => 'Failed: %title%', ResultEvent::BROKEN => 'Broken: %title%', ResultEvent::ERROR => 'Error: %title%'); $r = $spec->getClassReflection(); $arguments = array('file' => $r->getFileName()); $key = md5($r->getFileName() . $title); $format = $map[$result]; $title = $title == null ? $spec->getTitle() : $spec->getTitle() . '::' . $title; $message = strtr($format, array('%title%' => '<highlight>' . $title . '</highlight>')); $this->results[$key] = ResultEvent::create($result, $message, $arguments); }