36 if (!extension_loaded(
'openssl')) {
37 $this->markTestSkipped(
'This test requires openssl to run');
46 $content = fread($this->res, 1024);
48 $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);
56 $content = fread($this->res, 1024);
58 $this->assertRegexp(
'/token=myToken&channel=channel1&username=Monolog&text=&attachments=.*$/', $content);
63 $this->
createHandler(
'myToken',
'channel1',
'Monolog',
false);
66 $content = fread($this->res, 1024);
68 $this->
createHandler(
'myToken',
'channel1',
'Monolog',
false);
69 $this->handler->setFormatter(
new LineFormatter(
'foo--%message%'));
72 $content2 = fread($this->res, 1024);
74 $this->assertRegexp(
'/token=myToken&channel=channel1&username=Monolog&text=test1.*$/', $content);
75 $this->assertRegexp(
'/token=myToken&channel=channel1&username=Monolog&text=foo--test2.*$/', $content2);
80 $this->
createHandler(
'myToken',
'channel1',
'Monolog',
true,
'alien');
83 $content = fread($this->res, 1024);
85 $this->assertRegexp(
'/icon_emoji=%3Aalien%3A$/', $content);
94 $this->handler->handle($this->
getRecord($level,
'test1'));
96 $content = fread($this->res, 1024);
98 $this->assertRegexp(
'/color%22%3A%22'.$expectedColor.
'/', $content);
103 $this->
createHandler(
'myToken',
'channel1',
'Monolog',
false);
105 fseek($this->res, 0);
106 $content = fread($this->res, 1024);
108 $this->assertRegexp(
'/text=test1/', $content);
125 private function createHandler($token =
'myToken', $channel =
'channel1', $username =
'Monolog', $useAttachment =
true, $iconEmoji =
null, $useShortAttachment =
false, $includeExtra =
false)
127 $constructorArgs = array($token, $channel, $username, $useAttachment, $iconEmoji,
Logger::DEBUG,
true, $useShortAttachment, $includeExtra);
128 $this->res = fopen(
'php://memory',
'a');
129 $this->handler = $this->getMock(
130 '\Monolog\Handler\SlackHandler',
131 array(
'fsockopen',
'streamSetTimeout',
'closeSocket'),
135 $reflectionProperty = new \ReflectionProperty(
'\Monolog\Handler\SocketHandler',
'connectionString');
136 $reflectionProperty->setAccessible(
true);
137 $reflectionProperty->setValue($this->handler,
'localhost:1234');
139 $this->handler->expects($this->any())
140 ->method(
'fsockopen')
141 ->will($this->returnValue($this->res));
142 $this->handler->expects($this->any())
143 ->method(
'streamSetTimeout')
144 ->will($this->returnValue(
true));
145 $this->handler->expects($this->any())
146 ->method(
'closeSocket')
147 ->will($this->returnValue(
true));
An exception for terminatinating execution or to throw for unit testing.
testWriteContentWithColors($level, $expectedColor)
@dataProvider provideLevelColors
testWriteContentWithEmoji()
testWriteContentUsesFormatterIfProvided()
testWriteContentWithPlainTextMessage()
createHandler($token='myToken', $channel='channel1', $username='Monolog', $useAttachment=true, $iconEmoji=null, $useShortAttachment=false, $includeExtra=false)
const EMERGENCY
Urgent alert.
const ERROR
Runtime errors.
const CRITICAL
Critical conditions.
const WARNING
Exceptional occurrences that are not errors.
const INFO
Interesting events.
const DEBUG
Detailed debug information.
const NOTICE
Uncommon events.
const ALERT
Action must be taken immediately.
getRecord($level=Logger::WARNING, $message='test', $context=array())