diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 117227a..0cc5451 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,6 +16,12 @@ + + + ./tests/integration/ + + + ./src/ diff --git a/tests/integration/GuzzleTest.php b/tests/integration/GuzzleTest.php new file mode 100644 index 0000000..6d3a544 --- /dev/null +++ b/tests/integration/GuzzleTest.php @@ -0,0 +1,53 @@ + 'websocket' + , 'Connection' => 'Upgrade' + , 'Host' => 'localhost:8080' + , 'Origin' => 'chrome://newtab' + , 'Sec-WebSocket-Protocol' => 'one, two, three' + , 'Sec-WebSocket-Key' => '9bnXNp3ae6FbFFRtPdiPXA==' + , 'Sec-WebSocket-Version' => '13' + ); + + public function setUp() { + $this->_request = new Request('GET', 'http://localhost', $this->_headers); + } + + public function testGetHeaderString() { + $this->assertEquals('Upgrade', (string)$this->_request->getHeader('connection')); + $this->assertEquals('9bnXNp3ae6FbFFRtPdiPXA==', (string)$this->_request->getHeader('Sec-Websocket-Key')); + } + + public function testGetHeaderInteger() { + $this->assertSame('13', (string)$this->_request->getHeader('Sec-Websocket-Version')); + $this->assertSame(13, (int)(string)$this->_request->getHeader('Sec-WebSocket-Version')); + } + + public function testGetHeaderObject() { + $this->assertInstanceOf('Guzzle\Http\Message\Header', $this->_request->getHeader('Origin')); + $this->assertNull($this->_request->getHeader('Non-existant-header')); + } + + public function testHeaderObjectNormalizeValues() { + $expected = 1 + substr_count($this->_headers['Sec-WebSocket-Protocol'], ','); + $protocols = $this->_request->getHeader('Sec-WebSocket-Protocol')->normalize(); + $count = 0; + + foreach ($protocols as $protocol) { + $count++; + } + + $this->assertEquals($expected, $count); + $this->assertEquals($expected, count($protocols)); + } + + public function testRequestFactoryCreateSignature() { + $ref = new \ReflectionMethod('Guzzle\Http\Message\RequestFactory', 'create'); + $this->assertEquals(2, $ref->getNumberOfRequiredParameters()); + } +} \ No newline at end of file