ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
12namespace Monolog\Handler;
13
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}
An exception for terminatinating execution or to throw for unit testing.
testWriteMissingResource()
@expectedException LogicException @covers Monolog\Handler\StreamHandler::__construct @covers Monolog\...
testClose()
@covers Monolog\Handler\StreamHandler::close
testWrite()
@covers Monolog\Handler\StreamHandler::__construct @covers Monolog\Handler\StreamHandler::write
testWriteInvalidArgument($invalidArgument)
@dataProvider invalidArgumentProvider @expectedException InvalidArgumentException @covers Monolog\Han...
testWriteNonExistingAndNotCreatableFileResource()
@expectedException Exception @expectedExceptionMessageRegExp /There is no existing directory at/ @cov...
testWriteLocking()
@covers Monolog\Handler\StreamHandler::__construct @covers Monolog\Handler\StreamHandler::write
testWriteNonExistingPath()
@covers Monolog\Handler\StreamHandler::__construct @covers Monolog\Handler\StreamHandler::write
testWriteNonExistingAndNotCreatablePath()
@expectedException Exception @expectedExceptionMessageRegExp /There is no existing directory at/ @cov...
testCloseKeepsExternalHandlersOpen()
@covers Monolog\Handler\StreamHandler::close
testWriteNonExistingFileResource()
@covers Monolog\Handler\StreamHandler::__construct @covers Monolog\Handler\StreamHandler::write
testWriteNonExistingResource()
@expectedException UnexpectedValueException @covers Monolog\Handler\StreamHandler::__construct @cover...
testWriteCreatesTheStreamResource()
@covers Monolog\Handler\StreamHandler::write
testWriteInvalidResource()
@expectedException UnexpectedValueException @covers Monolog\Handler\StreamHandler::__construct @cover...
Stores to any stream resource.
Monolog log channel.
Definition: Logger.php:28
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
const DEBUG
Detailed debug information.
Definition: Logger.php:32
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27