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.'); }
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); }