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 | |||
17 | /** |
||
18 | * @author Robert Kaufmann III <rok3@rok3.me> |
||
19 | */ |
||
20 | class LogEntriesHandlerTest extends TestCase |
||
21 | { |
||
22 | /** |
||
23 | * @var resource |
||
24 | */ |
||
25 | private $res; |
||
26 | |||
27 | /** |
||
28 | * @var LogEntriesHandler |
||
29 | */ |
||
30 | private $handler; |
||
31 | |||
32 | public function testWriteContent() |
||
33 | { |
||
34 | $this->createHandler(); |
||
35 | $this->handler->handle($this->getRecord(Logger::CRITICAL, 'Critical write test')); |
||
36 | |||
37 | fseek($this->res, 0); |
||
38 | $content = fread($this->res, 1024); |
||
39 | |||
40 | $this->assertRegexp('/testToken \[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\] test.CRITICAL: Critical write test/', $content); |
||
41 | } |
||
42 | |||
43 | public function testWriteBatchContent() |
||
44 | { |
||
45 | $records = array( |
||
46 | $this->getRecord(), |
||
47 | $this->getRecord(), |
||
48 | $this->getRecord(), |
||
49 | ); |
||
50 | $this->createHandler(); |
||
51 | $this->handler->handleBatch($records); |
||
52 | |||
53 | fseek($this->res, 0); |
||
54 | $content = fread($this->res, 1024); |
||
55 | |||
56 | $this->assertRegexp('/(testToken \[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\] .* \[\] \[\]\n){3}/', $content); |
||
57 | } |
||
58 | |||
59 | private function createHandler() |
||
60 | { |
||
61 | $useSSL = extension_loaded('openssl'); |
||
62 | $args = array('testToken', $useSSL, Logger::DEBUG, true); |
||
63 | $this->res = fopen('php://memory', 'a'); |
||
64 | $this->handler = $this->getMock( |
||
65 | '\Monolog\Handler\LogEntriesHandler', |
||
66 | array('fsockopen', 'streamSetTimeout', 'closeSocket'), |
||
67 | $args |
||
68 | ); |
||
69 | |||
70 | $reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString'); |
||
71 | $reflectionProperty->setAccessible(true); |
||
72 | $reflectionProperty->setValue($this->handler, 'localhost:1234'); |
||
73 | |||
74 | $this->handler->expects($this->any()) |
||
75 | ->method('fsockopen') |
||
76 | ->will($this->returnValue($this->res)); |
||
77 | $this->handler->expects($this->any()) |
||
78 | ->method('streamSetTimeout') |
||
79 | ->will($this->returnValue(true)); |
||
80 | $this->handler->expects($this->any()) |
||
81 | ->method('closeSocket') |
||
82 | ->will($this->returnValue(true)); |
||
83 | } |
||
84 | } |