1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-05 20:57:36 +02:00

Remove old SocketTest. Fix CS issues

This commit is contained in:
Pablo Belloc
2012-02-26 14:17:19 -03:00
parent cc9c02250c
commit 722cabc535
5 changed files with 92 additions and 93 deletions

View File

@@ -15,7 +15,6 @@ use Monolog\Logger;
use Monolog\Handler\SocketHandler\Exception\ConnectionException;
use Monolog\Handler\SocketHandler\Exception\WriteToSocketException;
/**
* Stores to any socket - uses fsockopen() or pfsockopen().
*
@@ -24,6 +23,7 @@ use Monolog\Handler\SocketHandler\Exception\WriteToSocketException;
*/
class SocketHandler extends AbstractProcessingHandler
{
private $connectionString;
private $connectionTimeout;
private $resource;
@@ -39,7 +39,7 @@ class SocketHandler extends AbstractProcessingHandler
{
parent::__construct($level, $bubble);
$this->connectionString = $connectionString;
$this->connectionTimeout = (float)ini_get('default_socket_timeout');
$this->connectionTimeout = (float) ini_get('default_socket_timeout');
}
/**
@@ -76,7 +76,7 @@ class SocketHandler extends AbstractProcessingHandler
public function setPersistent($boolean)
{
$this->persistent = (boolean)$boolean;
$this->persistent = (boolean) $boolean;
}
/**
@@ -88,7 +88,7 @@ class SocketHandler extends AbstractProcessingHandler
public function setConnectionTimeout($seconds)
{
$this->validateTimeout($seconds);
$this->connectionTimeout = (float)$seconds;
$this->connectionTimeout = (float) $seconds;
}
/**
@@ -100,14 +100,14 @@ class SocketHandler extends AbstractProcessingHandler
public function setTimeout($seconds)
{
$this->validateTimeout($seconds);
$this->timeout = (int)$seconds;
$this->timeout = (int) $seconds;
}
private function validateTimeout($value)
{
$ok = filter_var($value, FILTER_VALIDATE_INT, array('options' => array(
'min_range' => 0,
)));
'min_range' => 0,
)));
if ($ok === false) {
throw new \InvalidArgumentException("Timeout must be 0 or a positive integer (got $value)");
}
@@ -123,11 +123,13 @@ class SocketHandler extends AbstractProcessingHandler
return $this->persistent;
}
public function getConnectionTimeout() {
public function getConnectionTimeout()
{
return $this->connectionTimeout;
}
public function getTimeout() {
public function getTimeout()
{
return $this->timeout;
}
@@ -164,7 +166,7 @@ class SocketHandler extends AbstractProcessingHandler
public function isConnected()
{
return is_resource($this->resource)
&& !feof($this->resource); // on TCP - other party can close connection.
&& !feof($this->resource); // on TCP - other party can close connection.
}
private function connect()
@@ -228,4 +230,5 @@ class SocketHandler extends AbstractProcessingHandler
{
return stream_get_meta_data($this->resource);
}
}

View File

@@ -13,4 +13,5 @@ namespace Monolog\Handler\SocketHandler\Exception;
class ConnectionException extends \RuntimeException
{
}

View File

@@ -13,4 +13,5 @@ namespace Monolog\Handler\SocketHandler\Exception;
class WriteToSocketException extends \RuntimeException
{
}

View File

@@ -1,8 +0,0 @@
<?php
namespace Monolog\Handler\SocketHandler;
class SocketTest extends \PHPUnit_Framework_TestCase
{
}

View File

@@ -21,6 +21,7 @@ use Monolog\Handler\SocketHandler\Exception\WriteToSocketException;
*/
class SocketHandlerTest extends TestCase
{
/**
* @var Monolog\Handler\SocketHandler
*/
@@ -34,7 +35,8 @@ class SocketHandlerTest extends TestCase
/**
* @expectedException Monolog\Handler\SocketHandler\Exception\ConnectionException
*/
public function testInvalidHostname() {
public function testInvalidHostname()
{
$this->createHandler('garbage://here');
$this->writeRecord('data');
}
@@ -85,6 +87,7 @@ class SocketHandlerTest extends TestCase
$this->writeRecord($string);
$this->fail("Shoul not connect - are you running a server on 127.0.0.1:7894 ?");
} catch (\Monolog\Handler\SocketHandler\Exception\ConnectionException $e) {
}
}
@@ -95,8 +98,8 @@ class SocketHandlerTest extends TestCase
{
$this->setMockHandler(array('createSocketResource'));
$this->handler->expects($this->once())
->method('createSocketResource')
->will($this->throwException(new ConnectionException()));
->method('createSocketResource')
->will($this->throwException(new ConnectionException()));
$this->writeRecord('Hello world');
}
@@ -113,8 +116,8 @@ class SocketHandlerTest extends TestCase
);
$this->handler->expects($this->exactly(2))
->method('fwrite')
->will($this->returnValueMap($map));
->method('fwrite')
->will($this->returnValueMap($map));
$this->injectMemoryResource();
$this->writeRecord('Hello world');
@@ -133,11 +136,11 @@ class SocketHandlerTest extends TestCase
);
$this->handler->expects($this->exactly(1))
->method('fwrite')
->will($this->returnValueMap($map));
->method('fwrite')
->will($this->returnValueMap($map));
$this->handler->expects($this->exactly(1))
->method('stream_get_meta_data')
->will($this->returnValue(array('timed_out' => true)));
->method('stream_get_meta_data')
->will($this->returnValue(array('timed_out' => true)));
$this->injectMemoryResource();
@@ -157,17 +160,17 @@ class SocketHandlerTest extends TestCase
);
$this->handler->expects($this->exactly(1))
->method('fwrite')
->will($this->returnValueMap($map));
->method('fwrite')
->will($this->returnValueMap($map));
$this->handler->expects($this->at(0))
->method('isConnected')
->will($this->returnValue(true));
->method('isConnected')
->will($this->returnValue(true));
$this->handler->expects($this->at(1))
->method('isConnected')
->will($this->returnValue(true));
->method('isConnected')
->will($this->returnValue(true));
$this->handler->expects($this->at(2))
->method('isConnected')
->will($this->returnValue(false));
->method('isConnected')
->will($this->returnValue(false));
$this->injectMemoryResource();
$this->writeRecord('Hello world');
@@ -194,8 +197,8 @@ class SocketHandlerTest extends TestCase
);
$this->handler->expects($this->exactly(2))
->method('fwrite')
->will($this->returnValueMap($map));
->method('fwrite')
->will($this->returnValueMap($map));
$this->injectMemoryResource();
$this->writeRecord('Hello world');
@@ -251,10 +254,9 @@ class SocketHandlerTest extends TestCase
private function setMockHandler(array $methods)
{
$this->handler = $this->getMock(
'\Monolog\Handler\SocketHandler',
$methods,
array('localhost:1234')
'\Monolog\Handler\SocketHandler', $methods, array('localhost:1234')
);
$this->handler->setFormatter($this->getIdentityFormatter());
}
}