Skip to content

Commit

Permalink
stop using JsonVatClient in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvankooten committed Apr 17, 2020
1 parent ecf8316 commit 70de835
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
1 change: 0 additions & 1 deletion tests/ClientsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function testClient(Client $client)

public function clientProvider()
{
yield [new JsonVatClient()];
yield [new IbericodeVatRatesClient()];
}
}
23 changes: 11 additions & 12 deletions tests/RatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Ibericode\Vat\Tests;

use Ibericode\Vat\Clients\ClientException;
use Ibericode\Vat\Clients\IbericodeVatRatesClient;
use Ibericode\Vat\Clients\JsonVatClient;
use Ibericode\Vat\Exception;
use Ibericode\Vat\Period;
Expand All @@ -19,10 +20,12 @@ public function setUp() : void
}
}

private function getJsonVatMock()
private function getRatesClientMock()
{
$client = $this->getMockBuilder(JsonVatClient::class)->getMock();
$client = $this->getMockBuilder(IbericodeVatRatesClient::class)
->getMock();
$client
->expects($this->once())
->method('fetch')
->willReturn([
'NL' => [
Expand All @@ -41,23 +44,19 @@ private function getJsonVatMock()
]
]);

$client
->expects($this->once())
->method('fetch');

return $client;
}

public function testGetRateForCountry()
{
$client = $this->getJsonVatMock();
$client = $this->getRatesClientMock();
$rates = new Rates('vendor/rates', 30, $client);
$this->assertEquals(21.0, $rates->getRateForCountry('NL'));
}

public function testGetRateForCountryOnDate()
{
$client = $this->getJsonVatMock();
$client = $this->getRatesClientMock();
$rates = new Rates('vendor/rates', 30, $client);
$this->assertEquals(19.0, $rates->getRateForCountryOnDate('NL', new \DateTime('2011/01/01')));
$this->assertEquals(6.0, $rates->getRateForCountryOnDate('NL', new \DateTime('2018/01/01'), 'reduced'));
Expand All @@ -68,15 +67,15 @@ public function testGetRateForCountryOnDate()

public function testGetRateForCountryWithInvalidCountryCode()
{
$client = $this->getJsonVatMock();
$client = $this->getRatesClientMock();
$rates = new Rates('vendor/rates', 30, $client);
$this->expectException(Exception::class);
$rates->getRateForCountry('FOO');
}

public function testRatesAreLoadedFromFile()
{
$client = $this->getJsonVatMock();
$client = $this->getRatesClientMock();
$rates = new Rates('vendor/rates', 30, $client);
$this->assertEquals(21.0, $rates->getRateForCountry('NL'));

Expand All @@ -95,12 +94,12 @@ public function testRatesAreLoadedFromFile()
public function testRatesAreLoadedFromFileOnClientException()
{
// first, populate local file
$client = $this->getJsonVatMock();
$client = $this->getRatesClientMock();
$rates = new Rates('vendor/rates', 10, $client);
$this->assertEquals(21.0, $rates->getRateForCountry('NL'));

// then, perform test
$client = $this->getJsonVatMock();
$client = $this->getRatesClientMock();
$client->method('fetch')->willThrowException(new ClientException('Service is down'));
$rates = new Rates('vendor/rates', -1, $client);
$this->assertEquals(21.0, $rates->getRateForCountry('NL'));
Expand Down

0 comments on commit 70de835

Please sign in to comment.