ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SlackWebhookHandlerTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Monolog package.
5  *
6  * (c) Jordi Boggiano <j.boggiano@seld.be>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Monolog\Handler;
13 
15 use Monolog\Logger;
18 
25 {
26  const WEBHOOK_URL = 'https://hooks.slack.com/services/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E';
27 
32  public function testConstructorMinimal()
33  {
34  $handler = new SlackWebhookHandler(self::WEBHOOK_URL);
35  $record = $this->getRecord();
36  $slackRecord = $handler->getSlackRecord();
37  $this->assertInstanceOf('Monolog\Handler\Slack\SlackRecord', $slackRecord);
38  $this->assertEquals(array(
39  'attachments' => array(
40  array(
41  'fallback' => 'test',
42  'text' => 'test',
43  'color' => SlackRecord::COLOR_WARNING,
44  'fields' => array(
45  array(
46  'title' => 'Level',
47  'value' => 'WARNING',
48  'short' => false,
49  ),
50  ),
51  'title' => 'Message',
52  'mrkdwn_in' => array('fields'),
53  'ts' => $record['datetime']->getTimestamp(),
54  ),
55  ),
56  ), $slackRecord->getSlackData($record));
57  }
58 
63  public function testConstructorFull()
64  {
66  self::WEBHOOK_URL,
67  'test-channel',
68  'test-username',
69  false,
70  ':ghost:',
71  false,
72  false,
74  false
75  );
76 
77  $slackRecord = $handler->getSlackRecord();
78  $this->assertInstanceOf('Monolog\Handler\Slack\SlackRecord', $slackRecord);
79  $this->assertEquals(array(
80  'username' => 'test-username',
81  'text' => 'test',
82  'channel' => 'test-channel',
83  'icon_emoji' => ':ghost:',
84  ), $slackRecord->getSlackData($this->getRecord()));
85  }
86 
90  public function testGetFormatter()
91  {
92  $handler = new SlackWebhookHandler(self::WEBHOOK_URL);
93  $formatter = $handler->getFormatter();
94  $this->assertInstanceOf('Monolog\Formatter\FormatterInterface', $formatter);
95  }
96 
100  public function testSetFormatter()
101  {
102  $handler = new SlackWebhookHandler(self::WEBHOOK_URL);
103  $formatter = new LineFormatter();
104  $handler->setFormatter($formatter);
105  $this->assertSame($formatter, $handler->getFormatter());
106  }
107 }
testConstructorFull()
::__construct ::getSlackRecord
const DEBUG
Detailed debug information.
Definition: Logger.php:33
Sends notifications through Slack Webhooks.
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
testConstructorMinimal()
::__construct ::getSlackRecord
Formats incoming records into a one-line string.
$handler