mxmbsocket/tests/Ratchet/Tests/WebSocket/WsServerTest.php
Chris Boden f729be2ef3 [WebSocket] [WAMP] Sub-Protocols
Updated how Ratchet handles WebSocket sub-protocols
Broke out WsServerInterface to not extend MessageInterface;
Components will instead use Interface segregation principle
WAMP is now able to work without the developer having to
manually enable the WAMP sub-protocol
2012-05-12 22:42:56 -04:00

48 lines
1.5 KiB
PHP

<?php
namespace Ratchet\Tests\WebSocket;
use Ratchet\WebSocket\WsServer;
use Ratchet\Tests\Mock\Component as MockComponent;
/**
* @covers Ratchet\WebSocket\WsServer
*/
class WsServerTest extends \PHPUnit_Framework_TestCase {
protected $comp;
protected $serv;
public function setUp() {
$this->comp = new MockComponent;
$this->serv = new WsServer($this->comp);
}
public function testIsSubProtocolSupported() {
$this->comp->protocols = array('hello', 'world');
$this->assertTrue($this->serv->isSubProtocolSupported('hello'));
$this->assertFalse($this->serv->isSubProtocolSupported('nope'));
}
public function protocolProvider() {
return array(
array('hello,world', array('hello', 'world'), array('hello', 'world'))
, array('', array('hello', 'world'), array('wamp'))
, array('', array(), null)
, array('wamp', array('hello', 'wamp', 'world'), array('herp', 'derp', 'wamp'))
);
}
/**
* @dataProvider protocolProvider
*/
public function testGetSubProtocolString($expected, $supported, $requested) {
$this->comp->protocols = $supported;
$req = (null === $requested ? $requested : new \ArrayIterator($requested));
$class = new \ReflectionClass('Ratchet\\WebSocket\\WsServer');
$method = $class->getMethod('getSubProtocolString');
$method->setAccessible(true);
$this->assertEquals($expected, $method->invokeArgs($this->serv, array($req)));
}
}