ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
InsightOpsHandlerTest.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 
14  use Monolog\TestCase;
15  use Monolog\Logger;
16 
22 {
26  private $resource;
27 
31  private $handler;
32 
33  public function testWriteContent()
34  {
35  $this->createHandler();
36  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'Critical write test'));
37 
38  fseek($this->resource, 0);
39  $content = fread($this->resource, 1024);
40 
41  $this->assertRegexp('/testToken \[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\] test.CRITICAL: Critical write test/', $content);
42  }
43 
44  public function testWriteBatchContent()
45  {
46  $this->createHandler();
47  $this->handler->handleBatch($this->getMultipleRecords());
48 
49  fseek($this->resource, 0);
50  $content = fread($this->resource, 1024);
51 
52  $this->assertRegexp('/(testToken \[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\] .* \[\] \[\]\n){3}/', $content);
53  }
54 
55  private function createHandler()
56  {
57  $useSSL = extension_loaded('openssl');
58  $args = array('testToken', 'us', $useSSL, Logger::DEBUG, true);
59  $this->resource = fopen('php://memory', 'a');
60  $this->handler = $this->getMock(
61  '\Monolog\Handler\InsightOpsHandler',
62  array('fsockopen', 'streamSetTimeout', 'closeSocket'),
63  $args
64  );
65 
66  $reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString');
67  $reflectionProperty->setAccessible(true);
68  $reflectionProperty->setValue($this->handler, 'localhost:1234');
69 
70  $this->handler->expects($this->any())
71  ->method('fsockopen')
72  ->will($this->returnValue($this->resource));
73  $this->handler->expects($this->any())
74  ->method('streamSetTimeout')
75  ->will($this->returnValue(true));
76  $this->handler->expects($this->any())
77  ->method('closeSocket')
78  ->will($this->returnValue(true));
79  }
80 }
const DEBUG
Detailed debug information.
Definition: Logger.php:33
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const CRITICAL
Critical conditions.
Definition: Logger.php:65