1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-04 12:17:35 +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\ConnectionException;
use Monolog\Handler\SocketHandler\Exception\WriteToSocketException; use Monolog\Handler\SocketHandler\Exception\WriteToSocketException;
/** /**
* Stores to any socket - uses fsockopen() or pfsockopen(). * Stores to any socket - uses fsockopen() or pfsockopen().
* *
@@ -24,6 +23,7 @@ use Monolog\Handler\SocketHandler\Exception\WriteToSocketException;
*/ */
class SocketHandler extends AbstractProcessingHandler class SocketHandler extends AbstractProcessingHandler
{ {
private $connectionString; private $connectionString;
private $connectionTimeout; private $connectionTimeout;
private $resource; private $resource;
@@ -39,7 +39,7 @@ class SocketHandler extends AbstractProcessingHandler
{ {
parent::__construct($level, $bubble); parent::__construct($level, $bubble);
$this->connectionString = $connectionString; $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) public function setPersistent($boolean)
{ {
$this->persistent = (boolean)$boolean; $this->persistent = (boolean) $boolean;
} }
/** /**
@@ -88,7 +88,7 @@ class SocketHandler extends AbstractProcessingHandler
public function setConnectionTimeout($seconds) public function setConnectionTimeout($seconds)
{ {
$this->validateTimeout($seconds); $this->validateTimeout($seconds);
$this->connectionTimeout = (float)$seconds; $this->connectionTimeout = (float) $seconds;
} }
/** /**
@@ -100,14 +100,14 @@ class SocketHandler extends AbstractProcessingHandler
public function setTimeout($seconds) public function setTimeout($seconds)
{ {
$this->validateTimeout($seconds); $this->validateTimeout($seconds);
$this->timeout = (int)$seconds; $this->timeout = (int) $seconds;
} }
private function validateTimeout($value) private function validateTimeout($value)
{ {
$ok = filter_var($value, FILTER_VALIDATE_INT, array('options' => array( $ok = filter_var($value, FILTER_VALIDATE_INT, array('options' => array(
'min_range' => 0, 'min_range' => 0,
))); )));
if ($ok === false) { if ($ok === false) {
throw new \InvalidArgumentException("Timeout must be 0 or a positive integer (got $value)"); throw new \InvalidArgumentException("Timeout must be 0 or a positive integer (got $value)");
} }
@@ -123,11 +123,13 @@ class SocketHandler extends AbstractProcessingHandler
return $this->persistent; return $this->persistent;
} }
public function getConnectionTimeout() { public function getConnectionTimeout()
{
return $this->connectionTimeout; return $this->connectionTimeout;
} }
public function getTimeout() { public function getTimeout()
{
return $this->timeout; return $this->timeout;
} }
@@ -164,7 +166,7 @@ class SocketHandler extends AbstractProcessingHandler
public function isConnected() public function isConnected()
{ {
return is_resource($this->resource) 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() private function connect()
@@ -228,4 +230,5 @@ class SocketHandler extends AbstractProcessingHandler
{ {
return stream_get_meta_data($this->resource); return stream_get_meta_data($this->resource);
} }
} }

View File

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

View File

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