Skip to content

Commit

Permalink
Write all accessors unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaujard-pg committed Jan 17, 2019
1 parent dc207eb commit 2b31306
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 8 deletions.
3 changes: 2 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="tmp/coverage.xml"/>
<log type="coverage-clover" target="./tmp/coverage.xml"/>
<log type="coverage-html" target="./tmp/report"/>
</logging>
</phpunit>
13 changes: 9 additions & 4 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

class Api
{
const SOURCE_DEFAULT = 'default';

const SOURCE_OUTDOOR = 'outdoor';

/** @var \GuzzleHttp\Client */
private $client;

Expand Down Expand Up @@ -194,10 +198,11 @@ public function setHeading(int $heading): self
*/
public function setSource(string $source): self
{
if ($source !== 'default' || $source !== 'outdoor') {
throw new UnexpectedValueException(
'Source value is unknown, "default" or "outdoor" values expected.'
);
if (!in_array($source, [self::SOURCE_DEFAULT, self::SOURCE_OUTDOOR], true)) {
throw new UnexpectedValueException(sprintf(
'Source value "%s" is unknown, only "%s" or "%s" values expected.',
$source, self::SOURCE_DEFAULT, self::SOURCE_OUTDOOR
));
}

$this->source = $source;
Expand Down
98 changes: 97 additions & 1 deletion tests/StreetViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Defro\Google\StreetView\Tests;

use Defro\Google\StreetView\Exception\UnexpectedStatusException;
use Defro\Google\StreetView\Exception\UnexpectedValueException;
use GuzzleHttp\Client;
use Defro\Google\StreetView\Api;

Expand Down Expand Up @@ -41,7 +42,7 @@ public function testGetMetadata()
$this->assertArrayHasKey('panoramaId', $result);
}

public function testGetMetadataExceptions()
public function testGetMetadataStatusException()
{
$this->expectException(UnexpectedStatusException::class);
$this->streetView->getMetadata('A place where I will got an error');
Expand All @@ -65,4 +66,99 @@ public function testGetImageUrlByPanoramaId()
$this->assertStringStartsWith('https://', $result);
}

public function testSetImageWidth()
{
$result = $this->streetView->setImageWidth(42);
$this->assertSame(get_class($result), Api::class);
}

public function testSetImageWidthException()
{
$this->expectException(UnexpectedValueException::class);
$this->streetView->setImageWidth(0);
}

public function testSetImageHeight()
{
$result = $this->streetView->setImageHeight(42);
$this->assertSame(get_class($result), Api::class);
}

public function testSetImageHeightException()
{
$this->expectException(UnexpectedValueException::class);
$this->streetView->setImageHeight(0);
}

public function testSetSource()
{
$result = $this->streetView->setSource(Api::SOURCE_DEFAULT);
$this->assertSame(get_class($result), Api::class);
}

public function testSetSourceException()
{
$this->expectException(UnexpectedValueException::class);
$this->streetView->setSource('unknownSource');
}

public function testSetHeading()
{
$result = $this->streetView->setHeading(42);
$this->assertSame(get_class($result), Api::class);
}

public function testSetHeadingFirstException()
{
$this->expectException(UnexpectedValueException::class);
$this->streetView->setHeading(-42);
}

public function testSetHeadingSecondException()
{
$this->expectException(UnexpectedValueException::class);
$this->streetView->setHeading(420);
}

public function testSetRadius()
{
$result = $this->streetView->setRadius(42);
$this->assertSame(get_class($result), Api::class);
}

public function testSetRadiusException()
{
$this->expectException(UnexpectedValueException::class);
$this->streetView->setRadius(-42);
}

public function testSetCameraPitch()
{
$result = $this->streetView->setCameraPitch(42);
$this->assertSame(get_class($result), Api::class);
}

public function testSetCameraPitchFirstException()
{
$this->expectException(UnexpectedValueException::class);
$this->streetView->setCameraPitch(-100);
}

public function testSetCameraPitchSecondException()
{
$this->expectException(UnexpectedValueException::class);
$this->streetView->setCameraPitch(100);
}

public function testSetCameraFov()
{
$result = $this->streetView->setCameraFov(42);
$this->assertSame(get_class($result), Api::class);
}

public function testSetCameraFovException()
{
$this->expectException(UnexpectedValueException::class);
$this->streetView->setCameraFov(150);
}
}
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ protected function setUp()
$this->loadEnvironmentVariables();
}

protected function loadEnvironmentVariables()
protected function loadEnvironmentVariables(): void
{
if (! file_exists(__DIR__.'/../.env')) {
if (!file_exists(__DIR__.'/../.env')) {
return;
}

Expand Down

0 comments on commit 2b31306

Please sign in to comment.