Beispiel #1
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $helperSet = $this->getHelperSet();
     $this->container->set('console.input', $input);
     $this->container->set('console.output', $output);
     $this->container->setShared('console.prompter.factory', function ($c) use($helperSet) {
         return new Factory($c->get('console.input'), $c->get('console.output'), $helperSet);
     });
     $this->container->setShared('process.executioncontext', function () {
         return JsonExecutionContext::fromEnv($_SERVER);
     });
     $assembler = new ContainerAssembler();
     $assembler->build($this->container);
     $this->loadConfigurationFile($input, $this->container);
     foreach ($this->container->getByPrefix('console.commands') as $command) {
         $this->add($command);
     }
     $this->setDispatcher($this->container->get('console_event_dispatcher'));
     $this->container->get('console.io')->setConsoleWidth($this->getTerminalWidth());
     StreamWrapper::reset();
     foreach ($this->container->getByPrefix('loader.resource_loader.spec_transformer') as $transformer) {
         StreamWrapper::addTransformer($transformer);
     }
     StreamWrapper::register();
     return parent::doRun($input, $output);
 }
Beispiel #2
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(), false) && is_file($resource->getSpecFilename())) {
             require_once StreamWrapper::wrapPath($resource->getSpecFilename());
         }
         if (!class_exists($resource->getSpecClassname(), false)) {
             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;
 }
Beispiel #3
0
 /**
  * @test
  * @requires PHP 7.0
  */
 function it_loads_a_spec_with_no_typehints()
 {
     require StreamWrapper::wrapPath(__DIR__ . '/examples/ExampleSpec.php');
     $reflection = new \ReflectionClass('integration\\PhpSpec\\Loader\\examples\\ExampleSpec');
     $method = $reflection->getMethod('it_requires_a_stdclass');
     $parameters = $method->getParameters();
     $this->assertNull($parameters[0]->getClass());
 }
 /**
  * @beforeScenario
  */
 public function setupApplication()
 {
     StreamWrapper::register();
     $this->application = new Application('2.1-dev');
     $this->application->setAutoExit(false);
     $this->tester = new ApplicationTester($this->application);
     $this->setupReRunner();
     $this->setupPrompter();
 }
Beispiel #5
0
 /**
  * @param \ReflectionMethod $reflectionMethod
  *
  * @return string
  */
 private function getCodeBody(\ReflectionMethod $reflectionMethod)
 {
     $endLine = $reflectionMethod->getEndLine();
     $startLine = $reflectionMethod->getStartLine();
     $reflectionClass = $this->getMethodOwner($reflectionMethod, $startLine, $endLine);
     $length = $endLine - $startLine;
     $lines = file(StreamWrapper::wrapPath($reflectionClass->getFileName()));
     $code = join(PHP_EOL, array_slice($lines, $startLine - 1, $length + 1));
     return preg_replace('/.*function[^{]+{/s', '', $code);
 }