-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case for validating conversion of WebSocket URI into corresp…
…onding HTTP/S request URI.
- Loading branch information
1 parent
ddba9cf
commit 00a49ef
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |