Mock Socket, Interfaces, Test stubs
This commit is contained in:
parent
8c9f55240c
commit
2811cdbd48
@ -11,13 +11,18 @@ class Socket {
|
||||
);
|
||||
|
||||
public function __construct($domain = null, $type = null, $protocol = null) {
|
||||
foreach (static::$_default as $key => $val) {
|
||||
list($domain, $type, $protocol) = static::getConfig($domain, $type, $protocol);
|
||||
$this->_socket = socket_create($domain, $type, $protocol);
|
||||
}
|
||||
|
||||
protected static function getConfig($domain = null, $type = null, $protocol = null) {
|
||||
foreach (static::$_defaults as $key => $val) {
|
||||
if (null === $$key) {
|
||||
$$key = $val;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_socket = socket_create($domain, $type, $protocol);
|
||||
return Array($domain, $type, $protocol);
|
||||
}
|
||||
|
||||
public function __call($method, $arguments) {
|
||||
|
41
tests/Ratchet/Tests/Mock/Socket.php
Normal file
41
tests/Ratchet/Tests/Mock/Socket.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace Ratchet\Tests\Mock;
|
||||
use Ratchet\Socket as RealSocket;
|
||||
|
||||
class Socket extends RealSocket {
|
||||
protected $_options = Array();
|
||||
|
||||
public function __construct($domain = null, $type = null, $protocol = null) {
|
||||
list($domain, $type, $protocol) = static::getConfig($domain, $type, $protocol);
|
||||
}
|
||||
|
||||
public function accept() {
|
||||
}
|
||||
|
||||
public function bind($address, $port) {
|
||||
}
|
||||
|
||||
public function close() {
|
||||
}
|
||||
|
||||
public function get_option($level, $optname) {
|
||||
return $this->_options[$level][$optname];
|
||||
}
|
||||
|
||||
public function listen($backlog) {
|
||||
}
|
||||
|
||||
public function recv($buf, $len, $flags) {
|
||||
}
|
||||
|
||||
public function set_option($level, $optname, $optval) {
|
||||
if (!is_array($this->_options[$level])) {
|
||||
$this->_options[$level] = Array();
|
||||
}
|
||||
|
||||
$this->_options[$level][$optname] = $optval;
|
||||
}
|
||||
|
||||
public function write($buffer, $length = 0) {
|
||||
}
|
||||
}
|
20
tests/Ratchet/Tests/ServerTest.php
Normal file
20
tests/Ratchet/Tests/ServerTest.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Ratchet\Tests;
|
||||
use Ratchet\Server;
|
||||
use Ratchet\Tests\Mock\Socket;
|
||||
|
||||
/**
|
||||
* @covers Ratchet\Server
|
||||
*/
|
||||
class ServerTest extends \PHPUnit_Framework_TestCase {
|
||||
protected $_server;
|
||||
|
||||
public function setUp() {
|
||||
$this->_server = new Server(new Socket());
|
||||
}
|
||||
|
||||
public function testServerHasServerInterface() {
|
||||
$constraint = $this->isInstanceOf('\\Ratchet\\ServerInterface');
|
||||
$this->assertThat($this->_server, $constraint);
|
||||
}
|
||||
}
|
29
tests/Ratchet/Tests/SocketTest.php
Normal file
29
tests/Ratchet/Tests/SocketTest.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace Ratchet\Tests;
|
||||
use Ratchet\Tests\Mock\Socket;
|
||||
|
||||
/**
|
||||
* @covers Ratchet\Socket
|
||||
*/
|
||||
class SocketTest extends \PHPUnit_Framework_TestCase {
|
||||
protected $_socket;
|
||||
|
||||
protected static function getMethod($name) {
|
||||
$class = new \ReflectionClass('\\Ratchet\\Tests\\Mock\\Socket');
|
||||
$method = $class->getMethod($name);
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method;
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
$this->_socket = new Socket();
|
||||
}
|
||||
|
||||
public function testGetConfigForConstruct() {
|
||||
$ref_conf = static::getMethod('getConfig');
|
||||
$config = $ref_conf->invokeArgs($this->_socket, Array());
|
||||
|
||||
$this->assertEquals(array_values(Socket::$_defaults), $config);
|
||||
}
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
<?php
|
||||
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'SplClassLoader.php');
|
||||
|
||||
$app = new SplClassLoader('Ratchet', __DIR__);
|
||||
$app->register();
|
||||
|
||||
$app = new SplClassLoader('Ratchet', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'lib');
|
||||
$app->register();
|
Loading…
Reference in New Issue
Block a user