77 lines
2.7 KiB
PHP
77 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\PHPCI\Logging;
|
|
|
|
use Monolog\Logger;
|
|
use PHPCI\Logging\OutputLogHandler;
|
|
use PHPUnit_Framework_TestCase;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
/**
|
|
* Generated by PHPUnit_SkeletonGenerator on 2015-05-03 at 14:16:42.
|
|
*/
|
|
class OutputLogHandlerTest extends PHPUnit_Framework_TestCase
|
|
{
|
|
/**
|
|
* @dataProvider getVerbosityLevelMap
|
|
*/
|
|
public function testLevelMatchVerbosity($verbosity, $level)
|
|
{
|
|
$output = $this->prophesize('\Symfony\Component\Console\Output\OutputInterface');
|
|
$output->getVerbosity()->willReturn($verbosity);
|
|
|
|
$handler = new OutputLogHandler($output->reveal());
|
|
|
|
$this->assertEquals($level, $handler->getLevel());
|
|
}
|
|
|
|
|
|
public function getVerbosityLevelMap()
|
|
{
|
|
return array(
|
|
array(OutputInterface::VERBOSITY_QUIET, Logger::ERROR),
|
|
array(OutputInterface::VERBOSITY_NORMAL, Logger::WARNING),
|
|
array(OutputInterface::VERBOSITY_VERBOSE, Logger::NOTICE),
|
|
array(OutputInterface::VERBOSITY_VERY_VERBOSE, Logger::INFO),
|
|
array(OutputInterface::VERBOSITY_DEBUG, Logger::DEBUG),
|
|
);
|
|
}
|
|
|
|
public function testSendInfoToOutput()
|
|
{
|
|
$record = array('message' => 'FOO', 'level' => Logger::INFO);
|
|
|
|
$output = $this->prophesize('\Symfony\Component\Console\Output\ConsoleOutputInterface');
|
|
$output->getVerbosity()->willReturn(OutputInterface::VERBOSITY_DEBUG);
|
|
$output->getErrorOutput()->shouldNotBeCalled();
|
|
$output->write('BAR')->shouldBeCalled();
|
|
|
|
$formatter = $this->prophesize('\Monolog\Formatter\FormatterInterface');
|
|
$formatter->format($record)->willReturn('BAR');
|
|
|
|
$handler = new OutputLogHandler($output->reveal());
|
|
$handler->setFormatter($formatter->reveal());
|
|
|
|
$handler->handle($record);
|
|
}
|
|
|
|
public function testSendErrorsToStderr()
|
|
{
|
|
$record = array('message' => 'FOO', 'level' => Logger::ERROR);
|
|
|
|
$error = $this->prophesize('\Symfony\Component\Console\Output\OutputInterface');
|
|
$error->write('BAR')->shouldBeCalled();
|
|
|
|
$output = $this->prophesize('\Symfony\Component\Console\Output\ConsoleOutputInterface');
|
|
$output->getVerbosity()->willReturn(OutputInterface::VERBOSITY_DEBUG);
|
|
$output->getErrorOutput()->willReturn($error);
|
|
|
|
$formatter = $this->prophesize('\Monolog\Formatter\FormatterInterface');
|
|
$formatter->format(array('message' => '<fg=red>FOO</fg=red>', 'level' => Logger::ERROR))->willReturn('BAR');
|
|
|
|
$handler = new OutputLogHandler($output->reveal());
|
|
$handler->setFormatter($formatter->reveal());
|
|
|
|
$handler->handle($record);
|
|
}
|
|
}
|