ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
FlowdockHandlerTest.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
12namespace Monolog\Handler;
13
17
23{
27 private $res;
28
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
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}
formats the record to be used in the FlowdockHandler
testWriteContent($content)
@depends testWriteHeader
Monolog log channel.
Definition: Logger.php:28
const CRITICAL
Critical conditions.
Definition: Logger.php:64
const DEBUG
Detailed debug information.
Definition: Logger.php:32
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19