Skip to content

Commit

Permalink
fixed more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Kalkbrenner committed Feb 1, 2019
1 parent fe6f264 commit fc91f53
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
11 changes: 8 additions & 3 deletions src/Core/Client/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function getCollectionBaseUri(): string
$uri .= $collection.'/';
}
else {
throw new UnexpectedValueException();
throw new UnexpectedValueException('No collection set.');
}

return $uri;
Expand All @@ -276,7 +276,7 @@ public function getCoreBaseUri(): string
$uri .= $core.'/';
}
else {
throw new UnexpectedValueException();
throw new UnexpectedValueException('No core set.');
}

return $uri;
Expand All @@ -295,7 +295,12 @@ public function getBaseUri(): string
return $this->getCollectionBaseUri();
}
catch (UnexpectedValueException $e) {
return $this->getCoreBaseUri();
try {
return $this->getCoreBaseUri();
}
catch (UnexpectedValueException $e) {
throw new UnexpectedValueException('Neither collection nor core set.');
}
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/Core/Client/Adapter/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function testExecute()

$request = new Request();
$request->setMethod(Request::METHOD_GET);
$request->setIsServerRequest(true);
$endpoint = new Endpoint();

/** @var Http|MockObject $mock */
Expand Down
23 changes: 15 additions & 8 deletions tests/Core/Client/EndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,33 @@ public function testGetCollectionBaseUri()
{
$this->endpoint->setHost('myserver')->setPath('/mypath')->setPort(123);
$this->expectException(UnexpectedValueException::class);
$this->assertSame('http://myserver:123/mypath/collection1', $this->endpoint->getCollectionBaseUri());
$this->assertSame('http://myserver:123/mypath/collection1/', $this->endpoint->getCollectionBaseUri());

$this->endpoint->setCollection('collection1');
$this->assertSame('http://myserver:123/mypath/collection1', $this->endpoint->getCollectionBaseUri());
$this->assertSame('http://myserver:123/mypath/collection1/', $this->endpoint->getCollectionBaseUri());
}

public function testGetCoreBaseUri()
{
$this->endpoint->setHost('myserver')->setPath('/mypath')->setPort(123);
$this->expectException(UnexpectedValueException::class);
$this->assertSame('http://myserver:123/mypath/core1', $this->endpoint->getCoreBaseUri());
$this->assertSame('http://myserver:123/mypath/core1/', $this->endpoint->getCoreBaseUri());

$this->endpoint->setCore('core1');
$this->assertSame('http://myserver:123/mypath/core1', $this->endpoint->getCoreBaseUri());
$this->assertSame('http://myserver:123/mypath/core1/', $this->endpoint->getCoreBaseUri());
}

public function testGetBaseUri()
{
$this->endpoint->setHost('myserver')->setPath('/mypath')->setPort(123);
$this->expectException(UnexpectedValueException::class);
$this->assertSame('http://myserver:123/mypath/core1', $this->endpoint->getCoreBaseUri());
$this->assertSame('http://myserver:123/mypath/core1/', $this->endpoint->getCoreBaseUri());

$this->endpoint->setCore('core1');
$this->assertSame('http://myserver:123/mypath/core1', $this->endpoint->getCoreBaseUri());
$this->assertSame('http://myserver:123/mypath/core1/', $this->endpoint->getCoreBaseUri());

$this->endpoint->setCollection('collection1');
$this->assertSame('http://myserver:123/mypath/collection1', $this->endpoint->getCollectionBaseUri());
$this->assertSame('http://myserver:123/mypath/collection1/', $this->endpoint->getCollectionBaseUri());
}

public function testGetServerUri()
Expand All @@ -131,7 +131,7 @@ public function testGetCoreBaseUriWithHttps()
{
$this->endpoint->setScheme('https')->setHost('myserver')->setPath('/mypath')->setPort(123)->setCore('core1');

$this->assertSame('https://myserver:123/mypath/', $this->endpoint->getCoreBaseUri());
$this->assertSame('https://myserver:123/mypath/core1/', $this->endpoint->getCoreBaseUri());
}

public function testGetServerUriWithHttps()
Expand All @@ -141,6 +141,13 @@ public function testGetServerUriWithHttps()
$this->assertSame('https://myserver:123/mypath/', $this->endpoint->getServerUri());
}

public function testServerUriDoesNotContainCollectionSegment()
{
$this->endpoint->setHost('myserver')->setPath('/mypath')->setPort(123)->setCollection('mycollection');

$this->assertSame('http://myserver:123/mypath/', $this->endpoint->getServerUri());
}

public function testServerUriDoesNotContainCoreSegment()
{
$this->endpoint->setHost('myserver')->setPath('/mypath')->setPort(123)->setCore('mycore');
Expand Down

0 comments on commit fc91f53

Please sign in to comment.