Esempio n. 1
0
 public function setContainer(ContainerInterface $container)
 {
     parent::setContainer($container);
     $logger = new Logger($this->getTitle());
     $logger->pushHandler($container->get('logger.handler'));
     $this->logger = $logger;
 }
Esempio n. 2
0
 /**
  * @dataProvider getTestLogOutput
  */
 public function testLogOutput($type, $message, $expected = null, $context = array())
 {
     if (is_null($expected)) {
         $expected = $message;
     }
     $handler = new ConsoleHandler(static::$container->get('ui.output'));
     $logger = new Logger('TestLog');
     $logger->pushHandler($handler);
     $method = 'add' . $type;
     call_user_func(array($logger, $method), $message, $context);
     $this->assertDisplayContains($expected);
 }
 function it_should_handle_runAllCommand_events(GenericEvent $event, ContainerInterface $container, PluginInterface $plugin, Logger $logger)
 {
     $event->getSubject()->willReturn($container);
     $event->addProcessEvent(Argument::any())->shouldBeCalled();
     $logger->addDebug(Argument::cetera())->shouldBeCalled();
     $logger->addDebug(Argument::containingString('Start'))->shouldBeCalled();
     $logger->addDebug(Argument::containingString('End'), Argument::cetera())->shouldBeCalled();
     $event->getArgument('plugin')->willReturn(null);
     $resultEvent = new ProcessEvent($plugin->getWrappedObject(), array());
     $plugin->getTitle()->willReturn('PluginSpec');
     $plugin->runAll()->shouldBeCalled()->willReturn($resultEvent);
     $this->runAllCommand($event);
 }
Esempio n. 4
0
 private function doRunAll()
 {
     $command = $this->cmdRunAll;
     if ($this->options['keep_failed']) {
         $files = array();
         foreach ($this->failed as $key => $failedEvent) {
             $file = $failedEvent->getArgument('file');
             if (file_exists($file)) {
                 $file = ltrim(str_replace(getcwd(), '', $file), '\\/');
                 if (!in_array($file, $files)) {
                     $files[] = $file;
                 }
             }
         }
         $files = array_unique($files);
         if (!empty($files)) {
             $command = $this->cmdRun;
             $specFiles = implode(',', $files);
             $command = $command . ' --spec-files=' . $specFiles;
             $this->logger->debug('Keep failed spec run');
         }
     }
     // start to run phpspec command
     $arguments = explode(' ', $command);
     $builder = new ProcessBuilder($arguments);
     $runner = $this->getRunner();
     $runner->run($builder);
     // not showing success events for run all
     $results = $this->renderResult(false);
     if (count($this->failed) === 0) {
         $results[] = ResultEvent::createSucceed('Run all specs success');
     }
     return $results;
 }
Esempio n. 5
0
 private function reportClover($target)
 {
     /* @var \PHP_CodeCoverage_Report_Clover $report */
     $relative = str_replace(getcwd() . DIRECTORY_SEPARATOR, '', $target);
     $this->logger->addCommon(sprintf('Generating clover output to: <comment>%s</comment> please wait!', $relative));
     $report = new \PHP_CodeCoverage_Report_Clover();
     $report->process($this->coverage, $target);
 }
Esempio n. 6
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);
             }
         }
     }
 }
Esempio n. 7
0
 function its_write_behavior_should_be_detected()
 {
     $infoRecord = array('message' => 'My info message', 'context' => array(), 'level' => Logger::INFO, 'level_name' => Logger::getLevelName(Logger::INFO), 'channel' => 'app', 'datetime' => new \DateTime('2013-05-29 16:21:54'), 'extra' => array());
     $this->shouldNotBeLogged();
     $this->handle($infoRecord);
     $this->shouldBeLogged();
     $this->reset();
     $this->shouldNotBeLogged();
     $this->handle($infoRecord);
     $this->shouldBeLogged();
 }
Esempio n. 8
0
 public function testWritingAndFormatting()
 {
     $output = $this->getMock('Symfony\\Component\\Console\\Output\\ConsoleOutputInterface');
     $output->expects($this->any())->method('getVerbosity')->will($this->returnValue(OutputInterface::VERBOSITY_DEBUG));
     $output->expects($this->once())->method('write')->with('<info>[16:21:54] app.INFO:</info> My info message' . "\n");
     $errorOutput = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface');
     $errorOutput->expects($this->once())->method('write')->with('<error>[16:21:54] app.ERROR:</error> My error message' . "\n");
     $output->expects($this->any())->method('getErrorOutput')->will($this->returnValue($errorOutput));
     $handler = new ConsoleHandler(null, false);
     $handler->setOutput($output);
     $infoRecord = array('message' => 'My info message', 'context' => array(), 'level' => Logger::INFO, 'level_name' => Logger::getLevelName(Logger::INFO), 'channel' => 'app', 'datetime' => new \DateTime('2013-05-29 16:21:54'), 'extra' => array());
     $this->assertTrue($handler->handle($infoRecord), 'The handler finished handling the log as bubble is false.');
     $errorRecord = array('message' => 'My error message', 'context' => array(), 'level' => Logger::ERROR, 'level_name' => Logger::getLevelName(Logger::ERROR), 'channel' => 'app', 'datetime' => new \DateTime('2013-05-29 16:21:54'), 'extra' => array());
     $this->assertTrue($handler->handle($errorRecord), 'The handler finished handling the log as bubble is false.');
 }
Esempio n. 9
0
 public function configure()
 {
     $logger = new Logger($this->getTitle());
     $logger->pushHandler($this->container->get('logger.handler'));
     $this->setLogger($logger);
 }
Esempio n. 10
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);
 }
Esempio n. 11
0
 private function renderLintOutput($output)
 {
     foreach ($output as $message) {
         $this->logger->addFail($message);
     }
 }