RequestUriTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * Created by claudio on 2018-12-31
  4. */
  5. use PHPUnit\Framework\TestCase;
  6. use React\EventLoop\Factory;
  7. use Ratchet\Client\Connector;
  8. use Psr\Http\Message\RequestInterface;
  9. class RequestUriTest extends TestCase {
  10. protected static function getPrivateClassMethod($className, $methodName) {
  11. $class = new ReflectionClass($className);
  12. $method = $class->getMethod($methodName);
  13. $method->setAccessible(true);
  14. return $method;
  15. }
  16. function uriDataProvider() {
  17. return [
  18. ['ws://127.0.0.1/bla', 'http://127.0.0.1/bla'],
  19. ['wss://127.0.0.1/bla', 'https://127.0.0.1/bla'],
  20. ['ws://127.0.0.1:1234/bla', 'http://127.0.0.1:1234/bla'],
  21. ['wss://127.0.0.1:4321/bla', 'https://127.0.0.1:4321/bla']
  22. ];
  23. }
  24. /**
  25. * @dataProvider uriDataProvider
  26. */
  27. function testGeneratedRequestUri($uri, $expectedRequestUri) {
  28. $connector = new Connector();
  29. $generateRequest = self::getPrivateClassMethod('\Ratchet\Client\Connector', 'generateRequest');
  30. $request = $generateRequest->invokeArgs($connector, [$uri, [], []]);
  31. $this->assertEquals((string)$request->getUri(), $expectedRequestUri);
  32. }
  33. }