ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
StreamHandlerTest.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 
18 {
23  public function testWrite()
24  {
25  $handle = fopen('php://memory', 'a+');
26  $handler = new StreamHandler($handle);
27  $handler->setFormatter($this->getIdentityFormatter());
28  $handler->handle($this->getRecord(Logger::WARNING, 'test'));
29  $handler->handle($this->getRecord(Logger::WARNING, 'test2'));
30  $handler->handle($this->getRecord(Logger::WARNING, 'test3'));
31  fseek($handle, 0);
32  $this->assertEquals('testtest2test3', fread($handle, 100));
33  }
34 
39  {
40  $handle = fopen('php://memory', 'a+');
41  $handler = new StreamHandler($handle);
42  $this->assertTrue(is_resource($handle));
43  $handler->close();
44  $this->assertTrue(is_resource($handle));
45  }
46 
50  public function testClose()
51  {
52  $handler = new StreamHandler('php://memory');
53  $handler->handle($this->getRecord(Logger::WARNING, 'test'));
54  $streamProp = new \ReflectionProperty('Monolog\Handler\StreamHandler', 'stream');
55  $streamProp->setAccessible(true);
56  $handle = $streamProp->getValue($handler);
57 
58  $this->assertTrue(is_resource($handle));
59  $handler->close();
60  $this->assertFalse(is_resource($handle));
61  }
62 
67  {
68  $handler = new StreamHandler('php://memory');
69  $handler->handle($this->getRecord());
70  }
71 
76  public function testWriteLocking()
77  {
78  $temp = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'monolog_locked_log';
79  $handler = new StreamHandler($temp, Logger::DEBUG, true, null, true);
80  $handler->handle($this->getRecord());
81  }
82 
88  public function testWriteMissingResource()
89  {
90  $handler = new StreamHandler(null);
91  $handler->handle($this->getRecord());
92  }
93 
94  public function invalidArgumentProvider()
95  {
96  return array(
97  array(1),
98  array(array()),
99  array(array('bogus://url')),
100  );
101  }
102 
108  public function testWriteInvalidArgument($invalidArgument)
109  {
110  $handler = new StreamHandler($invalidArgument);
111  }
112 
118  public function testWriteInvalidResource()
119  {
120  $handler = new StreamHandler('bogus://url');
121  $handler->handle($this->getRecord());
122  }
123 
130  {
131  $handler = new StreamHandler('ftp://foo/bar/baz/'.rand(0, 10000));
132  $handler->handle($this->getRecord());
133  }
134 
139  public function testWriteNonExistingPath()
140  {
141  $handler = new StreamHandler(sys_get_temp_dir().'/bar/'.rand(0, 10000).DIRECTORY_SEPARATOR.rand(0, 10000));
142  $handler->handle($this->getRecord());
143  }
144 
150  {
151  $handler = new StreamHandler('file://'.sys_get_temp_dir().'/bar/'.rand(0, 10000).DIRECTORY_SEPARATOR.rand(0, 10000));
152  $handler->handle($this->getRecord());
153  }
154 
162  {
163  if (defined('PHP_WINDOWS_VERSION_BUILD')) {
164  $this->markTestSkipped('Permissions checks can not run on windows');
165  }
166  $handler = new StreamHandler('/foo/bar/'.rand(0, 10000).DIRECTORY_SEPARATOR.rand(0, 10000));
167  $handler->handle($this->getRecord());
168  }
169 
177  {
178  if (defined('PHP_WINDOWS_VERSION_BUILD')) {
179  $this->markTestSkipped('Permissions checks can not run on windows');
180  }
181  $handler = new StreamHandler('file:///foo/bar/'.rand(0, 10000).DIRECTORY_SEPARATOR.rand(0, 10000));
182  $handler->handle($this->getRecord());
183  }
184 }
testWriteNonExistingAndNotCreatablePath()
Exception /There is no existing directory at/ Monolog::__construct Monolog::write ...
testWriteMissingResource()
LogicException Monolog::__construct Monolog::write
const DEBUG
Detailed debug information.
Definition: Logger.php:32
testWriteNonExistingFileResource()
Monolog::__construct Monolog::write
testWriteNonExistingResource()
UnexpectedValueException Monolog::__construct Monolog::write
testWriteInvalidResource()
UnexpectedValueException Monolog::__construct Monolog::write
testWriteNonExistingPath()
Monolog::__construct Monolog::write
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
testWriteCreatesTheStreamResource()
Monolog::write
testWriteLocking()
Monolog::__construct Monolog::write
testWrite()
Monolog::__construct Monolog::write
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
Create styles array
The data for the language used.
Stores to any stream resource.
testWriteNonExistingAndNotCreatableFileResource()
Exception /There is no existing directory at/ Monolog::__construct Monolog::write ...
testCloseKeepsExternalHandlersOpen()
Monolog::close
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
$handler
testWriteInvalidArgument($invalidArgument)
invalidArgumentProvider InvalidArgumentException Monolog::__construct