ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Monolog\Handler\SlackHandlerTest Class Reference
+ Inheritance diagram for Monolog\Handler\SlackHandlerTest:
+ Collaboration diagram for Monolog\Handler\SlackHandlerTest:

Public Member Functions

 setUp ()
 
 testWriteHeader ()
 
 testWriteContent ()
 
 testWriteContentUsesFormatterIfProvided ()
 
 testWriteContentWithEmoji ()
 
 testWriteContentWithColors ($level, $expectedColor)
 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 125 of file SlackHandlerTest.php.

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

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

126  {
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'),
132  $constructorArgs
133  );
134 
135  $reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString');
136  $reflectionProperty->setAccessible(true);
137  $reflectionProperty->setValue($this->handler, 'localhost:1234');
138 
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));
148 
149  $this->handler->setFormatter($this->getIdentityFormatter());
150  }
const DEBUG
Detailed debug information.
Definition: Logger.php:32
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ provideLevelColors()

Monolog\Handler\SlackHandlerTest::provideLevelColors ( )

Definition at line 111 of file SlackHandlerTest.php.

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

112  {
113  return array(
114  array(Logger::DEBUG, '%23e3e4e6'), // escaped #e3e4e6
115  array(Logger::INFO, 'good'),
116  array(Logger::NOTICE, 'good'),
117  array(Logger::WARNING, 'warning'),
118  array(Logger::ERROR, 'danger'),
119  array(Logger::CRITICAL, 'danger'),
120  array(Logger::ALERT, 'danger'),
121  array(Logger::EMERGENCY,'danger'),
122  );
123  }
const NOTICE
Uncommon events.
Definition: Logger.php:44
const DEBUG
Detailed debug information.
Definition: Logger.php:32
const ERROR
Runtime errors.
Definition: Logger.php:57
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
const EMERGENCY
Urgent alert.
Definition: Logger.php:77
Create styles array
The data for the language used.
const CRITICAL
Critical conditions.
Definition: Logger.php:64
const ALERT
Action must be taken immediately.
Definition: Logger.php:72
const INFO
Interesting events.
Definition: Logger.php:39

◆ setUp()

Monolog\Handler\SlackHandlerTest::setUp ( )

Definition at line 34 of file SlackHandlerTest.php.

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

◆ testWriteContent()

Monolog\Handler\SlackHandlerTest::testWriteContent ( )

Definition at line 51 of file SlackHandlerTest.php.

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

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

◆ testWriteContentUsesFormatterIfProvided()

Monolog\Handler\SlackHandlerTest::testWriteContentUsesFormatterIfProvided ( )

Definition at line 61 of file SlackHandlerTest.php.

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

62  {
63  $this->createHandler('myToken', 'channel1', 'Monolog', false);
64  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
65  fseek($this->res, 0);
66  $content = fread($this->res, 1024);
67 
68  $this->createHandler('myToken', 'channel1', 'Monolog', false);
69  $this->handler->setFormatter(new LineFormatter('foo--%message%'));
70  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test2'));
71  fseek($this->res, 0);
72  $content2 = fread($this->res, 1024);
73 
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);
76  }
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
createHandler($token='myToken', $channel='channel1', $username='Monolog', $useAttachment=true, $iconEmoji=null, $useShortAttachment=false, $includeExtra=false)
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

◆ testWriteContentWithColors()

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

provideLevelColors

Definition at line 91 of file SlackHandlerTest.php.

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

92  {
93  $this->createHandler();
94  $this->handler->handle($this->getRecord($level, 'test1'));
95  fseek($this->res, 0);
96  $content = fread($this->res, 1024);
97 
98  $this->assertRegexp('/color%22%3A%22'.$expectedColor.'/', $content);
99  }
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
createHandler($token='myToken', $channel='channel1', $username='Monolog', $useAttachment=true, $iconEmoji=null, $useShortAttachment=false, $includeExtra=false)
+ Here is the call graph for this function:

◆ testWriteContentWithEmoji()

Monolog\Handler\SlackHandlerTest::testWriteContentWithEmoji ( )

Definition at line 78 of file SlackHandlerTest.php.

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

79  {
80  $this->createHandler('myToken', 'channel1', 'Monolog', true, 'alien');
81  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
82  fseek($this->res, 0);
83  $content = fread($this->res, 1024);
84 
85  $this->assertRegexp('/icon_emoji=%3Aalien%3A$/', $content);
86  }
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
createHandler($token='myToken', $channel='channel1', $username='Monolog', $useAttachment=true, $iconEmoji=null, $useShortAttachment=false, $includeExtra=false)
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

◆ testWriteContentWithPlainTextMessage()

Monolog\Handler\SlackHandlerTest::testWriteContentWithPlainTextMessage ( )

Definition at line 101 of file SlackHandlerTest.php.

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

102  {
103  $this->createHandler('myToken', 'channel1', 'Monolog', false);
104  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
105  fseek($this->res, 0);
106  $content = fread($this->res, 1024);
107 
108  $this->assertRegexp('/text=test1/', $content);
109  }
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
createHandler($token='myToken', $channel='channel1', $username='Monolog', $useAttachment=true, $iconEmoji=null, $useShortAttachment=false, $includeExtra=false)
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

◆ testWriteHeader()

Monolog\Handler\SlackHandlerTest::testWriteHeader ( )

Definition at line 41 of file SlackHandlerTest.php.

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

42  {
43  $this->createHandler();
44  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
45  fseek($this->res, 0);
46  $content = fread($this->res, 1024);
47 
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);
49  }
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
createHandler($token='myToken', $channel='channel1', $username='Monolog', $useAttachment=true, $iconEmoji=null, $useShortAttachment=false, $includeExtra=false)
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

Field Documentation

◆ $handler

Monolog\Handler\SlackHandlerTest::$handler
private

Definition at line 32 of file SlackHandlerTest.php.

◆ $res

Monolog\Handler\SlackHandlerTest::$res
private

Definition at line 27 of file SlackHandlerTest.php.


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