Skip to content

Commit

Permalink
Merge pull request #63 from adriansuter/patch-1
Browse files Browse the repository at this point in the history
Add additional test cases for Uri
  • Loading branch information
l0gicgate committed Apr 30, 2019
2 parents 109508b + 4d53377 commit 8dfb52d
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/UriTest.php
Expand Up @@ -12,6 +12,7 @@
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use Slim\Psr7\Uri;
use stdClass;

class UriTest extends TestCase
{
Expand Down Expand Up @@ -119,6 +120,26 @@ public function testWithHost()
$this->assertEquals('slimframework.com', $uri->getHost());
}

public function testWithHostValidObject()
{
$mock = $this->getMockBuilder('UriTestHost')->setMethods(['__toString'])->getMock();
$mock->expects($this->once())
->method('__toString')
->will($this->returnValue('host.test'));

$uri = $this->uriFactory()->withHost($mock);
$this->assertEquals('host.test', $uri->getHost());
}

/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Uri host must be a string
*/
public function testWithHostInvalidObject()
{
$this->uriFactory()->withHost(new stdClass());
}

public function testFilterHost()
{
$uri = new Uri('http', '2001:db8::1');
Expand Down Expand Up @@ -261,6 +282,17 @@ public function testWithQueryEmpty()
$this->assertEquals('', $uri->getQuery());
}

public function testWithQueryValidObject()
{
$mock = $this->getMockBuilder('UriTestQuery')->setMethods(['__toString'])->getMock();
$mock->expects($this->once())
->method('__toString')
->will($this->returnValue('xyz=123'));

$uri = $this->uriFactory()->withQuery($mock);
$this->assertEquals('xyz=123', $uri->getQuery());
}

public function testFilterQuery()
{
$uri = $this->uriFactory()->withQuery('?foobar=%match');
Expand Down Expand Up @@ -303,6 +335,24 @@ public function testWithFragmentEmpty()
$this->assertEquals('', $uri->getFragment());
}

public function testWithFragmentValidObject()
{
$mock = $this->getMockBuilder('UriTestFragment')->setMethods(['__toString'])->getMock();
$mock->expects($this->once())
->method('__toString')
->will($this->returnValue('other-fragment'));

$uri = $this->uriFactory()->withFragment($mock);
$this->assertEquals('other-fragment', $uri->getFragment());
}

public function testWithFragmentUrlEncode()
{
$uri = $this->uriFactory()->withFragment('^a');

$this->assertEquals('%5Ea', $uri->getFragment());
}

/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Uri fragment must be a string
Expand Down

0 comments on commit 8dfb52d

Please sign in to comment.