ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
LogEntriesHandlerTest.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;
16 
21 {
25  private $res;
26 
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 }
const DEBUG
Detailed debug information.
Definition: Logger.php:32
$records
Definition: simple_test.php:22
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
Create styles array
The data for the language used.
const CRITICAL
Critical conditions.
Definition: Logger.php:64