ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Monolog\Handler\SocketHandlerTest Class Reference
+ Inheritance diagram for Monolog\Handler\SocketHandlerTest:
+ Collaboration diagram for Monolog\Handler\SocketHandlerTest:

Public Member Functions

 testInvalidHostname ()
 UnexpectedValueException More...
 
 testBadConnectionTimeout ()
 
 testSetConnectionTimeout ()
 
 testBadTimeout ()
 
 testSetTimeout ()
 
 testSetWritingTimeout ()
 
 testSetChunkSize ()
 
 testSetConnectionString ()
 
 testExceptionIsThrownOnFsockopenError ()
 UnexpectedValueException More...
 
 testExceptionIsThrownOnPfsockopenError ()
 UnexpectedValueException More...
 
 testExceptionIsThrownIfCannotSetTimeout ()
 UnexpectedValueException More...
 
 testExceptionIsThrownIfCannotSetChunkSize ()
 UnexpectedValueException More...
 
 testWriteFailsOnIfFwriteReturnsFalse ()
 RuntimeException More...
 
 testWriteFailsIfStreamTimesOut ()
 RuntimeException More...
 
 testWriteFailsOnIncompleteWrite ()
 RuntimeException More...
 
 testWriteWithMemoryFile ()
 
 testWriteWithMock ()
 
 testClose ()
 
 testCloseDoesNotClosePersistentSocket ()
 
 testAvoidInfiniteLoopWhenNoDataIsWrittenForAWritingTimeoutSeconds ()
 

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 296 of file SocketHandlerTest.php.

References Monolog\TestCase\getIdentityFormatter().

Referenced by Monolog\Handler\SocketHandlerTest\testAvoidInfiniteLoopWhenNoDataIsWrittenForAWritingTimeoutSeconds(), Monolog\Handler\SocketHandlerTest\testClose(), Monolog\Handler\SocketHandlerTest\testCloseDoesNotClosePersistentSocket(), Monolog\Handler\SocketHandlerTest\testExceptionIsThrownIfCannotSetChunkSize(), 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().

297  {
298  $this->res = fopen('php://memory', 'a');
299 
300  $defaultMethods = array('fsockopen', 'pfsockopen', 'streamSetTimeout');
301  $newMethods = array_diff($methods, $defaultMethods);
302 
303  $finalMethods = array_merge($defaultMethods, $newMethods);
304 
305  $this->handler = $this->getMock(
306  '\Monolog\Handler\SocketHandler', $finalMethods, array('localhost:1234')
307  );
308 
309  if (!in_array('fsockopen', $methods)) {
310  $this->handler->expects($this->any())
311  ->method('fsockopen')
312  ->will($this->returnValue($this->res));
313  }
314 
315  if (!in_array('pfsockopen', $methods)) {
316  $this->handler->expects($this->any())
317  ->method('pfsockopen')
318  ->will($this->returnValue($this->res));
319  }
320 
321  if (!in_array('streamSetTimeout', $methods)) {
322  $this->handler->expects($this->any())
323  ->method('streamSetTimeout')
324  ->will($this->returnValue(true));
325  }
326 
327  if (!in_array('streamSetChunkSize', $methods)) {
328  $this->handler->expects($this->any())
329  ->method('streamSetChunkSize')
330  ->will($this->returnValue(8192));
331  }
332 
333  $this->handler->setFormatter($this->getIdentityFormatter());
334  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testAvoidInfiniteLoopWhenNoDataIsWrittenForAWritingTimeoutSeconds()

Monolog\Handler\SocketHandlerTest::testAvoidInfiniteLoopWhenNoDataIsWrittenForAWritingTimeoutSeconds ( )

Definition at line 268 of file SocketHandlerTest.php.

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

269  {
270  $this->setMockHandler(array('fwrite', 'streamGetMetadata'));
271 
272  $this->handler->expects($this->any())
273  ->method('fwrite')
274  ->will($this->returnValue(0));
275 
276  $this->handler->expects($this->any())
277  ->method('streamGetMetadata')
278  ->will($this->returnValue(array('timed_out' => false)));
279 
280  $this->handler->setWritingTimeout(1);
281 
282  $this->writeRecord('Hello world');
283  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testBadConnectionTimeout()

Monolog\Handler\SocketHandlerTest::testBadConnectionTimeout ( )

Definition at line 44 of file SocketHandlerTest.php.

References Monolog\Handler\SocketHandlerTest\createHandler().

45  {
46  $this->createHandler('localhost:1234');
47  $this->handler->setConnectionTimeout(-1);
48  }
+ Here is the call graph for this function:

◆ testBadTimeout()

Monolog\Handler\SocketHandlerTest::testBadTimeout ( )

Definition at line 60 of file SocketHandlerTest.php.

References Monolog\Handler\SocketHandlerTest\createHandler().

61  {
62  $this->createHandler('localhost:1234');
63  $this->handler->setTimeout(-1);
64  }
+ Here is the call graph for this function:

◆ testClose()

Monolog\Handler\SocketHandlerTest::testClose ( )

Definition at line 246 of file SocketHandlerTest.php.

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

247  {
248  $this->setMockHandler();
249  $this->writeRecord('Hello world');
250  $this->assertInternalType('resource', $this->res);
251  $this->handler->close();
252  $this->assertFalse(is_resource($this->res), "Expected resource to be closed after closing handler");
253  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testCloseDoesNotClosePersistentSocket()

Monolog\Handler\SocketHandlerTest::testCloseDoesNotClosePersistentSocket ( )

Definition at line 255 of file SocketHandlerTest.php.

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

256  {
257  $this->setMockHandler();
258  $this->handler->setPersistent(true);
259  $this->writeRecord('Hello world');
260  $this->assertTrue(is_resource($this->res));
261  $this->handler->close();
262  $this->assertTrue(is_resource($this->res));
263  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testExceptionIsThrownIfCannotSetChunkSize()

Monolog\Handler\SocketHandlerTest::testExceptionIsThrownIfCannotSetChunkSize ( )

UnexpectedValueException

Definition at line 133 of file SocketHandlerTest.php.

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

134  {
135  $this->setMockHandler(array('streamSetChunkSize'));
136  $this->handler->setChunkSize(8192);
137  $this->handler->expects($this->once())
138  ->method('streamSetChunkSize')
139  ->will($this->returnValue(false));
140  $this->writeRecord('Hello world');
141  }
setMockHandler(array $methods=array())
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testExceptionIsThrownIfCannotSetTimeout()

Monolog\Handler\SocketHandlerTest::testExceptionIsThrownIfCannotSetTimeout ( )

UnexpectedValueException

Definition at line 121 of file SocketHandlerTest.php.

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

122  {
123  $this->setMockHandler(array('streamSetTimeout'));
124  $this->handler->expects($this->once())
125  ->method('streamSetTimeout')
126  ->will($this->returnValue(false));
127  $this->writeRecord('Hello world');
128  }
setMockHandler(array $methods=array())
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testExceptionIsThrownOnFsockopenError()

Monolog\Handler\SocketHandlerTest::testExceptionIsThrownOnFsockopenError ( )

UnexpectedValueException

Definition at line 96 of file SocketHandlerTest.php.

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

97  {
98  $this->setMockHandler(array('fsockopen'));
99  $this->handler->expects($this->once())
100  ->method('fsockopen')
101  ->will($this->returnValue(false));
102  $this->writeRecord('Hello world');
103  }
setMockHandler(array $methods=array())
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testExceptionIsThrownOnPfsockopenError()

Monolog\Handler\SocketHandlerTest::testExceptionIsThrownOnPfsockopenError ( )

UnexpectedValueException

Definition at line 108 of file SocketHandlerTest.php.

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

109  {
110  $this->setMockHandler(array('pfsockopen'));
111  $this->handler->expects($this->once())
112  ->method('pfsockopen')
113  ->will($this->returnValue(false));
114  $this->handler->setPersistent(true);
115  $this->writeRecord('Hello world');
116  }
setMockHandler(array $methods=array())
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testInvalidHostname()

Monolog\Handler\SocketHandlerTest::testInvalidHostname ( )

UnexpectedValueException

Definition at line 35 of file SocketHandlerTest.php.

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

36  {
37  $this->createHandler('garbage://here');
38  $this->writeRecord('data');
39  }
+ Here is the call graph for this function:

◆ testSetChunkSize()

Monolog\Handler\SocketHandlerTest::testSetChunkSize ( )

Definition at line 80 of file SocketHandlerTest.php.

References Monolog\Handler\SocketHandlerTest\createHandler().

81  {
82  $this->createHandler('localhost:1234');
83  $this->handler->setChunkSize(1025);
84  $this->assertEquals(1025, $this->handler->getChunkSize());
85  }
+ Here is the call graph for this function:

◆ testSetConnectionString()

Monolog\Handler\SocketHandlerTest::testSetConnectionString ( )

Definition at line 87 of file SocketHandlerTest.php.

References Monolog\Handler\SocketHandlerTest\createHandler().

88  {
89  $this->createHandler('tcp://localhost:9090');
90  $this->assertEquals('tcp://localhost:9090', $this->handler->getConnectionString());
91  }
+ Here is the call graph for this function:

◆ testSetConnectionTimeout()

Monolog\Handler\SocketHandlerTest::testSetConnectionTimeout ( )

Definition at line 50 of file SocketHandlerTest.php.

References Monolog\Handler\SocketHandlerTest\createHandler().

51  {
52  $this->createHandler('localhost:1234');
53  $this->handler->setConnectionTimeout(10.1);
54  $this->assertEquals(10.1, $this->handler->getConnectionTimeout());
55  }
+ Here is the call graph for this function:

◆ testSetTimeout()

Monolog\Handler\SocketHandlerTest::testSetTimeout ( )

Definition at line 66 of file SocketHandlerTest.php.

References Monolog\Handler\SocketHandlerTest\createHandler().

67  {
68  $this->createHandler('localhost:1234');
69  $this->handler->setTimeout(10.25);
70  $this->assertEquals(10.25, $this->handler->getTimeout());
71  }
+ Here is the call graph for this function:

◆ testSetWritingTimeout()

Monolog\Handler\SocketHandlerTest::testSetWritingTimeout ( )

Definition at line 73 of file SocketHandlerTest.php.

References Monolog\Handler\SocketHandlerTest\createHandler().

74  {
75  $this->createHandler('localhost:1234');
76  $this->handler->setWritingTimeout(10.25);
77  $this->assertEquals(10.25, $this->handler->getWritingTimeout());
78  }
+ Here is the call graph for this function:

◆ testWriteFailsIfStreamTimesOut()

Monolog\Handler\SocketHandlerTest::testWriteFailsIfStreamTimesOut ( )

RuntimeException

Definition at line 169 of file SocketHandlerTest.php.

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

170  {
171  $this->setMockHandler(array('fwrite', 'streamGetMetadata'));
172 
173  $callback = function ($arg) {
174  $map = array(
175  'Hello world' => 6,
176  'world' => 5,
177  );
178 
179  return $map[$arg];
180  };
181 
182  $this->handler->expects($this->exactly(1))
183  ->method('fwrite')
184  ->will($this->returnCallback($callback));
185  $this->handler->expects($this->exactly(1))
186  ->method('streamGetMetadata')
187  ->will($this->returnValue(array('timed_out' => true)));
188 
189  $this->writeRecord('Hello world');
190  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testWriteFailsOnIfFwriteReturnsFalse()

Monolog\Handler\SocketHandlerTest::testWriteFailsOnIfFwriteReturnsFalse ( )

RuntimeException

Definition at line 146 of file SocketHandlerTest.php.

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

147  {
148  $this->setMockHandler(array('fwrite'));
149 
150  $callback = function ($arg) {
151  $map = array(
152  'Hello world' => 6,
153  'world' => false,
154  );
155 
156  return $map[$arg];
157  };
158 
159  $this->handler->expects($this->exactly(2))
160  ->method('fwrite')
161  ->will($this->returnCallback($callback));
162 
163  $this->writeRecord('Hello world');
164  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testWriteFailsOnIncompleteWrite()

Monolog\Handler\SocketHandlerTest::testWriteFailsOnIncompleteWrite ( )

RuntimeException

Definition at line 195 of file SocketHandlerTest.php.

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

196  {
197  $this->setMockHandler(array('fwrite', 'streamGetMetadata'));
198 
199  $res = $this->res;
200  $callback = function ($string) use ($res) {
201  fclose($res);
202 
203  return strlen('Hello');
204  };
205 
206  $this->handler->expects($this->exactly(1))
207  ->method('fwrite')
208  ->will($this->returnCallback($callback));
209  $this->handler->expects($this->exactly(1))
210  ->method('streamGetMetadata')
211  ->will($this->returnValue(array('timed_out' => false)));
212 
213  $this->writeRecord('Hello world');
214  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testWriteWithMemoryFile()

Monolog\Handler\SocketHandlerTest::testWriteWithMemoryFile ( )

Definition at line 216 of file SocketHandlerTest.php.

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

217  {
218  $this->setMockHandler();
219  $this->writeRecord('test1');
220  $this->writeRecord('test2');
221  $this->writeRecord('test3');
222  fseek($this->res, 0);
223  $this->assertEquals('test1test2test3', fread($this->res, 1024));
224  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testWriteWithMock()

Monolog\Handler\SocketHandlerTest::testWriteWithMock ( )

Definition at line 226 of file SocketHandlerTest.php.

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

227  {
228  $this->setMockHandler(array('fwrite'));
229 
230  $callback = function ($arg) {
231  $map = array(
232  'Hello world' => 6,
233  'world' => 5,
234  );
235 
236  return $map[$arg];
237  };
238 
239  $this->handler->expects($this->exactly(2))
240  ->method('fwrite')
241  ->will($this->returnCallback($callback));
242 
243  $this->writeRecord('Hello world');
244  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ writeRecord()

Monolog\Handler\SocketHandlerTest::writeRecord (   $string)
private

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: