Skip to content

Commit

Permalink
Remove unneeded MessageFactory helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Jul 25, 2020
1 parent 0daf98f commit 4ce74d2
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
24 changes: 0 additions & 24 deletions src/Io/MessageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}
}
3 changes: 2 additions & 1 deletion src/Io/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
62 changes: 0 additions & 62 deletions tests/Io/MessageFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 4ce74d2

Please sign in to comment.