Пример #1
0
 /**
  * @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;
 }
 /**
  * @param SuiteEvent $event
  */
 public function afterSuite(SuiteEvent $event)
 {
     if (!$this->io->isCodeGenerationEnabled()) {
         return;
     }
     foreach ($this->exceptions as $exception) {
         $resource = $this->resources->createResource($exception->getCollaboratorName());
         if ($this->resourceIsInSpecNamespace($exception, $resource)) {
             continue;
         }
         if ($this->io->askConfirmation(sprintf('Would you like me to generate an interface `%s` for you?', $exception->getCollaboratorName()))) {
             $this->generator->generate($resource, 'interface');
             $event->markAsWorthRerunning();
         }
     }
 }
 /**
  * @param SuiteEvent $event
  */
 public function afterSuite(SuiteEvent $event)
 {
     foreach ($this->interfaces as $interface => $methods) {
         try {
             $resource = $this->resources->createResource($interface);
         } catch (ResourceCreationException $e) {
             continue;
         }
         foreach ($methods as $method => $arguments) {
             if ($this->io->askConfirmation(sprintf(self::PROMPT, $interface, $method))) {
                 $this->generator->generate($resource, 'method-signature', array('name' => $method, 'arguments' => $this->getRealArguments($arguments)));
                 $event->markAsWorthRerunning();
             }
         }
     }
 }