Unit Testing
This commit is contained in:
parent
6ac2272114
commit
5b99af0f82
@ -3,14 +3,26 @@ namespace Ratchet\Logging;
|
|||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
|
|
||||||
class MonologAdapter extends Logger implements LoggerInterface {
|
class MonologAdapter extends Logger implements LoggerInterface {
|
||||||
|
/**
|
||||||
|
* Maps to Monolog\Logger::addInfo
|
||||||
|
* @param string
|
||||||
|
*/
|
||||||
function note($msg) {
|
function note($msg) {
|
||||||
$this->addInfo($msg);
|
$this->addInfo($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps to Monolog\Logger::addWarning
|
||||||
|
* @param string
|
||||||
|
*/
|
||||||
function warning($msg) {
|
function warning($msg) {
|
||||||
$this->addWarning($msg);
|
$this->addWarning($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps to Monolog\Logger::addError
|
||||||
|
* @param string
|
||||||
|
*/
|
||||||
function error($msg) {
|
function error($msg) {
|
||||||
$this->addError($msg);
|
$this->addError($msg);
|
||||||
}
|
}
|
||||||
|
30
tests/Ratchet/Tests/Logging/NullLoggerTest.php
Normal file
30
tests/Ratchet/Tests/Logging/NullLoggerTest.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
namespace Ratchet\Tests\Logging;
|
||||||
|
use Ratchet\Logging\NullLogger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Ratchet\Logging\NullLogger
|
||||||
|
*/
|
||||||
|
class NullLoggerTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
protected $_log;
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
$this->_log = new NullLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInterface() {
|
||||||
|
$this->assertInstanceOf('\\Ratchet\\Logging\\LoggerInterface', $this->_log);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNoteDoesNothing() {
|
||||||
|
$this->assertNull($this->_log->note('hi'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testWarningDoesNothing() {
|
||||||
|
$this->assertNull($this->_log->warning('hi'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testErrorDoesNothing() {
|
||||||
|
$this->assertNull($this->_log->error('hi'));
|
||||||
|
}
|
||||||
|
}
|
19
tests/Ratchet/Tests/Mock/ArrayLogger.php
Normal file
19
tests/Ratchet/Tests/Mock/ArrayLogger.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
namespace Ratchet\Tests\Mock;
|
||||||
|
use Ratchet\Logging\LoggerInterface;
|
||||||
|
|
||||||
|
class ArrayLogger implements LoggerInterface {
|
||||||
|
public $last_msg = '';
|
||||||
|
|
||||||
|
public function note($msg) {
|
||||||
|
$this->last_msg = $msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function warning($msg) {
|
||||||
|
$this->last_msg = $msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function error($msg) {
|
||||||
|
$this->last_msg = $msg;
|
||||||
|
}
|
||||||
|
}
|
@ -3,15 +3,26 @@ namespace Ratchet\Tests;
|
|||||||
use Ratchet\Server;
|
use Ratchet\Server;
|
||||||
use Ratchet\Tests\Mock\FakeSocket as Socket;
|
use Ratchet\Tests\Mock\FakeSocket as Socket;
|
||||||
use Ratchet\Tests\Mock\Application as TestApp;
|
use Ratchet\Tests\Mock\Application as TestApp;
|
||||||
|
use Ratchet\Tests\Mock\ArrayLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Ratchet\Server
|
* @covers Ratchet\Server
|
||||||
*/
|
*/
|
||||||
class ServerTest extends \PHPUnit_Framework_TestCase {
|
class ServerTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
protected $_catalyst;
|
||||||
protected $_server;
|
protected $_server;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->_server = new Server(new Socket());
|
$this->_catalyst = new Socket;
|
||||||
|
$this->_server = new Server($this->_catalyst);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getPrivateProperty($class, $name) {
|
||||||
|
$reflectedClass = new \ReflectionClass($class);
|
||||||
|
$property = $reflectedClass->getProperty($name);
|
||||||
|
$property->setAccessible(true);
|
||||||
|
|
||||||
|
return $property->getValue($class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testServerHasServerInterface() {
|
public function testServerHasServerInterface() {
|
||||||
@ -19,6 +30,32 @@ class ServerTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$this->assertThat($this->_server, $constraint);
|
$this->assertThat($this->_server, $constraint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNullLoggerIsSetInConstruct() {
|
||||||
|
$this->assertInstanceOf('\\Ratchet\\Logging\\LoggerInterface', $this->getPrivateProperty($this->_server, '_log'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPassedLoggerIsSetInConstruct() {
|
||||||
|
$logger = new ArrayLogger;
|
||||||
|
$server = new Server(new Socket(), $logger);
|
||||||
|
|
||||||
|
$this->assertSame($logger, $this->getPrivateProperty($server, '_log'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLoggerIsSetInMethod() {
|
||||||
|
$logger = new ArrayLogger;
|
||||||
|
$this->_server->setLogger($logger);
|
||||||
|
|
||||||
|
$this->assertSame($logger, $this->getPrivateProperty($this->_server, '_log'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetMasterReturnsCatalyst() {
|
||||||
|
$this->assertSame($this->_catalyst, $this->_server->getMaster());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIteration() {
|
||||||
|
$this->assertInstanceOf('\\Iterator', $this->_server->getIterator());
|
||||||
|
}
|
||||||
|
|
||||||
public function testServerCanNotRunWithoutApplication() {
|
public function testServerCanNotRunWithoutApplication() {
|
||||||
$this->setExpectedException('\\RuntimeException');
|
$this->setExpectedException('\\RuntimeException');
|
||||||
$this->_server->run();
|
$this->_server->run();
|
||||||
|
Loading…
Reference in New Issue
Block a user