ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 ()
 
 testSetConnectionString ()
 
 testExceptionIsThrownOnFsockopenError ()
 UnexpectedValueException More...
 
 testExceptionIsThrownOnPfsockopenError ()
 UnexpectedValueException More...
 
 testExceptionIsThrownIfCannotSetTimeout ()
 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 276 of file SocketHandlerTest.php.

References array, and Monolog\TestCase\getIdentityFormatter().

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

277  {
278  $this->res = fopen('php://memory', 'a');
279 
280  $defaultMethods = array('fsockopen', 'pfsockopen', 'streamSetTimeout');
281  $newMethods = array_diff($methods, $defaultMethods);
282 
283  $finalMethods = array_merge($defaultMethods, $newMethods);
284 
285  $this->handler = $this->getMock(
286  '\Monolog\Handler\SocketHandler', $finalMethods, array('localhost:1234')
287  );
288 
289  if (!in_array('fsockopen', $methods)) {
290  $this->handler->expects($this->any())
291  ->method('fsockopen')
292  ->will($this->returnValue($this->res));
293  }
294 
295  if (!in_array('pfsockopen', $methods)) {
296  $this->handler->expects($this->any())
297  ->method('pfsockopen')
298  ->will($this->returnValue($this->res));
299  }
300 
301  if (!in_array('streamSetTimeout', $methods)) {
302  $this->handler->expects($this->any())
303  ->method('streamSetTimeout')
304  ->will($this->returnValue(true));
305  }
306 
307  $this->handler->setFormatter($this->getIdentityFormatter());
308  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testAvoidInfiniteLoopWhenNoDataIsWrittenForAWritingTimeoutSeconds()

Monolog\Handler\SocketHandlerTest::testAvoidInfiniteLoopWhenNoDataIsWrittenForAWritingTimeoutSeconds ( )

Definition at line 248 of file SocketHandlerTest.php.

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

249  {
250  $this->setMockHandler(array('fwrite', 'streamGetMetadata'));
251 
252  $this->handler->expects($this->any())
253  ->method('fwrite')
254  ->will($this->returnValue(0));
255 
256  $this->handler->expects($this->any())
257  ->method('streamGetMetadata')
258  ->will($this->returnValue(array('timed_out' => false)));
259 
260  $this->handler->setWritingTimeout(1);
261 
262  $this->writeRecord('Hello world');
263  }
setMockHandler(array $methods=array())
Create styles array
The data for the language used.
+ 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 226 of file SocketHandlerTest.php.

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

227  {
228  $this->setMockHandler();
229  $this->writeRecord('Hello world');
230  $this->assertInternalType('resource', $this->res);
231  $this->handler->close();
232  $this->assertFalse(is_resource($this->res), "Expected resource to be closed after closing handler");
233  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testCloseDoesNotClosePersistentSocket()

Monolog\Handler\SocketHandlerTest::testCloseDoesNotClosePersistentSocket ( )

Definition at line 235 of file SocketHandlerTest.php.

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

236  {
237  $this->setMockHandler();
238  $this->handler->setPersistent(true);
239  $this->writeRecord('Hello world');
240  $this->assertTrue(is_resource($this->res));
241  $this->handler->close();
242  $this->assertTrue(is_resource($this->res));
243  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testExceptionIsThrownIfCannotSetTimeout()

Monolog\Handler\SocketHandlerTest::testExceptionIsThrownIfCannotSetTimeout ( )

UnexpectedValueException

Definition at line 114 of file SocketHandlerTest.php.

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

115  {
116  $this->setMockHandler(array('streamSetTimeout'));
117  $this->handler->expects($this->once())
118  ->method('streamSetTimeout')
119  ->will($this->returnValue(false));
120  $this->writeRecord('Hello world');
121  }
setMockHandler(array $methods=array())
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ testExceptionIsThrownOnFsockopenError()

Monolog\Handler\SocketHandlerTest::testExceptionIsThrownOnFsockopenError ( )

UnexpectedValueException

Definition at line 89 of file SocketHandlerTest.php.

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

90  {
91  $this->setMockHandler(array('fsockopen'));
92  $this->handler->expects($this->once())
93  ->method('fsockopen')
94  ->will($this->returnValue(false));
95  $this->writeRecord('Hello world');
96  }
setMockHandler(array $methods=array())
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ testExceptionIsThrownOnPfsockopenError()

Monolog\Handler\SocketHandlerTest::testExceptionIsThrownOnPfsockopenError ( )

UnexpectedValueException

Definition at line 101 of file SocketHandlerTest.php.

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

102  {
103  $this->setMockHandler(array('pfsockopen'));
104  $this->handler->expects($this->once())
105  ->method('pfsockopen')
106  ->will($this->returnValue(false));
107  $this->handler->setPersistent(true);
108  $this->writeRecord('Hello world');
109  }
setMockHandler(array $methods=array())
Create styles array
The data for the language used.
+ 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:

◆ testSetConnectionString()

Monolog\Handler\SocketHandlerTest::testSetConnectionString ( )

Definition at line 80 of file SocketHandlerTest.php.

References Monolog\Handler\SocketHandlerTest\createHandler().

81  {
82  $this->createHandler('tcp://localhost:9090');
83  $this->assertEquals('tcp://localhost:9090', $this->handler->getConnectionString());
84  }
+ 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 149 of file SocketHandlerTest.php.

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

150  {
151  $this->setMockHandler(array('fwrite', 'streamGetMetadata'));
152 
153  $callback = function ($arg) {
154  $map = array(
155  'Hello world' => 6,
156  'world' => 5,
157  );
158 
159  return $map[$arg];
160  };
161 
162  $this->handler->expects($this->exactly(1))
163  ->method('fwrite')
164  ->will($this->returnCallback($callback));
165  $this->handler->expects($this->exactly(1))
166  ->method('streamGetMetadata')
167  ->will($this->returnValue(array('timed_out' => true)));
168 
169  $this->writeRecord('Hello world');
170  }
setMockHandler(array $methods=array())
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ testWriteFailsOnIfFwriteReturnsFalse()

Monolog\Handler\SocketHandlerTest::testWriteFailsOnIfFwriteReturnsFalse ( )

RuntimeException

Definition at line 126 of file SocketHandlerTest.php.

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

127  {
128  $this->setMockHandler(array('fwrite'));
129 
130  $callback = function ($arg) {
131  $map = array(
132  'Hello world' => 6,
133  'world' => false,
134  );
135 
136  return $map[$arg];
137  };
138 
139  $this->handler->expects($this->exactly(2))
140  ->method('fwrite')
141  ->will($this->returnCallback($callback));
142 
143  $this->writeRecord('Hello world');
144  }
setMockHandler(array $methods=array())
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ testWriteFailsOnIncompleteWrite()

Monolog\Handler\SocketHandlerTest::testWriteFailsOnIncompleteWrite ( )

RuntimeException

Definition at line 175 of file SocketHandlerTest.php.

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

176  {
177  $this->setMockHandler(array('fwrite', 'streamGetMetadata'));
178 
179  $res = $this->res;
180  $callback = function ($string) use ($res) {
181  fclose($res);
182 
183  return strlen('Hello');
184  };
185 
186  $this->handler->expects($this->exactly(1))
187  ->method('fwrite')
188  ->will($this->returnCallback($callback));
189  $this->handler->expects($this->exactly(1))
190  ->method('streamGetMetadata')
191  ->will($this->returnValue(array('timed_out' => false)));
192 
193  $this->writeRecord('Hello world');
194  }
setMockHandler(array $methods=array())
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ testWriteWithMemoryFile()

Monolog\Handler\SocketHandlerTest::testWriteWithMemoryFile ( )

Definition at line 196 of file SocketHandlerTest.php.

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

197  {
198  $this->setMockHandler();
199  $this->writeRecord('test1');
200  $this->writeRecord('test2');
201  $this->writeRecord('test3');
202  fseek($this->res, 0);
203  $this->assertEquals('test1test2test3', fread($this->res, 1024));
204  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testWriteWithMock()

Monolog\Handler\SocketHandlerTest::testWriteWithMock ( )

Definition at line 206 of file SocketHandlerTest.php.

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

207  {
208  $this->setMockHandler(array('fwrite'));
209 
210  $callback = function ($arg) {
211  $map = array(
212  'Hello world' => 6,
213  'world' => 5,
214  );
215 
216  return $map[$arg];
217  };
218 
219  $this->handler->expects($this->exactly(2))
220  ->method('fwrite')
221  ->will($this->returnCallback($callback));
222 
223  $this->writeRecord('Hello world');
224  }
setMockHandler(array $methods=array())
Create styles array
The data for the language used.
+ 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: