ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 129 of file SlackHandlerTest.php.

References PHPMailer\PHPMailer\$token, 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().

130  {
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'),
136  $constructorArgs
137  );
138 
139  $reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString');
140  $reflectionProperty->setAccessible(true);
141  $reflectionProperty->setValue($this->handler, 'localhost:1234');
142 
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));
152 
153  $this->handler->setFormatter($this->getIdentityFormatter());
154  }
const DEBUG
Detailed debug information.
Definition: Logger.php:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ provideLevelColors()

Monolog\Handler\SlackHandlerTest::provideLevelColors ( )

Definition at line 115 of file SlackHandlerTest.php.

References Monolog\Logger\ALERT, Monolog\Handler\Slack\SlackRecord\COLOR_DANGER, Monolog\Handler\Slack\SlackRecord\COLOR_DEFAULT, Monolog\Handler\Slack\SlackRecord\COLOR_GOOD, Monolog\Handler\Slack\SlackRecord\COLOR_WARNING, Monolog\Logger\CRITICAL, Monolog\Logger\DEBUG, Monolog\Logger\EMERGENCY, Monolog\Logger\ERROR, Monolog\Logger\INFO, Monolog\Logger\NOTICE, and Monolog\Logger\WARNING.

116  {
117  return array(
118  array(Logger::DEBUG, urlencode(SlackRecord::COLOR_DEFAULT)),
126  );
127  }
const NOTICE
Uncommon events.
Definition: Logger.php:45
const DEBUG
Detailed debug information.
Definition: Logger.php:33
const ERROR
Runtime errors.
Definition: Logger.php:58
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:53
const EMERGENCY
Urgent alert.
Definition: Logger.php:78
const CRITICAL
Critical conditions.
Definition: Logger.php:65
const ALERT
Action must be taken immediately.
Definition: Logger.php:73
const INFO
Interesting events.
Definition: Logger.php:40

◆ setUp()

Monolog\Handler\SlackHandlerTest::setUp ( )

Definition at line 35 of file SlackHandlerTest.php.

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

◆ testWriteContent()

Monolog\Handler\SlackHandlerTest::testWriteContent ( )

Definition at line 52 of file SlackHandlerTest.php.

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

53  {
54  $this->createHandler();
55  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
56  fseek($this->res, 0);
57  $content = fread($this->res, 1024);
58 
59  $this->assertRegExp('/username=Monolog/', $content);
60  $this->assertRegExp('/channel=channel1/', $content);
61  $this->assertRegExp('/token=myToken/', $content);
62  $this->assertRegExp('/attachments/', $content);
63  }
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:65
+ Here is the call graph for this function:

◆ testWriteContentUsesFormatterIfProvided()

Monolog\Handler\SlackHandlerTest::testWriteContentUsesFormatterIfProvided ( )

Definition at line 65 of file SlackHandlerTest.php.

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

66  {
67  $this->createHandler('myToken', 'channel1', 'Monolog', false);
68  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
69  fseek($this->res, 0);
70  $content = fread($this->res, 1024);
71 
72  $this->createHandler('myToken', 'channel1', 'Monolog', false);
73  $this->handler->setFormatter(new LineFormatter('foo--%message%'));
74  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test2'));
75  fseek($this->res, 0);
76  $content2 = fread($this->res, 1024);
77 
78  $this->assertRegexp('/text=test1/', $content);
79  $this->assertRegexp('/text=foo--test2/', $content2);
80  }
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:65
+ Here is the call graph for this function:

◆ testWriteContentWithColors()

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

provideLevelColors

Definition at line 95 of file SlackHandlerTest.php.

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

96  {
97  $this->createHandler();
98  $this->handler->handle($this->getRecord($level, 'test1'));
99  fseek($this->res, 0);
100  $content = fread($this->res, 1024);
101 
102  $this->assertRegexp('/%22color%22%3A%22'.$expectedColor.'/', $content);
103  }
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 82 of file SlackHandlerTest.php.

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

83  {
84  $this->createHandler('myToken', 'channel1', 'Monolog', true, 'alien');
85  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
86  fseek($this->res, 0);
87  $content = fread($this->res, 1024);
88 
89  $this->assertRegexp('/icon_emoji=%3Aalien%3A/', $content);
90  }
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:65
+ Here is the call graph for this function:

◆ testWriteContentWithPlainTextMessage()

Monolog\Handler\SlackHandlerTest::testWriteContentWithPlainTextMessage ( )

Definition at line 105 of file SlackHandlerTest.php.

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

106  {
107  $this->createHandler('myToken', 'channel1', 'Monolog', false);
108  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
109  fseek($this->res, 0);
110  $content = fread($this->res, 1024);
111 
112  $this->assertRegexp('/text=test1/', $content);
113  }
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:65
+ Here is the call graph for this function:

◆ testWriteHeader()

Monolog\Handler\SlackHandlerTest::testWriteHeader ( )

Definition at line 42 of file SlackHandlerTest.php.

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

43  {
44  $this->createHandler();
45  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
46  fseek($this->res, 0);
47  $content = fread($this->res, 1024);
48 
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);
50  }
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:65
+ Here is the call graph for this function:

Field Documentation

◆ $handler

Monolog\Handler\SlackHandlerTest::$handler
private

Definition at line 33 of file SlackHandlerTest.php.

◆ $res

Monolog\Handler\SlackHandlerTest::$res
private

Definition at line 28 of file SlackHandlerTest.php.


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