mxmbsocket/tests/Ratchet/Tests/SocketTest.php
Chris Boden 1b01582ab9 SocketInterface
Added unix socket methods to interface, replaced __call/call_user_func calls with concrete methods
2011-11-20 20:38:20 -05:00

65 lines
2.0 KiB
PHP

<?php
namespace Ratchet\Tests;
use Ratchet\Tests\Mock\FakeSocket as Socket;
use Ratchet\Socket as RealSocket;
use Ratchet\Tests\Mock\Application as TestApp;
/**
* @covers Ratchet\Socket
*/
class SocketTest extends \PHPUnit_Framework_TestCase {
protected $_socket;
protected static function getMethod($name) {
$class = new \ReflectionClass('\\Ratchet\\Tests\\Mock\\FakeSocket');
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method;
}
public function setUp() {
$this->_socket = new Socket();
}
public function testGetDefaultConfigForConstruct() {
$ref_conf = static::getMethod('getConfig');
$config = $ref_conf->invokeArgs($this->_socket, array());
$this->assertEquals(array_values(Socket::$_defaults), $config);
}
public function testInvalidConstructorArguments() {
$this->setExpectedException('\\Ratchet\\Exception');
$socket = new RealSocket('invalid', 'param', 'derp');
}
public function testConstructAndCallByOpenAndClose() {
$socket = new RealSocket();
$socket->close();
}
public function asArrayProvider() {
return array(
array(array('hello' => 'world'), array('hello' => 'world'))
, array(null, null)
, array(array('hello' => 'world'), new \ArrayObject(array('hello' => 'world')))
);
}
/**
* @dataProvider asArrayProvider
*/
public function testMethodMungforselectReturnsExpectedValues($output, $input) {
$method = static::getMethod('mungForSelect');
$return = $method->invokeArgs($this->_socket, array($input));
$this->assertEquals($return, $output);
}
public function testMethodMungforselectRejectsNonTraversable() {
$this->setExpectedException('\\InvalidArgumentException');
$method = static::getMethod('mungForSelect');
$method->invokeArgs($this->_socket, array('I am upset with PHP ATM'));
}
}