Skip to content

Commit

Permalink
Add test case for validating conversion of WebSocket URI into corresp…
Browse files Browse the repository at this point in the history
…onding HTTP/S request URI.
  • Loading branch information
claudiosdc committed Dec 31, 2018
1 parent ddba9cf commit 00a49ef
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/unit/RequestUriTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Created by claudio on 2018-12-31
*/

use PHPUnit\Framework\TestCase;
use React\EventLoop\Factory;
use Ratchet\Client\Connector;
use Psr\Http\Message\RequestInterface;

class RequestUriTest extends TestCase {
protected static function getPrivateClassMethod($className, $methodName) {
$class = new ReflectionClass($className);
$method = $class->getMethod($methodName);
$method->setAccessible(true);
return $method;
}

function uriDataProvider() {
return [
['ws://127.0.0.1/bla', 'http://127.0.0.1/bla'],
['wss://127.0.0.1/bla', 'https://127.0.0.1/bla'],
['ws://127.0.0.1:1234/bla', 'http://127.0.0.1:1234/bla'],
['wss://127.0.0.1:4321/bla', 'https://127.0.0.1:4321/bla']
];
}

/**
* @dataProvider uriDataProvider
*/
function testGeneratedRequestUri($uri, $expectedRequestUri) {
$loop = Factory::create();

$connector = new Connector($loop);

$generateRequest = self::getPrivateClassMethod('\Ratchet\Client\Connector', 'generateRequest');
$request = $generateRequest->invokeArgs($connector, [$uri, [], []]);

$this->assertEquals((string)$request->getUri(), $expectedRequestUri);
}
}

0 comments on commit 00a49ef

Please sign in to comment.