mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-07 21:56:31 +02:00
CI fixes
This commit is contained in:
@@ -19,7 +19,6 @@ use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\InvalidArgumentException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
use Psr\Log\Test\LoggerInterfaceTest;
|
||||
|
||||
class PsrLogCompatTest extends TestCase
|
||||
{
|
||||
@@ -61,28 +60,28 @@ class PsrLogCompatTest extends TestCase
|
||||
public function testLogsAtAllLevels($level, $message)
|
||||
{
|
||||
$logger = $this->getLogger();
|
||||
$logger->{$level}($message, array('user' => 'Bob'));
|
||||
$logger->log($level, $message, array('user' => 'Bob'));
|
||||
$logger->{$level}($message, ['user' => 'Bob']);
|
||||
$logger->log($level, $message, ['user' => 'Bob']);
|
||||
|
||||
$expected = array(
|
||||
$expected = [
|
||||
"$level message of level $level with context: Bob",
|
||||
"$level message of level $level with context: Bob",
|
||||
);
|
||||
];
|
||||
$this->assertEquals($expected, $this->getLogs());
|
||||
}
|
||||
|
||||
public function provideLevelsAndMessages()
|
||||
{
|
||||
return array(
|
||||
LogLevel::EMERGENCY => array(LogLevel::EMERGENCY, 'message of level emergency with context: {user}'),
|
||||
LogLevel::ALERT => array(LogLevel::ALERT, 'message of level alert with context: {user}'),
|
||||
LogLevel::CRITICAL => array(LogLevel::CRITICAL, 'message of level critical with context: {user}'),
|
||||
LogLevel::ERROR => array(LogLevel::ERROR, 'message of level error with context: {user}'),
|
||||
LogLevel::WARNING => array(LogLevel::WARNING, 'message of level warning with context: {user}'),
|
||||
LogLevel::NOTICE => array(LogLevel::NOTICE, 'message of level notice with context: {user}'),
|
||||
LogLevel::INFO => array(LogLevel::INFO, 'message of level info with context: {user}'),
|
||||
LogLevel::DEBUG => array(LogLevel::DEBUG, 'message of level debug with context: {user}'),
|
||||
);
|
||||
return [
|
||||
LogLevel::EMERGENCY => [LogLevel::EMERGENCY, 'message of level emergency with context: {user}'],
|
||||
LogLevel::ALERT => [LogLevel::ALERT, 'message of level alert with context: {user}'],
|
||||
LogLevel::CRITICAL => [LogLevel::CRITICAL, 'message of level critical with context: {user}'],
|
||||
LogLevel::ERROR => [LogLevel::ERROR, 'message of level error with context: {user}'],
|
||||
LogLevel::WARNING => [LogLevel::WARNING, 'message of level warning with context: {user}'],
|
||||
LogLevel::NOTICE => [LogLevel::NOTICE, 'message of level notice with context: {user}'],
|
||||
LogLevel::INFO => [LogLevel::INFO, 'message of level info with context: {user}'],
|
||||
LogLevel::DEBUG => [LogLevel::DEBUG, 'message of level debug with context: {user}'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testThrowsOnInvalidLevel()
|
||||
@@ -96,9 +95,9 @@ class PsrLogCompatTest extends TestCase
|
||||
public function testContextReplacement()
|
||||
{
|
||||
$logger = $this->getLogger();
|
||||
$logger->info('{Message {nothing} {user} {foo.bar} a}', array('user' => 'Bob', 'foo.bar' => 'Bar'));
|
||||
$logger->info('{Message {nothing} {user} {foo.bar} a}', ['user' => 'Bob', 'foo.bar' => 'Bar']);
|
||||
|
||||
$expected = array('info {Message {nothing} Bob Bar a}');
|
||||
$expected = ['info {Message {nothing} Bob Bar a}'];
|
||||
$this->assertEquals($expected, $this->getLogs());
|
||||
}
|
||||
|
||||
@@ -111,7 +110,7 @@ class PsrLogCompatTest extends TestCase
|
||||
|
||||
$this->getLogger()->warning($dummy);
|
||||
|
||||
$expected = array("warning $string");
|
||||
$expected = ["warning $string"];
|
||||
$this->assertEquals($expected, $this->getLogs());
|
||||
}
|
||||
|
||||
@@ -120,47 +119,47 @@ class PsrLogCompatTest extends TestCase
|
||||
$closed = fopen('php://memory', 'r');
|
||||
fclose($closed);
|
||||
|
||||
$context = array(
|
||||
$context = [
|
||||
'bool' => true,
|
||||
'null' => null,
|
||||
'string' => 'Foo',
|
||||
'int' => 0,
|
||||
'float' => 0.5,
|
||||
'nested' => array('with object' => $this->createStringable()),
|
||||
'nested' => ['with object' => $this->createStringable()],
|
||||
'object' => new \DateTime('now', new DateTimeZone('Europe/London')),
|
||||
'resource' => fopen('php://memory', 'r'),
|
||||
'closed' => $closed,
|
||||
);
|
||||
];
|
||||
|
||||
$this->getLogger()->warning('Crazy context data', $context);
|
||||
|
||||
$expected = array('warning Crazy context data');
|
||||
$expected = ['warning Crazy context data'];
|
||||
$this->assertEquals($expected, $this->getLogs());
|
||||
}
|
||||
|
||||
public function testContextExceptionKeyCanBeExceptionOrOtherValues()
|
||||
{
|
||||
$logger = $this->getLogger();
|
||||
$logger->warning('Random message', array('exception' => 'oops'));
|
||||
$logger->critical('Uncaught Exception!', array('exception' => new \LogicException('Fail')));
|
||||
$logger->warning('Random message', ['exception' => 'oops']);
|
||||
$logger->critical('Uncaught Exception!', ['exception' => new \LogicException('Fail')]);
|
||||
|
||||
$expected = array(
|
||||
$expected = [
|
||||
'warning Random message',
|
||||
'critical Uncaught Exception!'
|
||||
);
|
||||
'critical Uncaught Exception!',
|
||||
];
|
||||
$this->assertEquals($expected, $this->getLogs());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a mock of a `Stringable`.
|
||||
*
|
||||
* @param string $string The string that must be represented by the stringable.
|
||||
* @param string $string The string that must be represented by the stringable.
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject A mock of an object that has a `__toString()` method.
|
||||
*/
|
||||
protected function createStringable($string = '')
|
||||
{
|
||||
$mock = $this->getMockBuilder('Stringable')
|
||||
->setMethods(array('__toString'))
|
||||
->setMethods(['__toString'])
|
||||
->getMock();
|
||||
|
||||
$mock->method('__toString')
|
||||
|
Reference in New Issue
Block a user