示例#1
0
 function let(ContainerInterface $container, OutputInterface $output, ConsoleHandler $handler)
 {
     Filesystem::create()->mkdir(self::$tmpDir);
     $container->get('logger.handler')->willReturn($handler);
     $this->setContainer($container);
     $container->get('ui.output')->willReturn($output);
     $container->getParameter('phpguard.use_tty', Argument::any())->willReturn(false);
 }
示例#2
0
 function it_should_find_executable(ContainerInterface $container)
 {
     $container->hasParameter($id = 'runner.default_dirs')->willReturn(false);
     $container->setParameter($id, Argument::any())->shouldBeCalled();
     $this->findExecutable('foo')->shouldReturn(false);
     $this->findExecutable('php')->shouldNotReturn(false);
     $this->findExecutable('phpspec')->shouldNotReturn(false);
 }
 function it_should_terminate_application(GenericEvent $event, ContainerInterface $container, Application $application, PhpGuard $phpGuard)
 {
     $container->get('ui.application')->shouldBeCalled()->willReturn($application);
     $container->get('phpguard')->shouldBeCalled()->willReturn($phpGuard);
     $application->exitApplication()->shouldBeCalled();
     $phpGuard->stop()->shouldBeCalled();
     $this->terminated($event);
 }
示例#4
0
 function it_should_run_for_paths(Runner $runner, Process $process, ContainerInterface $container)
 {
     $results = array('succeed' => ResultEvent::createSucceed('Succeed'), 'failed' => ResultEvent::createFailed('Failed'), 'broken' => ResultEvent::createBroken('Broken'));
     Filesystem::create()->serialize($this->cacheFile, $results);
     $runner->run(Argument::any())->shouldBeCalled();
     $process->getExitCode()->shouldBeCalled()->willReturn(1);
     $container->setParameter('application.exit_code', ResultEvent::FAILED)->shouldBeCalled();
     $results = $this->run(array('some_path'));
     $results->getResults()->shouldHaveCount(2);
 }
示例#5
0
    function it_throws_when_plugin_not_exists(ContainerInterface $container)
    {
        $container->has('plugins.some')->willReturn(false);
        $text = <<<EOF
some:
    watch:
        - { pattern: "#^spec\\/.*\\.php" }
EOF;
        $this->shouldThrow('InvalidArgumentException')->duringCompile($text);
    }
 function it_plugin_should_not_run_if_not_active(ContainerInterface $container, PluginInterface $active, PluginInterface $inactive, EvaluateEvent $event)
 {
     $container->getByPrefix('plugins')->willReturn(array($active, $inactive));
     $active->isActive()->shouldBeCalled()->willReturn(true);
     $active->getMatchedFiles($event)->willReturn(array('some_file'));
     $active->run(Argument::any())->shouldBeCalled();
     $inactive->isActive()->shouldBeCalled()->willReturn(false);
     $inactive->run(Argument::any())->shouldNotBeCalled();
     $this->evaluate($event);
 }
示例#7
0
 function let(ContainerInterface $container, PhpGuard $phpGuard, Application $application, OutputInterface $output, OutputFormatterInterface $outputFormatter, EventDispatcherInterface $dispatcher)
 {
     $container->get('phpguard')->willReturn($phpGuard);
     $container->get('ui.application')->willReturn($application);
     $container->get('ui.output')->willReturn($output);
     $container->get('dispatcher')->willReturn($dispatcher);
     $output->getFormatter()->willreturn($outputFormatter);
     $output->write(Argument::any())->willReturn();
     $this->beAnInstanceOf('PhpGuard\\Application\\Test\\TestShell', array($container));
 }
示例#8
0
 function it_should_reload_when_configuration_changed(ContainerInterface $container, ChangeSetEvent $event, EventDispatcherInterface $dispatcher, ConsoleHandler $handler, Logger $logger)
 {
     $container->getParameter('config.file', Argument::any())->shouldBeCalled()->willReturn('phpguard.yml.dist');
     $container->get('logger.handler')->willReturn($handler);
     $container->get('logger')->willReturn($logger);
     $event->getFiles()->willReturn(array('phpguard.yml.dist'));
     $dispatcher->dispatch(ConfigEvents::RELOAD, Argument::any())->shouldBeCalled();
     $dispatcher->dispatch(ApplicationEvents::preEvaluate, Argument::any())->shouldBeCalled();
     $dispatcher->dispatch(ApplicationEvents::evaluate, Argument::any())->shouldBeCalled();
     $dispatcher->dispatch(ApplicationEvents::postEvaluate, Argument::any())->shouldBeCalled();
     $this->listen($event);
 }
