Skip to content

Commit

Permalink
adds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gutocf committed May 29, 2022
1 parent f06fe89 commit 37e147e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/Exception/AbstractHttpExceptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Gutocf\BrasilAPI\Tests\Exception;

use Gutocf\BrasilAPI\Exception\AbstractHttpException;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\TestCase;

class AbstractHttpExceptionTest extends TestCase
{
public function testGetOriginalMessage(): void
{
$response = new Response(404, [], '{"name":"Not Found"}');
$exception = $this->getMockForAbstractClass(AbstractHttpException::class, [
$response, 404
]);
$originalMessage = $exception->getOriginalMessage();
$this->assertEquals('Not Found', $originalMessage->name);
}
}
13 changes: 13 additions & 0 deletions tests/Service/V1/IbgeServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ public function testGetCitiesByStateNotFound(): void
$ibgeService->getCitiesByState('invalid');
}

public function testGetAllStates(): void
{
$data = loadFixture('Entity/V1/Ibge/states');
$mock = new MockHandler([
new Response(200, [], strval(json_encode($data))),
]);
$handlerStack = HandlerStack::create($mock);
$ibgeService = new IbgeService(new Adapter(new Client(['handler' => $handlerStack])));

$states = $ibgeService->getAllStates();
$this->assertInstanceOf(State::class, $states[0]);
}

public function testGetState(): void
{
$data = loadFixture('Entity/V1/Ibge/states');
Expand Down

0 comments on commit 37e147e

Please sign in to comment.