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 ()
 UnexpectedValueException More...
 
 testBadConnectionTimeout ()
 
 testSetConnectionTimeout ()
 
 testBadTimeout ()
 
 testSetTimeout ()
 
 testSetConnectionString ()
 
 testExceptionIsThrownOnFsockopenError ()
 UnexpectedValueException More...
 
 testExceptionIsThrownOnPfsockopenError ()
 UnexpectedValueException More...
 
 testExceptionIsThrownIfCannotSetTimeout ()
 UnexpectedValueException More...
 
 testWriteFailsOnIfFwriteReturnsFalse ()
 RuntimeException More...
 
 testWriteFailsIfStreamTimesOut ()
 RuntimeException More...
 
 testWriteFailsOnIncompleteWrite ()
 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

Definition at line 238 of file SocketHandlerTest.php.

References Monolog\TestCase\getIdentityFormatter().

Referenced by Monolog\Handler\SocketHandlerTest\testBadConnectionTimeout(), Monolog\Handler\SocketHandlerTest\testBadTimeout(), Monolog\Handler\SocketHandlerTest\testInvalidHostname(), Monolog\Handler\SocketHandlerTest\testSetConnectionString(), Monolog\Handler\SocketHandlerTest\testSetConnectionTimeout(), and Monolog\Handler\SocketHandlerTest\testSetTimeout().

239  {
240  $this->handler = new SocketHandler($connectionString);
241  $this->handler->setFormatter($this->getIdentityFormatter());
242  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setMockHandler()

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

Definition at line 249 of file SocketHandlerTest.php.

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().

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  }
+ Here is the call graph for this function:
+ Here is the caller 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 219 of file SocketHandlerTest.php.

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

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())
+ Here is the call graph for this function:

◆ testCloseDoesNotClosePersistentSocket()

Monolog\Handler\SocketHandlerTest::testCloseDoesNotClosePersistentSocket ( )

Definition at line 228 of file SocketHandlerTest.php.

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

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  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testExceptionIsThrownIfCannotSetTimeout()

Monolog\Handler\SocketHandlerTest::testExceptionIsThrownIfCannotSetTimeout ( )

UnexpectedValueException

Definition at line 107 of file SocketHandlerTest.php.

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

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  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testExceptionIsThrownOnFsockopenError()

Monolog\Handler\SocketHandlerTest::testExceptionIsThrownOnFsockopenError ( )

UnexpectedValueException

Definition at line 82 of file SocketHandlerTest.php.

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

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  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testExceptionIsThrownOnPfsockopenError()

Monolog\Handler\SocketHandlerTest::testExceptionIsThrownOnPfsockopenError ( )

UnexpectedValueException

Definition at line 94 of file SocketHandlerTest.php.

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

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  }
setMockHandler(array $methods=array())
+ 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 73 of file SocketHandlerTest.php.

References Monolog\Handler\SocketHandlerTest\createHandler().

74  {
75  $this->createHandler('tcp://localhost:9090');
76  $this->assertEquals('tcp://localhost:9090', $this->handler->getConnectionString());
77  }
+ 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:

◆ testWriteFailsIfStreamTimesOut()

Monolog\Handler\SocketHandlerTest::testWriteFailsIfStreamTimesOut ( )

RuntimeException

Definition at line 142 of file SocketHandlerTest.php.

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

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  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testWriteFailsOnIfFwriteReturnsFalse()

Monolog\Handler\SocketHandlerTest::testWriteFailsOnIfFwriteReturnsFalse ( )

RuntimeException

Definition at line 119 of file SocketHandlerTest.php.

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

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  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testWriteFailsOnIncompleteWrite()

Monolog\Handler\SocketHandlerTest::testWriteFailsOnIncompleteWrite ( )

RuntimeException

Definition at line 168 of file SocketHandlerTest.php.

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

169  {
170  $this->setMockHandler(array('fwrite', 'streamGetMetadata'));
171 
172  $res = $this->res;
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  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testWriteWithMemoryFile()

Monolog\Handler\SocketHandlerTest::testWriteWithMemoryFile ( )

Definition at line 189 of file SocketHandlerTest.php.

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

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  }
setMockHandler(array $methods=array())
+ Here is the call graph for this function:

◆ testWriteWithMock()

Monolog\Handler\SocketHandlerTest::testWriteWithMock ( )

Definition at line 199 of file SocketHandlerTest.php.

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

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  }
setMockHandler(array $methods=array())
+ 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: