ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
38  public function testClose()
39  {
40  $handle = fopen('php://memory', 'a+');
41  $handler = new StreamHandler($handle);
42  $this->assertTrue(is_resource($handle));
43  $handler->close();
44  $this->assertFalse(is_resource($handle));
45  }
46 
51  {
52  $handler = new StreamHandler('php://memory');
53  $handler->handle($this->getRecord());
54  }
55 
60  public function testWriteLocking()
61  {
62  $temp = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'monolog_locked_log';
63  $handler = new StreamHandler($temp, Logger::DEBUG, true, null, true);
64  $handler->handle($this->getRecord());
65  }
66 
72  public function testWriteMissingResource()
73  {
74  $handler = new StreamHandler(null);
75  $handler->handle($this->getRecord());
76  }
77 
78  public function invalidArgumentProvider()
79  {
80  return array(
81  array(1),
82  array(array()),
83  array(array('bogus://url')),
84  );
85  }
86 
92  public function testWriteInvalidArgument($invalidArgument)
93  {
94  $handler = new StreamHandler($invalidArgument);
95  }
96 
102  public function testWriteInvalidResource()
103  {
104  $handler = new StreamHandler('bogus://url');
105  $handler->handle($this->getRecord());
106  }
107 
114  {
115  $handler = new StreamHandler('ftp://foo/bar/baz/'.rand(0, 10000));
116  $handler->handle($this->getRecord());
117  }
118 
123  public function testWriteNonExistingPath()
124  {
125  $handler = new StreamHandler(sys_get_temp_dir().'/bar/'.rand(0, 10000).DIRECTORY_SEPARATOR.rand(0, 10000));
126  $handler->handle($this->getRecord());
127  }
128 
134  {
135  $handler = new StreamHandler('file://'.sys_get_temp_dir().'/bar/'.rand(0, 10000).DIRECTORY_SEPARATOR.rand(0, 10000));
136  $handler->handle($this->getRecord());
137  }
138 
146  {
147  if (defined('PHP_WINDOWS_VERSION_BUILD')) {
148  $this->markTestSkipped('Permissions checks can not run on windows');
149  }
150  $handler = new StreamHandler('/foo/bar/'.rand(0, 10000).DIRECTORY_SEPARATOR.rand(0, 10000));
151  $handler->handle($this->getRecord());
152  }
153 
161  {
162  if (defined('PHP_WINDOWS_VERSION_BUILD')) {
163  $this->markTestSkipped('Permissions checks can not run on windows');
164  }
165  $handler = new StreamHandler('file:///foo/bar/'.rand(0, 10000).DIRECTORY_SEPARATOR.rand(0, 10000));
166  $handler->handle($this->getRecord());
167  }
168 }
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
handle(array $record)
{Handles a record.All records may be passed to this method, and the handler should discard those that...
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
Stores to any stream resource.
testWriteNonExistingAndNotCreatableFileResource()
Exception /There is no existing directory at/ Monolog::__construct Monolog::write ...
testWriteInvalidArgument($invalidArgument)
invalidArgumentProvider InvalidArgumentException Monolog::__construct