ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Monolog\Handler\SlackHandlerTest Class Reference
+ Inheritance diagram for Monolog\Handler\SlackHandlerTest:
+ Collaboration diagram for Monolog\Handler\SlackHandlerTest:

Public Member Functions

 setUp ()
 
 testWriteHeader ()
 
 testWriteContent ()
 
 testWriteContentWithEmoji ()
 
 testWriteContentWithColors ($level, $expectedColor)
 @dataProvider provideLevelColors More...
 
 testWriteContentWithPlainTextMessage ()
 
 provideLevelColors ()
 

Private Member Functions

 createHandler ($token='myToken', $channel='channel1', $username='Monolog', $useAttachment=true, $iconEmoji=null, $useShortAttachment=false, $includeExtra=false)
 

Private Attributes

 $res
 
 $handler
 

Additional Inherited Members

- Protected Member Functions inherited from Monolog\TestCase
 getRecord ($level=Logger::WARNING, $message='test', $context=array())
 
 getMultipleRecords ()
 
 getIdentityFormatter ()
 

Detailed Description

Member Function Documentation

◆ createHandler()

Monolog\Handler\SlackHandlerTest::createHandler (   $token = 'myToken',
  $channel = 'channel1',
  $username = 'Monolog',
  $useAttachment = true,
  $iconEmoji = null,
  $useShortAttachment = false,
  $includeExtra = false 
)
private

Definition at line 107 of file SlackHandlerTest.php.

108 {
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'),
114 $constructorArgs
115 );
116
117 $reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString');
118 $reflectionProperty->setAccessible(true);
119 $reflectionProperty->setValue($this->handler, 'localhost:1234');
120
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));
130
131 $this->handler->setFormatter($this->getIdentityFormatter());
132 }
const DEBUG
Detailed debug information.
Definition: Logger.php:32

References Monolog\Logger\DEBUG, and Monolog\TestCase\getIdentityFormatter().

Referenced by Monolog\Handler\SlackHandlerTest\testWriteContent(), Monolog\Handler\SlackHandlerTest\testWriteContentWithColors(), Monolog\Handler\SlackHandlerTest\testWriteContentWithEmoji(), Monolog\Handler\SlackHandlerTest\testWriteContentWithPlainTextMessage(), and Monolog\Handler\SlackHandlerTest\testWriteHeader().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ provideLevelColors()

Monolog\Handler\SlackHandlerTest::provideLevelColors ( )

Definition at line 93 of file SlackHandlerTest.php.

94 {
95 return array(
96 array(Logger::DEBUG, '%23e3e4e6'), // escaped #e3e4e6
97 array(Logger::INFO, 'good'),
98 array(Logger::NOTICE, 'good'),
99 array(Logger::WARNING, 'warning'),
100 array(Logger::ERROR, 'danger'),
101 array(Logger::CRITICAL, 'danger'),
102 array(Logger::ALERT, 'danger'),
103 array(Logger::EMERGENCY,'danger'),
104 );
105 }
const EMERGENCY
Urgent alert.
Definition: Logger.php:77
const ERROR
Runtime errors.
Definition: Logger.php:57
const CRITICAL
Critical conditions.
Definition: Logger.php:64
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
const INFO
Interesting events.
Definition: Logger.php:39
const NOTICE
Uncommon events.
Definition: Logger.php:44
const ALERT
Action must be taken immediately.
Definition: Logger.php:72

References Monolog\Logger\ALERT, Monolog\Logger\CRITICAL, Monolog\Logger\DEBUG, Monolog\Logger\EMERGENCY, Monolog\Logger\ERROR, Monolog\Logger\INFO, Monolog\Logger\NOTICE, and Monolog\Logger\WARNING.

◆ setUp()

Monolog\Handler\SlackHandlerTest::setUp ( )

Definition at line 33 of file SlackHandlerTest.php.

34 {
35 if (!extension_loaded('openssl')) {
36 $this->markTestSkipped('This test requires openssl to run');
37 }
38 }

◆ testWriteContent()

Monolog\Handler\SlackHandlerTest::testWriteContent ( )

Definition at line 50 of file SlackHandlerTest.php.

51 {
52 $this->createHandler();
53 $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
54 fseek($this->res, 0);
55 $content = fread($this->res, 1024);
56
57 $this->assertRegexp('/token=myToken&channel=channel1&username=Monolog&text=&attachments=.*$/', $content);
58 }
createHandler($token='myToken', $channel='channel1', $username='Monolog', $useAttachment=true, $iconEmoji=null, $useShortAttachment=false, $includeExtra=false)
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19

References Monolog\Handler\SlackHandlerTest\createHandler(), Monolog\Logger\CRITICAL, and Monolog\TestCase\getRecord().

+ Here is the call graph for this function:

◆ testWriteContentWithColors()

Monolog\Handler\SlackHandlerTest::testWriteContentWithColors (   $level,
  $expectedColor 
)

@dataProvider provideLevelColors

Definition at line 73 of file SlackHandlerTest.php.

74 {
75 $this->createHandler();
76 $this->handler->handle($this->getRecord($level, 'test1'));
77 fseek($this->res, 0);
78 $content = fread($this->res, 1024);
79
80 $this->assertRegexp('/color%22%3A%22'.$expectedColor.'/', $content);
81 }

References Monolog\Handler\SlackHandlerTest\createHandler(), and Monolog\TestCase\getRecord().

+ Here is the call graph for this function:

◆ testWriteContentWithEmoji()

Monolog\Handler\SlackHandlerTest::testWriteContentWithEmoji ( )

Definition at line 60 of file SlackHandlerTest.php.

61 {
62 $this->createHandler('myToken', 'channel1', 'Monolog', true, 'alien');
63 $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
64 fseek($this->res, 0);
65 $content = fread($this->res, 1024);
66
67 $this->assertRegexp('/icon_emoji=%3Aalien%3A$/', $content);
68 }

References Monolog\Handler\SlackHandlerTest\createHandler(), Monolog\Logger\CRITICAL, and Monolog\TestCase\getRecord().

+ Here is the call graph for this function:

◆ testWriteContentWithPlainTextMessage()

Monolog\Handler\SlackHandlerTest::testWriteContentWithPlainTextMessage ( )

Definition at line 83 of file SlackHandlerTest.php.

84 {
85 $this->createHandler('myToken', 'channel1', 'Monolog', false);
86 $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
87 fseek($this->res, 0);
88 $content = fread($this->res, 1024);
89
90 $this->assertRegexp('/text=test1/', $content);
91 }

References Monolog\Handler\SlackHandlerTest\createHandler(), Monolog\Logger\CRITICAL, and Monolog\TestCase\getRecord().

+ Here is the call graph for this function:

◆ testWriteHeader()

Monolog\Handler\SlackHandlerTest::testWriteHeader ( )

Definition at line 40 of file SlackHandlerTest.php.

41 {
42 $this->createHandler();
43 $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
44 fseek($this->res, 0);
45 $content = fread($this->res, 1024);
46
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);
48 }

References Monolog\Handler\SlackHandlerTest\createHandler(), Monolog\Logger\CRITICAL, and Monolog\TestCase\getRecord().

+ Here is the call graph for this function:

Field Documentation

◆ $handler

Monolog\Handler\SlackHandlerTest::$handler
private

Definition at line 31 of file SlackHandlerTest.php.

◆ $res

Monolog\Handler\SlackHandlerTest::$res
private

Definition at line 26 of file SlackHandlerTest.php.


The documentation for this class was generated from the following file: