37 if (!extension_loaded(
'openssl')) {
38 $this->markTestSkipped(
'This test requires openssl to run');
47 $content = fread($this->res, 1024);
49 $this->assertRegexp(
'/POST \/api\/chat.postMessage HTTP\/1.1\\r\\nHost: slack.com\\r\\nContent-Type: application\/x-www-form-urlencoded\\r\\nContent-Length: \d{2,4}\\r\\n\\r\\n/', $content);
57 $content = fread($this->res, 1024);
59 $this->assertRegExp(
'/username=Monolog/', $content);
60 $this->assertRegExp(
'/channel=channel1/', $content);
61 $this->assertRegExp(
'/token=myToken/', $content);
62 $this->assertRegExp(
'/attachments/', $content);
67 $this->
createHandler(
'myToken',
'channel1',
'Monolog',
false);
70 $content = fread($this->res, 1024);
72 $this->
createHandler(
'myToken',
'channel1',
'Monolog',
false);
73 $this->handler->setFormatter(
new LineFormatter(
'foo--%message%'));
76 $content2 = fread($this->res, 1024);
78 $this->assertRegexp(
'/text=test1/', $content);
79 $this->assertRegexp(
'/text=foo--test2/', $content2);
84 $this->
createHandler(
'myToken',
'channel1',
'Monolog',
true,
'alien');
87 $content = fread($this->res, 1024);
89 $this->assertRegexp(
'/icon_emoji=%3Aalien%3A/', $content);
98 $this->handler->handle($this->
getRecord($level,
'test1'));
100 $content = fread($this->res, 1024);
102 $this->assertRegexp(
'/%22color%22%3A%22'.$expectedColor.
'/', $content);
107 $this->
createHandler(
'myToken',
'channel1',
'Monolog',
false);
109 fseek($this->res, 0);
110 $content = fread($this->res, 1024);
112 $this->assertRegexp(
'/text=test1/', $content);
129 private function createHandler(
$token =
'myToken', $channel =
'channel1', $username =
'Monolog', $useAttachment =
true, $iconEmoji = null, $useShortAttachment =
false, $includeExtra =
false)
131 $constructorArgs = array(
$token, $channel, $username, $useAttachment, $iconEmoji,
Logger::DEBUG,
true, $useShortAttachment, $includeExtra);
132 $this->res =
fopen(
'php://memory',
'a');
133 $this->handler = $this->getMock(
134 '\Monolog\Handler\SlackHandler',
135 array(
'fsockopen',
'streamSetTimeout',
'closeSocket'),
139 $reflectionProperty = new \ReflectionProperty(
'\Monolog\Handler\SocketHandler',
'connectionString');
140 $reflectionProperty->setAccessible(
true);
141 $reflectionProperty->setValue($this->handler,
'localhost:1234');
143 $this->handler->expects($this->any())
144 ->method(
'fsockopen')
145 ->will($this->returnValue($this->res));
146 $this->handler->expects($this->any())
147 ->method(
'streamSetTimeout')
148 ->will($this->returnValue(
true));
149 $this->handler->expects($this->any())
150 ->method(
'closeSocket')
151 ->will($this->returnValue(
true));
testWriteContentWithPlainTextMessage()
const NOTICE
Uncommon events.
const DEBUG
Detailed debug information.
testWriteContentWithEmoji()
const ERROR
Runtime errors.
getRecord($level=Logger::WARNING, $message='test', $context=array())
testWriteContentWithColors($level, $expectedColor)
provideLevelColors
createHandler($token='myToken', $channel='channel1', $username='Monolog', $useAttachment=true, $iconEmoji=null, $useShortAttachment=false, $includeExtra=false)
testWriteContentUsesFormatterIfProvided()
const WARNING
Exceptional occurrences that are not errors.
const EMERGENCY
Urgent alert.
const CRITICAL
Critical conditions.
const ALERT
Action must be taken immediately.
const INFO
Interesting events.