From b1b5fbe1a7c2d22e59f3d4b8092c6cf84f67fce3 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sun, 16 Jun 2013 17:40:38 -0400 Subject: [PATCH] [Tests] Added Guzzle integration tests --- phpunit.xml.dist | 6 ++++ tests/integration/GuzzleTest.php | 53 ++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 tests/integration/GuzzleTest.php 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