scratch – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
115 | office | 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 | |||
14 | use Monolog\TestCase; |
||
15 | use Monolog\Logger; |
||
16 | use Monolog\Formatter\LineFormatter; |
||
17 | use Monolog\Handler\Slack\SlackRecord; |
||
18 | |||
19 | /** |
||
20 | * @author Haralan Dobrev <hkdobrev@gmail.com> |
||
21 | * @see https://api.slack.com/incoming-webhooks |
||
22 | * @coversDefaultClass Monolog\Handler\SlackWebhookHandler |
||
23 | */ |
||
24 | class SlackWebhookHandlerTest extends TestCase |
||
25 | { |
||
26 | const WEBHOOK_URL = 'https://hooks.slack.com/services/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E'; |
||
27 | |||
28 | /** |
||
29 | * @covers ::__construct |
||
30 | * @covers ::getSlackRecord |
||
31 | */ |
||
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 | |||
59 | /** |
||
60 | * @covers ::__construct |
||
61 | * @covers ::getSlackRecord |
||
62 | */ |
||
63 | public function testConstructorFull() |
||
64 | { |
||
65 | $handler = new SlackWebhookHandler( |
||
66 | self::WEBHOOK_URL, |
||
67 | 'test-channel', |
||
68 | 'test-username', |
||
69 | false, |
||
70 | ':ghost:', |
||
71 | false, |
||
72 | false, |
||
73 | Logger::DEBUG, |
||
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 | |||
87 | /** |
||
88 | * @covers ::getFormatter |
||
89 | */ |
||
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 | |||
97 | /** |
||
98 | * @covers ::setFormatter |
||
99 | */ |
||
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 | } |