Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
namespace Ratchet\WebSocket;
3
use Ratchet\WebSocket\WsServer;
4
use Ratchet\Mock\Component as MockComponent;
5
 
6
/**
7
 * @covers Ratchet\WebSocket\WsServer
8
 * @covers Ratchet\ComponentInterface
9
 * @covers Ratchet\MessageComponentInterface
10
 */
11
class WsServerTest extends \PHPUnit_Framework_TestCase {
12
    protected $comp;
13
 
14
    protected $serv;
15
 
16
    public function setUp() {
17
        $this->comp = new MockComponent;
18
        $this->serv = new WsServer($this->comp);
19
    }
20
 
21
    public function testIsSubProtocolSupported() {
22
        $this->comp->protocols = array('hello', 'world');
23
 
24
        $this->assertTrue($this->serv->isSubProtocolSupported('hello'));
25
        $this->assertFalse($this->serv->isSubProtocolSupported('nope'));
26
    }
27
 
28
    public function protocolProvider() {
29
        return array(
30
            array('hello', array('hello', 'world'), array('hello', 'world'))
31
          , array('', array('hello', 'world'), array('wamp'))
32
          , array('', array(), null)
33
          , array('wamp', array('hello', 'wamp', 'world'), array('herp', 'derp', 'wamp'))
34
          , array('wamp', array('wamp'), array('wamp'))
35
        );
36
    }
37
 
38
    /**
39
     * @dataProvider protocolProvider
40
     */
41
    public function testGetSubProtocolString($expected, $supported, $requested) {
42
        $this->comp->protocols = $supported;
43
        $req = (null === $requested ? $requested : new \ArrayIterator($requested));
44
 
45
        $class  = new \ReflectionClass('Ratchet\\WebSocket\\WsServer');
46
        $method = $class->getMethod('getSubProtocolString');
47
        $method->setAccessible(true);
48
 
49
        $this->assertSame($expected, $method->invokeArgs($this->serv, array($req)));
50
    }
51
}