35 if (!extension_loaded(
'openssl')) {
36 $this->markTestSkipped(
'This test requires openssl to run');
45 $content = fread($this->res, 1024);
47 $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);
55 $content = fread($this->res, 1024);
57 $this->assertRegexp(
'/token=myToken&channel=channel1&username=Monolog&text=&attachments=.*$/', $content);
62 $this->
createHandler(
'myToken',
'channel1',
'Monolog',
true,
'alien');
65 $content = fread($this->res, 1024);
67 $this->assertRegexp(
'/icon_emoji=%3Aalien%3A$/', $content);
76 $this->handler->handle($this->
getRecord($level,
'test1'));
78 $content = fread($this->res, 1024);
80 $this->assertRegexp(
'/color%22%3A%22'.$expectedColor.
'/', $content);
85 $this->
createHandler(
'myToken',
'channel1',
'Monolog',
false);
88 $content = fread($this->res, 1024);
90 $this->assertRegexp(
'/text=test1/', $content);
107 private function createHandler($token =
'myToken', $channel =
'channel1', $username =
'Monolog', $useAttachment =
true, $iconEmoji = null, $useShortAttachment =
false, $includeExtra =
false)
109 $constructorArgs = array($token, $channel, $username, $useAttachment, $iconEmoji,
Logger::DEBUG,
true, $useShortAttachment, $includeExtra);
110 $this->res = fopen(
'php://memory',
'a');
111 $this->handler = $this->getMock(
112 '\Monolog\Handler\SlackHandler',
113 array(
'fsockopen',
'streamSetTimeout',
'closeSocket'),
117 $reflectionProperty = new \ReflectionProperty(
'\Monolog\Handler\SocketHandler',
'connectionString');
118 $reflectionProperty->setAccessible(
true);
119 $reflectionProperty->setValue($this->handler,
'localhost:1234');
121 $this->handler->expects($this->any())
122 ->method(
'fsockopen')
123 ->will($this->returnValue($this->res));
124 $this->handler->expects($this->any())
125 ->method(
'streamSetTimeout')
126 ->will($this->returnValue(
true));
127 $this->handler->expects($this->any())
128 ->method(
'closeSocket')
129 ->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)
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.