1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-08 06:06:40 +02:00

Initial version

This commit is contained in:
Pablo Belloc
2012-02-25 20:37:04 -03:00
parent 6c15897ac7
commit 486cbb78ab
8 changed files with 516 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
<?php
/**
* @author Pablo de Leon Belloc <pablolb@gmail.com>
*/
namespace Monolog\Handler;
use Monolog\Handler\SocketHandler\MockSocket;
use Monolog\Handler\SocketHandler\Socket;
use Monolog\Handler\SocketHandler\PersistentSocket;
use Monolog\TestCase;
use Monolog\Logger;
class SocketHandlerTest extends TestCase
{
public function testWrite()
{
$socket = new MockSocket('localhost');
$handler = new SocketHandler('localhost');
$handler->setSocket($socket);
$handler->setFormatter($this->getIdentityFormatter());
$handler->handle($this->getRecord(Logger::WARNING, 'test'));
$handler->handle($this->getRecord(Logger::WARNING, 'test2'));
$handler->handle($this->getRecord(Logger::WARNING, 'test3'));
$handle = $socket->getResource();
fseek($handle, 0);
$this->assertEquals('testtest2test3', fread($handle, 100));
}
public function testCloseClosesNonPersistentSocket()
{
$socket = new Socket('localhost');
$res = fopen('php://memory', 'a');
$socket->setResource($res);
$handler = new SocketHandler('localhost');
$handler->setSocket($socket);
$handler->close();
$this->assertFalse($socket->isConnected());
}
public function testCloseDoesNotClosePersistentSocket()
{
$socket = new PersistentSocket('localhost');
$res = fopen('php://memory', 'a');
$socket->setResource($res);
$handler = new SocketHandler('localhost');
$handler->setSocket($socket);
$handler->close();
$this->assertTrue($socket->isConnected());
}
}