示例#9
0
 function it_should_configure_inspector(ContainerInterface $container, Runner $runner)
 {
     $this->beConstructedWith();
     /*$container->get('runner')
           ->shouldBeCalled()
           ->willReturn($runner)
       ;
       $runner->findExecutable('behat-phpguard')
           ->shouldBeCalled()
           ->willReturn('some')
       ;*/
     $container->setShared('behat.inspector', Argument::any())->shouldBeCalled();
     $this->configure();
 }
示例#10
0
 public static function setupContainer(ContainerInterface $container)
 {
     $container->setShared('coverage.filter', function () {
         return new \PHP_CodeCoverage_Filter();
     });
     $container->setShared('coverage', function ($c) {
         $filter = $c->get('coverage.filter');
         return new \PHP_CodeCoverage(null, $filter);
     });
     $container->setShared('coverage.session', function () {
         $runner = new CodeCoverageSession();
         return new $runner();
     });
     $container->setShared('dispatcher.listeners.coverage', function ($c) {
         return $c->get('coverage.session');
     });
 }
示例#11
0
 private function loadPlugin(ContainerInterface $container, $class)
 {
     if (class_exists($class)) {
         $r = new \ReflectionClass($class);
         if (!$r->isAbstract()) {
             $plugin = new $class();
             $id = 'plugins.' . $plugin->getName();
             if (!$container->has($id)) {
                 $logger = new Logger($plugin->getTitle());
                 $logger->pushHandler($container->get('logger.handler'));
                 $plugin->setLogger($logger);
                 $plugin->setContainer($container);
                 $container->set($id, $plugin);
                 $container->get('dispatcher')->addSubscriber($plugin);
             }
         }
     }
 }
示例#12
0
 function its_getMatchedFiles_returns_false_if_tag_is_not_matched(EvaluateEvent $event, Watcher $watcher, ContainerInterface $container)
 {
     $tags = array('foo');
     $container->getParameter('filter.tags', array())->shouldBeCalled()->willReturn($tags);
     $watcher->hasTags($tags)->shouldBeCalled()->willReturn(false);
     $watcher->matchFile(__FILE__)->shouldNotBeCalled();
     $watcher->getOptions()->willReturn(array('tags' => $tags));
     $event->getFiles()->willReturn(array(__FILE__));
     $this->getMatchedFiles($event);
 }
示例#13
0
 function let(ContainerInterface $container, Runner $runner, Process $process, BehatPlugin $plugin, Filesystem $filesystem)
 {
     if (is_null(static::$cwd)) {
         static::$cwd = getcwd();
     }
     if (!is_dir(static::$tmpDir)) {
         mkdir(static::$tmpDir, 0777, true);
     }
     chdir(static::$tmpDir);
     $container->get('plugins.behat')->willReturn($plugin);
     $container->get('runner')->willReturn($runner);
     $this->options = array('all_after_pass' => false, 'cli' => 'run_cli', 'run_all_cli' => 'run_all_cli', 'executable' => 'executable');
     $plugin->getOptions()->willReturn($this->options);
     $runner->run(Argument::any())->willReturn($process);
     $filesystem->pathExists(Inspector::getRerunFileName())->willReturn(false);
     $container->get('filesystem')->willReturn($filesystem);
     $this->rerunFile = Inspector::getRerunFileName();
     $this->setContainer($container);
 }
示例#14
0
 function it_should_check_file_with_linter_if_defined(ContainerInterface $container, LinterInterface $linter)
 {
     $container->has('linters.some')->shouldBeCalled()->willReturn(true);
     $container->get('linters.some')->willReturn($linter);
     $linter->getName()->shouldBeCalled()->willReturn('some');
     $linter->getTitle()->willReturn('SomeTitle');
     $this->setOptions(array('lint' => 'some', 'pattern' => 'some'));
     $linter->check(__FILE__)->shouldBeCalled()->willReturn(true);
     $this->lint(__FILE__)->shouldReturn(true);
 }
示例#15
0
 /**
  * @codeCoverageIgnore
  */
 public function exitApplication()
 {
     $exitCode = $this->container->getParameter('application.exit_code', 0);
     $type = ResultEvent::$maps[$exitCode];
     $this->container->get('logger')->addCommon('Application exit with code: <highlight>' . $exitCode . ' - ' . $type . '</highlight>');
     $this->container->get('ui.output')->writeln('');
     $this->container->get('logger')->addCommon(PhpGuard::EXIT_MESSAGE);
     $this->container->get('ui.output')->writeln('');
     exit($exitCode);
 }
 function let(ContainerInterface $container, OutputInterface $output, PhpGuard $phpGuard, Inspector $inspector)
 {
     $container->get('ui.output')->willReturn($output);
     $container->get('phpguard')->willReturn($phpGuard);
     $container->get('phpunit.inspector')->willReturn($inspector);
     $container->setShared('phpunit.inspector', Argument::any())->willReturn();
     $logger = new Logger('PhpUnit');
     $this->setLogger($logger);
     $this->setContainer($container);
 }
示例#17
0
 /**
  * @param  false|string $command
  * @return int
  */
 public function runCommand($command)
 {
     if ($command == false) {
         $command = 'all';
     }
     $command = trim($command);
     if ($command == 'quit') {
         $event = new GenericEvent($this->container);
         $this->container->get('dispatcher')->dispatch(ApplicationEvents::terminated, $event);
     } else {
         $this->unsetStreamBlocking();
         $this->readlineWriteHistory($command);
         $input = new StringInput($command);
         $retVal = $this->application->run($input, $this->output);
         $this->setStreamBlocking();
         $this->showPrompt();
         return $retVal;
     }
 }
示例#18
0
 function its_runAll_should_set_application_exit_code_if_results_has_failed_or_broken(ContainerInterface $container)
 {
     $failed = ResultEvent::createFailed('Failed', array('file' => 'some_file'));
     $success = ResultEvent::createSucceed('Success');
     Filesystem::create()->serialize($this->cacheFile, array('failed' => $failed, 'success' => $success));
     $container->setParameter('application.exit_code', ResultEvent::FAILED)->shouldBeCalled();
     $this->runAll();
 }
 function it_should_reload_configuration(GenericEvent $event, ContainerInterface $container, EventDispatcherInterface $dispatcher, Processor $processor)
 {
     $configFile = getcwd() . '/phpguard.yml.dist';
     $container->get('config')->shouldBeCalled()->willReturn($processor);
     $container->getParameter('config.file')->shouldBeCalled()->willReturn($configFile);
     $dispatcher->dispatch(ConfigEvents::PRELOAD, $event)->shouldBeCalled();
     $processor->compileFile($configFile)->shouldBeCalled();
     $dispatcher->dispatch(ConfigEvents::POSTLOAD, $event)->shouldBeCalled();
     $this->reload($event, ConfigEvents::LOAD, $dispatcher);
 }
示例#20
0
 function let(ContainerInterface $container, Logger $logger)
 {
     $container->get('logger')->willReturn($logger);
     $container->has(Argument::any())->willReturn(true);
     $this->setContainer($container);
 }
示例#21
0
 /**
  * @return ApplicationTester
  */
 protected function getTester()
 {
     return static::$container->get('tester');
 }
 function it_should_configure_inspector_when_application_initialized(ContainerInterface $container)
 {
     $container->setShared('phpspec.inspector', Argument::any())->shouldBeCalled();
     $this->configure();
 }
示例#23
0
 public function setupServices(ContainerInterface $container)
 {
     $container->setShared('config', function () {
         return new Processor();
     });
     $container->setShared('dispatcher', function ($c) {
         $dispatcher = new EventDispatcher();
         array_map(array($dispatcher, 'addSubscriber'), $c->getByPrefix('dispatcher.listeners'));
         return $dispatcher;
     });
     $container->setShared('logger.handler', function ($c) {
         $format = "%start_tag%[%datetime%][%channel%][%level_name%] %message% %context% %extra% %end_tag%\n";
         $formatter = new ConsoleFormatter($format);
         $handler = new ConsoleHandler(null, true);
         $handler->setFormatter($formatter);
         return $handler;
     });
     $container->setShared('logger', function ($c) {
         $logger = new Logger('Main');
         $logger->pushHandler($c->get('logger.handler'));
         return $logger;
     });
     $container->setShared('listen.listener', function ($c) {
         $listener = Listen::to(getcwd());
         $options = $c->get('phpguard')->getOptions();
         foreach ($options['ignores'] as $ignored) {
             $listener->ignores($ignored);
         }
         $phpguard = $c->get('phpguard');
         $listener->latency($options['latency']);
         $listener->callback(array($phpguard, 'listen'));
         return $listener;
     });
     $container->setShared('listen.adapter', function () {
         $adapter = Listen::getDefaultAdapter();
         return $adapter;
     });
     $container->setShared('locator', function () {
         $locator = new Locator();
         return $locator;
     });
     $container->setShared('dispatcher.listeners.locator', function ($c) {
         return $c->get('locator');
     });
     $container->setShared('runner.logger', function ($c) {
         $logger = new Logger('Runner');
         $logger->pushHandler($c->get('logger.handler'));
         return $logger;
     });
     $container->setShared('runner', function () {
         return new Runner();
     });
     $container->setShared('filesystem', function () {
         return new Filesystem();
     });
     CodeCoverageSession::setupContainer($container);
 }
 function it_should_not_print_report_if_session_has_empty_results(ContainerInterface $container)
 {
     $container->getParameter('session.results', Argument::any())->willReturn(array());
     $this->process();
 }