mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-13 08:34:12 +02:00
Convert level/levelName to enums (#1656)
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
namespace Monolog\Handler;
|
||||
|
||||
use Monolog\Test\TestCase;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Level;
|
||||
use Monolog\Formatter\LineFormatter;
|
||||
use Monolog\Handler\Slack\SlackRecord;
|
||||
|
||||
@@ -42,7 +42,7 @@ class SlackHandlerTest extends TestCase
|
||||
public function testWriteHeader()
|
||||
{
|
||||
$this->createHandler();
|
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
|
||||
$this->handler->handle($this->getRecord(Level::Critical, 'test1'));
|
||||
fseek($this->res, 0);
|
||||
$content = fread($this->res, 1024);
|
||||
|
||||
@@ -52,7 +52,7 @@ class SlackHandlerTest extends TestCase
|
||||
public function testWriteContent()
|
||||
{
|
||||
$this->createHandler();
|
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
|
||||
$this->handler->handle($this->getRecord(Level::Critical, 'test1'));
|
||||
fseek($this->res, 0);
|
||||
$content = fread($this->res, 1024);
|
||||
|
||||
@@ -65,13 +65,13 @@ class SlackHandlerTest extends TestCase
|
||||
public function testWriteContentUsesFormatterIfProvided()
|
||||
{
|
||||
$this->createHandler('myToken', 'channel1', 'Monolog', false);
|
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
|
||||
$this->handler->handle($this->getRecord(Level::Critical, 'test1'));
|
||||
fseek($this->res, 0);
|
||||
$content = fread($this->res, 1024);
|
||||
|
||||
$this->createHandler('myToken', 'channel1', 'Monolog', false);
|
||||
$this->handler->setFormatter(new LineFormatter('foo--%message%'));
|
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test2'));
|
||||
$this->handler->handle($this->getRecord(Level::Critical, 'test2'));
|
||||
fseek($this->res, 0);
|
||||
$content2 = fread($this->res, 1024);
|
||||
|
||||
@@ -82,7 +82,7 @@ class SlackHandlerTest extends TestCase
|
||||
public function testWriteContentWithEmoji()
|
||||
{
|
||||
$this->createHandler('myToken', 'channel1', 'Monolog', true, 'alien');
|
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
|
||||
$this->handler->handle($this->getRecord(Level::Critical, 'test1'));
|
||||
fseek($this->res, 0);
|
||||
$content = fread($this->res, 1024);
|
||||
|
||||
@@ -105,7 +105,7 @@ class SlackHandlerTest extends TestCase
|
||||
public function testWriteContentWithPlainTextMessage()
|
||||
{
|
||||
$this->createHandler('myToken', 'channel1', 'Monolog', false);
|
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
|
||||
$this->handler->handle($this->getRecord(Level::Critical, 'test1'));
|
||||
fseek($this->res, 0);
|
||||
$content = fread($this->res, 1024);
|
||||
|
||||
@@ -115,20 +115,20 @@ class SlackHandlerTest extends TestCase
|
||||
public function provideLevelColors()
|
||||
{
|
||||
return array(
|
||||
array(Logger::DEBUG, urlencode(SlackRecord::COLOR_DEFAULT)),
|
||||
array(Logger::INFO, SlackRecord::COLOR_GOOD),
|
||||
array(Logger::NOTICE, SlackRecord::COLOR_GOOD),
|
||||
array(Logger::WARNING, SlackRecord::COLOR_WARNING),
|
||||
array(Logger::ERROR, SlackRecord::COLOR_DANGER),
|
||||
array(Logger::CRITICAL, SlackRecord::COLOR_DANGER),
|
||||
array(Logger::ALERT, SlackRecord::COLOR_DANGER),
|
||||
array(Logger::EMERGENCY,SlackRecord::COLOR_DANGER),
|
||||
array(Level::Debug, urlencode(SlackRecord::COLOR_DEFAULT)),
|
||||
array(Level::Info, SlackRecord::COLOR_GOOD),
|
||||
array(Level::Notice, SlackRecord::COLOR_GOOD),
|
||||
array(Level::Warning, SlackRecord::COLOR_WARNING),
|
||||
array(Level::Error, SlackRecord::COLOR_DANGER),
|
||||
array(Level::Critical, SlackRecord::COLOR_DANGER),
|
||||
array(Level::Alert, SlackRecord::COLOR_DANGER),
|
||||
array(Level::Emergency,SlackRecord::COLOR_DANGER),
|
||||
);
|
||||
}
|
||||
|
||||
private function createHandler($token = 'myToken', $channel = 'channel1', $username = 'Monolog', $useAttachment = true, $iconEmoji = null, $useShortAttachment = false, $includeExtra = false)
|
||||
{
|
||||
$constructorArgs = [$token, $channel, $username, $useAttachment, $iconEmoji, Logger::DEBUG, true, $useShortAttachment, $includeExtra];
|
||||
$constructorArgs = [$token, $channel, $username, $useAttachment, $iconEmoji, Level::Debug, true, $useShortAttachment, $includeExtra];
|
||||
$this->res = fopen('php://memory', 'a');
|
||||
$this->handler = $this->getMockBuilder('Monolog\Handler\SlackHandler')
|
||||
->setConstructorArgs($constructorArgs)
|
||||
|
Reference in New Issue
Block a user