ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Monolog\Handler\SocketHandlerTest Class Reference
+ Inheritance diagram for Monolog\Handler\SocketHandlerTest:
+ Collaboration diagram for Monolog\Handler\SocketHandlerTest:

Public Member Functions

 testInvalidHostname ()
 @expectedException UnexpectedValueException More...
 
 testBadConnectionTimeout ()
 @expectedException \InvalidArgumentException More...
 
 testSetConnectionTimeout ()
 
 testBadTimeout ()
 @expectedException \InvalidArgumentException More...
 
 testSetTimeout ()
 
 testSetConnectionString ()
 
 testExceptionIsThrownOnFsockopenError ()
 @expectedException UnexpectedValueException More...
 
 testExceptionIsThrownOnPfsockopenError ()
 @expectedException UnexpectedValueException More...
 
 testExceptionIsThrownIfCannotSetTimeout ()
 @expectedException UnexpectedValueException More...
 
 testWriteFailsOnIfFwriteReturnsFalse ()
 @expectedException RuntimeException More...
 
 testWriteFailsIfStreamTimesOut ()
 @expectedException RuntimeException More...
 
 testWriteFailsOnIncompleteWrite ()
 @expectedException RuntimeException More...
 
 testWriteWithMemoryFile ()
 
 testWriteWithMock ()
 
 testClose ()
 
 testCloseDoesNotClosePersistentSocket ()
 

Private Member Functions

 createHandler ($connectionString)
 
 writeRecord ($string)
 
 setMockHandler (array $methods=array())
 

Private Attributes

 $handler
 
 $res
 

Additional Inherited Members

- Protected Member Functions inherited from Monolog\TestCase
 getRecord ($level=Logger::WARNING, $message='test', $context=array())
 
 getMultipleRecords ()
 
 getIdentityFormatter ()
 

Detailed Description

Author
Pablo de Leon Belloc pablo.nosp@m.lb@g.nosp@m.mail..nosp@m.com

Definition at line 20 of file SocketHandlerTest.php.

Member Function Documentation

◆ createHandler()

Monolog\Handler\SocketHandlerTest::createHandler (   $connectionString)
private

◆ setMockHandler()

Monolog\Handler\SocketHandlerTest::setMockHandler ( array  $methods = array())
private

Definition at line 249 of file SocketHandlerTest.php.

250 {
251 $this->res = fopen('php://memory', 'a');
252
253 $defaultMethods = array('fsockopen', 'pfsockopen', 'streamSetTimeout');
254 $newMethods = array_diff($methods, $defaultMethods);
255
256 $finalMethods = array_merge($defaultMethods, $newMethods);
257
258 $this->handler = $this->getMock(
259 '\Monolog\Handler\SocketHandler', $finalMethods, array('localhost:1234')
260 );
261
262 if (!in_array('fsockopen', $methods)) {
263 $this->handler->expects($this->any())
264 ->method('fsockopen')
265 ->will($this->returnValue($this->res));
266 }
267
268 if (!in_array('pfsockopen', $methods)) {
269 $this->handler->expects($this->any())
270 ->method('pfsockopen')
271 ->will($this->returnValue($this->res));
272 }
273
274 if (!in_array('streamSetTimeout', $methods)) {
275 $this->handler->expects($this->any())
276 ->method('streamSetTimeout')
277 ->will($this->returnValue(true));
278 }
279
280 $this->handler->setFormatter($this->getIdentityFormatter());
281 }

References Monolog\TestCase\getIdentityFormatter().

Referenced by Monolog\Handler\SocketHandlerTest\testClose(), Monolog\Handler\SocketHandlerTest\testCloseDoesNotClosePersistentSocket(), Monolog\Handler\SocketHandlerTest\testExceptionIsThrownIfCannotSetTimeout(), Monolog\Handler\SocketHandlerTest\testExceptionIsThrownOnFsockopenError(), Monolog\Handler\SocketHandlerTest\testExceptionIsThrownOnPfsockopenError(), Monolog\Handler\SocketHandlerTest\testWriteFailsIfStreamTimesOut(), Monolog\Handler\SocketHandlerTest\testWriteFailsOnIfFwriteReturnsFalse(), Monolog\Handler\SocketHandlerTest\testWriteFailsOnIncompleteWrite(), Monolog\Handler\SocketHandlerTest\testWriteWithMemoryFile(), and Monolog\Handler\SocketHandlerTest\testWriteWithMock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testBadConnectionTimeout()

Monolog\Handler\SocketHandlerTest::testBadConnectionTimeout ( )

@expectedException \InvalidArgumentException

Definition at line 44 of file SocketHandlerTest.php.

45 {
46 $this->createHandler('localhost:1234');
47 $this->handler->setConnectionTimeout(-1);
48 }

References Monolog\Handler\SocketHandlerTest\createHandler().

+ Here is the call graph for this function:

◆ testBadTimeout()

Monolog\Handler\SocketHandlerTest::testBadTimeout ( )

@expectedException \InvalidArgumentException

Definition at line 60 of file SocketHandlerTest.php.

61 {
62 $this->createHandler('localhost:1234');
63 $this->handler->setTimeout(-1);
64 }

References Monolog\Handler\SocketHandlerTest\createHandler().

+ Here is the call graph for this function:

◆ testClose()

Monolog\Handler\SocketHandlerTest::testClose ( )

Definition at line 219 of file SocketHandlerTest.php.

220 {
221 $this->setMockHandler();
222 $this->writeRecord('Hello world');
223 $this->assertInternalType('resource', $this->res);
224 $this->handler->close();
225 $this->assertFalse(is_resource($this->res), "Expected resource to be closed after closing handler");
226 }
setMockHandler(array $methods=array())

References Monolog\Handler\SocketHandlerTest\setMockHandler(), and Monolog\Handler\SocketHandlerTest\writeRecord().

+ Here is the call graph for this function:

◆ testCloseDoesNotClosePersistentSocket()

Monolog\Handler\SocketHandlerTest::testCloseDoesNotClosePersistentSocket ( )

Definition at line 228 of file SocketHandlerTest.php.

229 {
230 $this->setMockHandler();
231 $this->handler->setPersistent(true);
232 $this->writeRecord('Hello world');
233 $this->assertTrue(is_resource($this->res));
234 $this->handler->close();
235 $this->assertTrue(is_resource($this->res));
236 }

References Monolog\Handler\SocketHandlerTest\setMockHandler(), and Monolog\Handler\SocketHandlerTest\writeRecord().

+ Here is the call graph for this function:

◆ testExceptionIsThrownIfCannotSetTimeout()

Monolog\Handler\SocketHandlerTest::testExceptionIsThrownIfCannotSetTimeout ( )

@expectedException UnexpectedValueException

Definition at line 107 of file SocketHandlerTest.php.

108 {
109 $this->setMockHandler(array('streamSetTimeout'));
110 $this->handler->expects($this->once())
111 ->method('streamSetTimeout')
112 ->will($this->returnValue(false));
113 $this->writeRecord('Hello world');
114 }

References Monolog\Handler\SocketHandlerTest\setMockHandler(), and Monolog\Handler\SocketHandlerTest\writeRecord().

+ Here is the call graph for this function:

◆ testExceptionIsThrownOnFsockopenError()

Monolog\Handler\SocketHandlerTest::testExceptionIsThrownOnFsockopenError ( )

@expectedException UnexpectedValueException

Definition at line 82 of file SocketHandlerTest.php.

83 {
84 $this->setMockHandler(array('fsockopen'));
85 $this->handler->expects($this->once())
86 ->method('fsockopen')
87 ->will($this->returnValue(false));
88 $this->writeRecord('Hello world');
89 }

References Monolog\Handler\SocketHandlerTest\setMockHandler(), and Monolog\Handler\SocketHandlerTest\writeRecord().

+ Here is the call graph for this function:

◆ testExceptionIsThrownOnPfsockopenError()

Monolog\Handler\SocketHandlerTest::testExceptionIsThrownOnPfsockopenError ( )

@expectedException UnexpectedValueException

Definition at line 94 of file SocketHandlerTest.php.

95 {
96 $this->setMockHandler(array('pfsockopen'));
97 $this->handler->expects($this->once())
98 ->method('pfsockopen')
99 ->will($this->returnValue(false));
100 $this->handler->setPersistent(true);
101 $this->writeRecord('Hello world');
102 }

References Monolog\Handler\SocketHandlerTest\setMockHandler(), and Monolog\Handler\SocketHandlerTest\writeRecord().

+ Here is the call graph for this function:

◆ testInvalidHostname()

Monolog\Handler\SocketHandlerTest::testInvalidHostname ( )

@expectedException UnexpectedValueException

Definition at line 35 of file SocketHandlerTest.php.

36 {
37 $this->createHandler('garbage://here');
38 $this->writeRecord('data');
39 }

References Monolog\Handler\SocketHandlerTest\createHandler(), and Monolog\Handler\SocketHandlerTest\writeRecord().

+ Here is the call graph for this function:

◆ testSetConnectionString()

Monolog\Handler\SocketHandlerTest::testSetConnectionString ( )

Definition at line 73 of file SocketHandlerTest.php.

74 {
75 $this->createHandler('tcp://localhost:9090');
76 $this->assertEquals('tcp://localhost:9090', $this->handler->getConnectionString());
77 }

References Monolog\Handler\SocketHandlerTest\createHandler().

+ Here is the call graph for this function:

◆ testSetConnectionTimeout()

Monolog\Handler\SocketHandlerTest::testSetConnectionTimeout ( )

Definition at line 50 of file SocketHandlerTest.php.

51 {
52 $this->createHandler('localhost:1234');
53 $this->handler->setConnectionTimeout(10.1);
54 $this->assertEquals(10.1, $this->handler->getConnectionTimeout());
55 }

References Monolog\Handler\SocketHandlerTest\createHandler().

+ Here is the call graph for this function:

◆ testSetTimeout()

