/** * @param string $locator * @param integer|null $line * * @return Suite */ public function load($locator, $line = null) { $suite = new Suite(); 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); 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(); } $spec->addExample($example); } $suite->addSpecification($spec); } return $suite; }
public function afterExample(ExampleEvent $exampleEvent) { $exception = $exampleEvent->getException(); if (!$exception instanceof NotEqualException) { return; } if ($exception->getActual() !== null) { return; } if (is_object($exception->getExpected()) || is_array($exception->getExpected()) || is_resource($exception->getExpected())) { return; } if (!$this->lastMethodCallEvent) { return; } $class = get_class($this->lastMethodCallEvent->getSubject()); $method = $this->lastMethodCallEvent->getMethod(); if (!$this->methodAnalyser->methodIsEmpty($class, $method)) { return; } $key = $class . '::' . $method; if (!array_key_exists($key, $this->nullMethods)) { $this->nullMethods[$key] = array('class' => $class, 'method' => $method, 'expected' => array()); } $this->nullMethods[$key]['expected'][] = $exception->getExpected(); }
function it_does_not_prompt_when_method_is_not_empty(MethodCallEvent $methodCallEvent, ExampleEvent $exampleEvent, IO $io, MethodAnalyser $methodAnalyser, SuiteEvent $event) { $methodCallEvent->getMethod()->willReturn('myMethod'); $methodCallEvent->getSubject()->willReturn(new \DateTime()); $methodAnalyser->methodIsEmpty('DateTime', 'myMethod')->willReturn(false); $this->afterMethodCall($methodCallEvent); $this->afterExample($exampleEvent); $this->afterSuite($event); $io->askConfirmation(Argument::any())->shouldNotHaveBeenCalled(); }