From 4ce74d248187a9c7026edb43fb3a21e39b01ba1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 25 Jul 2020 01:33:12 +0200 Subject: [PATCH] Remove unneeded MessageFactory helper methods --- src/Browser.php | 2 +- src/Io/MessageFactory.php | 24 ------------- src/Io/Transaction.php | 3 +- tests/Io/MessageFactoryTest.php | 62 --------------------------------- 4 files changed, 3 insertions(+), 88 deletions(-) diff --git a/src/Browser.php b/src/Browser.php index 622404bf..48e64fcb 100644 --- a/src/Browser.php +++ b/src/Browser.php @@ -585,7 +585,7 @@ public function withBase($baseUrl) return $browser; } - $browser->baseUrl = $this->messageFactory->uri($baseUrl); + $browser->baseUrl = new Uri($baseUrl); if (!\in_array($browser->baseUrl->getScheme(), array('http', 'https')) || $browser->baseUrl->getHost() === '') { throw new \InvalidArgumentException('Base URL must be absolute'); } diff --git a/src/Io/MessageFactory.php b/src/Io/MessageFactory.php index 5b7a2b35..f3d0993d 100644 --- a/src/Io/MessageFactory.php +++ b/src/Io/MessageFactory.php @@ -6,7 +6,6 @@ use Psr\Http\Message\UriInterface; use RingCentral\Psr7\Request; use RingCentral\Psr7\Response; -use RingCentral\Psr7\Uri; use React\Stream\ReadableStreamInterface; /** @@ -76,27 +75,4 @@ public function body($body) return \RingCentral\Psr7\stream_for($body); } - - /** - * Creates a new instance of UriInterface for the given URI string - * - * @param string $uri - * @return UriInterface - */ - public function uri($uri) - { - return new Uri($uri); - } - - /** - * Creates a new instance of UriInterface for the given URI string relative to the given base URI - * - * @param UriInterface $base - * @param string $uri - * @return UriInterface - */ - public function uriRelative(UriInterface $base, $uri) - { - return Uri::resolve($base, $uri); - } } diff --git a/src/Io/Transaction.php b/src/Io/Transaction.php index a593e684..93741dcc 100644 --- a/src/Io/Transaction.php +++ b/src/Io/Transaction.php @@ -5,6 +5,7 @@ use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\UriInterface; +use RingCentral\Psr7\Uri; use React\EventLoop\LoopInterface; use React\Http\Message\ResponseException; use React\Promise\Deferred; @@ -246,7 +247,7 @@ public function onResponse(ResponseInterface $response, RequestInterface $reques private function onResponseRedirect(ResponseInterface $response, RequestInterface $request, Deferred $deferred) { // resolve location relative to last request URI - $location = $this->messageFactory->uriRelative($request->getUri(), $response->getHeaderLine('Location')); + $location = Uri::resolve($request->getUri(), $response->getHeaderLine('Location')); $request = $this->makeRedirectRequest($request, $location); $this->progress('redirect', array($request)); diff --git a/tests/Io/MessageFactoryTest.php b/tests/Io/MessageFactoryTest.php index b09a4af8..ae2dcdf9 100644 --- a/tests/Io/MessageFactoryTest.php +++ b/tests/Io/MessageFactoryTest.php @@ -17,68 +17,6 @@ public function setUpMessageFactory() $this->messageFactory = new MessageFactory(); } - public function testUriSimple() - { - $uri = $this->messageFactory->uri('http://www.lueck.tv/'); - - $this->assertEquals('http', $uri->getScheme()); - $this->assertEquals('www.lueck.tv', $uri->getHost()); - $this->assertEquals('/', $uri->getPath()); - - $this->assertEquals(null, $uri->getPort()); - $this->assertEquals('', $uri->getQuery()); - } - - public function testUriComplete() - { - $uri = $this->messageFactory->uri('https://example.com:8080/?just=testing'); - - $this->assertEquals('https', $uri->getScheme()); - $this->assertEquals('example.com', $uri->getHost()); - $this->assertEquals(8080, $uri->getPort()); - $this->assertEquals('/', $uri->getPath()); - $this->assertEquals('just=testing', $uri->getQuery()); - } - - public function testPlaceholdersInUriWillBeEscaped() - { - $uri = $this->messageFactory->uri('http://example.com/{version}'); - - $this->assertEquals('/%7Bversion%7D', $uri->getPath()); - } - - public function testEscapedPlaceholdersInUriWillStayEscaped() - { - $uri = $this->messageFactory->uri('http://example.com/%7Bversion%7D'); - - $this->assertEquals('/%7Bversion%7D', $uri->getPath()); - } - - public function testResolveRelative() - { - $base = $this->messageFactory->uri('http://example.com/base/'); - - $this->assertEquals('http://example.com/base/', $this->messageFactory->uriRelative($base, '')); - $this->assertEquals('http://example.com/', $this->messageFactory->uriRelative($base, '/')); - - $this->assertEquals('http://example.com/base/a', $this->messageFactory->uriRelative($base, 'a')); - $this->assertEquals('http://example.com/a', $this->messageFactory->uriRelative($base, '../a')); - } - - public function testResolveAbsolute() - { - $base = $this->messageFactory->uri('http://example.org/'); - - $this->assertEquals('http://www.example.com/', $this->messageFactory->uriRelative($base, 'http://www.example.com/')); - } - - public function testResolveUri() - { - $base = $this->messageFactory->uri('http://example.org/'); - - $this->assertEquals('http://www.example.com/', $this->messageFactory->uriRelative($base, $this->messageFactory->uri('http://www.example.com/'))); - } - public function testBodyString() { $body = $this->messageFactory->body('hi');