3
3
namespace Ibericode \Vat \Tests ;
4
4
5
5
use Ibericode \Vat \Clients \ClientException ;
6
+ use Ibericode \Vat \Clients \IbericodeVatRatesClient ;
6
7
use Ibericode \Vat \Clients \JsonVatClient ;
7
8
use Ibericode \Vat \Exception ;
8
9
use Ibericode \Vat \Period ;
@@ -19,10 +20,12 @@ public function setUp() : void
19
20
}
20
21
}
21
22
22
- private function getJsonVatMock ()
23
+ private function getRatesClientMock ()
23
24
{
24
- $ client = $ this ->getMockBuilder (JsonVatClient::class)->getMock ();
25
+ $ client = $ this ->getMockBuilder (IbericodeVatRatesClient::class)
26
+ ->getMock ();
25
27
$ client
28
+ ->expects ($ this ->once ())
26
29
->method ('fetch ' )
27
30
->willReturn ([
28
31
'NL ' => [
@@ -41,23 +44,19 @@ private function getJsonVatMock()
41
44
]
42
45
]);
43
46
44
- $ client
45
- ->expects ($ this ->once ())
46
- ->method ('fetch ' );
47
-
48
47
return $ client ;
49
48
}
50
49
51
50
public function testGetRateForCountry ()
52
51
{
53
- $ client = $ this ->getJsonVatMock ();
52
+ $ client = $ this ->getRatesClientMock ();
54
53
$ rates = new Rates ('vendor/rates ' , 30 , $ client );
55
54
$ this ->assertEquals (21.0 , $ rates ->getRateForCountry ('NL ' ));
56
55
}
57
56
58
57
public function testGetRateForCountryOnDate ()
59
58
{
60
- $ client = $ this ->getJsonVatMock ();
59
+ $ client = $ this ->getRatesClientMock ();
61
60
$ rates = new Rates ('vendor/rates ' , 30 , $ client );
62
61
$ this ->assertEquals (19.0 , $ rates ->getRateForCountryOnDate ('NL ' , new \DateTime ('2011/01/01 ' )));
63
62
$ this ->assertEquals (6.0 , $ rates ->getRateForCountryOnDate ('NL ' , new \DateTime ('2018/01/01 ' ), 'reduced ' ));
@@ -68,15 +67,15 @@ public function testGetRateForCountryOnDate()
68
67
69
68
public function testGetRateForCountryWithInvalidCountryCode ()
70
69
{
71
- $ client = $ this ->getJsonVatMock ();
70
+ $ client = $ this ->getRatesClientMock ();
72
71
$ rates = new Rates ('vendor/rates ' , 30 , $ client );
73
72
$ this ->expectException (Exception::class);
74
73
$ rates ->getRateForCountry ('FOO ' );
75
74
}
76
75
77
76
public function testRatesAreLoadedFromFile ()
78
77
{
79
- $ client = $ this ->getJsonVatMock ();
78
+ $ client = $ this ->getRatesClientMock ();
80
79
$ rates = new Rates ('vendor/rates ' , 30 , $ client );
81
80
$ this ->assertEquals (21.0 , $ rates ->getRateForCountry ('NL ' ));
82
81
@@ -95,12 +94,12 @@ public function testRatesAreLoadedFromFile()
95
94
public function testRatesAreLoadedFromFileOnClientException ()
96
95
{
97
96
// first, populate local file
98
- $ client = $ this ->getJsonVatMock ();
97
+ $ client = $ this ->getRatesClientMock ();
99
98
$ rates = new Rates ('vendor/rates ' , 10 , $ client );
100
99
$ this ->assertEquals (21.0 , $ rates ->getRateForCountry ('NL ' ));
101
100
102
101
// then, perform test
103
- $ client = $ this ->getJsonVatMock ();
102
+ $ client = $ this ->getRatesClientMock ();
104
103
$ client ->method ('fetch ' )->willThrowException (new ClientException ('Service is down ' ));
105
104
$ rates = new Rates ('vendor/rates ' , -1 , $ client );
106
105
$ this ->assertEquals (21.0 , $ rates ->getRateForCountry ('NL ' ));
0 commit comments