Monolog\Handler\SocketHandlerTest::testSetTimeout ( )

Definition at line 66 of file SocketHandlerTest.php.

67 {
68 $this->createHandler('localhost:1234');
69 $this->handler->setTimeout(10.25);
70 $this->assertEquals(10.25, $this->handler->getTimeout());
71 }

References Monolog\Handler\SocketHandlerTest\createHandler().

+ Here is the call graph for this function:

◆ testWriteFailsIfStreamTimesOut()

Monolog\Handler\SocketHandlerTest::testWriteFailsIfStreamTimesOut ( )

@expectedException RuntimeException

Definition at line 142 of file SocketHandlerTest.php.

143 {
144 $this->setMockHandler(array('fwrite', 'streamGetMetadata'));
145
146 $callback = function ($arg) {
147 $map = array(
148 'Hello world' => 6,
149 'world' => 5,
150 );
151
152 return $map[$arg];
153 };
154
155 $this->handler->expects($this->exactly(1))
156 ->method('fwrite')
157 ->will($this->returnCallback($callback));
158 $this->handler->expects($this->exactly(1))
159 ->method('streamGetMetadata')
160 ->will($this->returnValue(array('timed_out' => true)));
161
162 $this->writeRecord('Hello world');
163 }

References Monolog\Handler\SocketHandlerTest\setMockHandler(), and Monolog\Handler\SocketHandlerTest\writeRecord().

+ Here is the call graph for this function:

◆ testWriteFailsOnIfFwriteReturnsFalse()

Monolog\Handler\SocketHandlerTest::testWriteFailsOnIfFwriteReturnsFalse ( )

@expectedException RuntimeException

Definition at line 119 of file SocketHandlerTest.php.

120 {
121 $this->setMockHandler(array('fwrite'));
122
123 $callback = function ($arg) {
124 $map = array(
125 'Hello world' => 6,
126 'world' => false,
127 );
128
129 return $map[$arg];
130 };
131
132 $this->handler->expects($this->exactly(2))
133 ->method('fwrite')
134 ->will($this->returnCallback($callback));
135
136 $this->writeRecord('Hello world');
137 }

References Monolog\Handler\SocketHandlerTest\setMockHandler(), and Monolog\Handler\SocketHandlerTest\writeRecord().

+ Here is the call graph for this function:

◆ testWriteFailsOnIncompleteWrite()

Monolog\Handler\SocketHandlerTest::testWriteFailsOnIncompleteWrite ( )

@expectedException RuntimeException

Definition at line 168 of file SocketHandlerTest.php.

169 {
170 $this->setMockHandler(array('fwrite', 'streamGetMetadata'));
171
173 $callback = function ($string) use ($res) {
174 fclose($res);
175
176 return strlen('Hello');
177 };
178
179 $this->handler->expects($this->exactly(1))
180 ->method('fwrite')
181 ->will($this->returnCallback($callback));
182 $this->handler->expects($this->exactly(1))
183 ->method('streamGetMetadata')
184 ->will($this->returnValue(array('timed_out' => false)));
185
186 $this->writeRecord('Hello world');
187 }

References Monolog\Handler\SocketHandlerTest\$res, Monolog\Handler\SocketHandlerTest\setMockHandler(), and Monolog\Handler\SocketHandlerTest\writeRecord().

+ Here is the call graph for this function:

◆ testWriteWithMemoryFile()

Monolog\Handler\SocketHandlerTest::testWriteWithMemoryFile ( )

Definition at line 189 of file SocketHandlerTest.php.

190 {
191 $this->setMockHandler();
192 $this->writeRecord('test1');
193 $this->writeRecord('test2');
194 $this->writeRecord('test3');
195 fseek($this->res, 0);
196 $this->assertEquals('test1test2test3', fread($this->res, 1024));
197 }

References Monolog\Handler\SocketHandlerTest\setMockHandler(), and Monolog\Handler\SocketHandlerTest\writeRecord().

+ Here is the call graph for this function:

◆ testWriteWithMock()

Monolog\Handler\SocketHandlerTest::testWriteWithMock ( )

Definition at line 199 of file SocketHandlerTest.php.

200 {
201 $this->setMockHandler(array('fwrite'));
202
203 $callback = function ($arg) {
204 $map = array(
205 'Hello world' => 6,
206 'world' => 5,
207 );
208
209 return $map[$arg];
210 };
211
212 $this->handler->expects($this->exactly(2))
213 ->method('fwrite')
214 ->will($this->returnCallback($callback));
215
216 $this->writeRecord('Hello world');
217 }

References Monolog\Handler\SocketHandlerTest\setMockHandler(), and Monolog\Handler\SocketHandlerTest\writeRecord().

+ Here is the call graph for this function:

◆ writeRecord()

Field Documentation

◆ $handler

Monolog\Handler\SocketHandlerTest::$handler
private

Definition at line 25 of file SocketHandlerTest.php.

◆ $res

Monolog\Handler\SocketHandlerTest::$res
private

The documentation for this class was generated from the following file: