scratch – Blame information for rev 120
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
120 | 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\Formatter\FlowdockFormatter; |
||
15 | use Monolog\TestCase; |
||
16 | use Monolog\Logger; |
||
17 | |||
18 | /** |
||
19 | * @author Dominik Liebler <liebler.dominik@gmail.com> |
||
20 | * @see https://www.hipchat.com/docs/api |
||
21 | */ |
||
22 | class FlowdockHandlerTest extends TestCase |
||
23 | { |
||
24 | /** |
||
25 | * @var resource |
||
26 | */ |
||
27 | private $res; |
||
28 | |||
29 | /** |
||
30 | * @var FlowdockHandler |
||
31 | */ |
||
32 | private $handler; |
||
33 | |||
34 | public function setUp() |
||
35 | { |
||
36 | if (!extension_loaded('openssl')) { |
||
37 | $this->markTestSkipped('This test requires openssl to run'); |
||
38 | } |
||
39 | } |
||
40 | |||
41 | public function testWriteHeader() |
||
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 \/v1\/messages\/team_inbox\/.* HTTP\/1.1\\r\\nHost: api.flowdock.com\\r\\nContent-Type: application\/json\\r\\nContent-Length: \d{2,4}\\r\\n\\r\\n/', $content); |
||
49 | |||
50 | return $content; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @depends testWriteHeader |
||
55 | */ |
||
56 | public function testWriteContent($content) |
||
57 | { |
||
58 | $this->assertRegexp('/"source":"test_source"/', $content); |
||
59 | $this->assertRegexp('/"from_address":"source@test\.com"/', $content); |
||
60 | } |
||
61 | |||
62 | private function createHandler($token = 'myToken') |
||
63 | { |
||
64 | $constructorArgs = array($token, Logger::DEBUG); |
||
65 | $this->res = fopen('php://memory', 'a'); |
||
66 | $this->handler = $this->getMock( |
||
67 | '\Monolog\Handler\FlowdockHandler', |
||
68 | array('fsockopen', 'streamSetTimeout', 'closeSocket'), |
||
69 | $constructorArgs |
||
70 | ); |
||
71 | |||
72 | $reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString'); |
||
73 | $reflectionProperty->setAccessible(true); |
||
74 | $reflectionProperty->setValue($this->handler, 'localhost:1234'); |
||
75 | |||
76 | $this->handler->expects($this->any()) |
||
77 | ->method('fsockopen') |
||
78 | ->will($this->returnValue($this->res)); |
||
79 | $this->handler->expects($this->any()) |
||
80 | ->method('streamSetTimeout') |
||
81 | ->will($this->returnValue(true)); |
||
82 | $this->handler->expects($this->any()) |
||
83 | ->method('closeSocket') |
||
84 | ->will($this->returnValue(true)); |
||
85 | |||
86 | $this->handler->setFormatter(new FlowdockFormatter('test_source', 'source@test.com')); |
||
87 | } |
||
88 | } |