mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-04 20:27:31 +02:00
Add initial tests for SlackRecord
This commit is contained in:
84
tests/Monolog/Handler/Slack/SlackRecordTest.php
Normal file
84
tests/Monolog/Handler/Slack/SlackRecordTest.php
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Monolog package.
|
||||||
|
*
|
||||||
|
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Monolog\Handler\Slack;
|
||||||
|
|
||||||
|
use Monolog\Logger;
|
||||||
|
use Monolog\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @coversDefaultClass Monolog\Handler\Slack\SlackRecord
|
||||||
|
*/
|
||||||
|
class SlackRecordTest extends TestCase
|
||||||
|
{
|
||||||
|
public function dataGetAttachmentColor()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(Logger::DEBUG, 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),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @dataProvider dataGetAttachmentColor
|
||||||
|
* @param int $logLevel
|
||||||
|
* @param string $expectedColour RGB hex color or name of Slack color
|
||||||
|
* @covers ::getAttachmentColor
|
||||||
|
*/
|
||||||
|
public function testGetAttachmentColor($logLevel, $expectedColour)
|
||||||
|
{
|
||||||
|
$slackRecord = new SlackRecord('#test');
|
||||||
|
$this->assertSame(
|
||||||
|
$expectedColour,
|
||||||
|
$slackRecord->getAttachmentColor($logLevel)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testStringifyReturnsNullWithNoLineFormatter()
|
||||||
|
{
|
||||||
|
$slackRecord = new SlackRecord('#test');
|
||||||
|
$this->assertNull($slackRecord->stringify(array('foo' => 'bar')));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function dataStringify()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(array(), ''),
|
||||||
|
array(array('foo' => 'bar'), 'foo: bar'),
|
||||||
|
array(array('Foo' => 'bAr'), 'Foo: bAr'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataStringify
|
||||||
|
*/
|
||||||
|
public function testStringifyWithLineFormatter($fields, $expectedResult)
|
||||||
|
{
|
||||||
|
$slackRecord = new SlackRecord(
|
||||||
|
'#test',
|
||||||
|
'test',
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame($expectedResult, $slackRecord->stringify($fields));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user