@@ -86,6 +86,86 @@ public function it_fetches_a_historical_rate()
8686 $ this ->assertSame ($ pair , $ rate ->getCurrencyPair ());
8787 }
8888
89+ /**
90+ * @test
91+ */
92+ public function it_fetches_uses_a_specific_source_option ()
93+ {
94+ $ pair = CurrencyPair::createFromString ('EUR/AUD ' );
95+ $ uri = 'https://api.exchangerate.host/2000-01-03?base=EUR&source=ecb ' ;
96+ $ content = file_get_contents (__DIR__ .'/../../Fixtures/Service/ExchangerateHost/historical.json ' );
97+ $ date = new \DateTime ('2000-01-03 ' );
98+
99+ $ service = new ExchangerateHost ($ this ->getHttpAdapterMock ($ uri , $ content ), null , ['source ' => 'ecb ' ]);
100+
101+ $ rate = $ service ->getExchangeRate (new HistoricalExchangeRateQuery ($ pair , $ date ));
102+
103+ $ this ->assertEquals (1.5346 , $ rate ->getValue ());
104+ $ this ->assertEquals ($ date , $ rate ->getDate ());
105+ $ this ->assertEquals ('exchangeratehost ' , $ rate ->getProviderName ());
106+ $ this ->assertSame ($ pair , $ rate ->getCurrencyPair ());
107+ }
108+
109+ /**
110+ * @test
111+ */
112+ public function it_fetches_uses_a_specific_source_option_overridden_by_exchange_query_method ()
113+ {
114+ $ pair = CurrencyPair::createFromString ('EUR/AUD ' );
115+ $ uri = 'https://api.exchangerate.host/2000-01-03?base=EUR&source=testing ' ;
116+ $ content = file_get_contents (__DIR__ .'/../../Fixtures/Service/ExchangerateHost/historical.json ' );
117+ $ date = new \DateTime ('2000-01-03 ' );
118+
119+ $ service = new ExchangerateHost ($ this ->getHttpAdapterMock ($ uri , $ content ), null , ['source ' => 'ecb ' ]);
120+
121+ $ rate = $ service ->getExchangeRate (new HistoricalExchangeRateQuery ($ pair , $ date , ['source ' => 'testing ' ]));
122+
123+ $ this ->assertEquals (1.5346 , $ rate ->getValue ());
124+ $ this ->assertEquals ($ date , $ rate ->getDate ());
125+ $ this ->assertEquals ('exchangeratehost ' , $ rate ->getProviderName ());
126+ $ this ->assertSame ($ pair , $ rate ->getCurrencyPair ());
127+ }
128+
129+ /**
130+ * @test
131+ */
132+ public function it_fetches_uses_a_specific_places_option_overridden_by_exchange_query_method ()
133+ {
134+ $ pair = CurrencyPair::createFromString ('EUR/AUD ' );
135+ $ uri = 'https://api.exchangerate.host/2000-01-03?base=EUR&places=10 ' ;
136+ $ content = file_get_contents (__DIR__ .'/../../Fixtures/Service/ExchangerateHost/historical.json ' );
137+ $ date = new \DateTime ('2000-01-03 ' );
138+
139+ $ service = new ExchangerateHost ($ this ->getHttpAdapterMock ($ uri , $ content ), null , ['places ' => 6 ]);
140+
141+ $ rate = $ service ->getExchangeRate (new HistoricalExchangeRateQuery ($ pair , $ date , ['places ' => 10 ]));
142+
143+ $ this ->assertEquals (1.5346 , $ rate ->getValue ());
144+ $ this ->assertEquals ($ date , $ rate ->getDate ());
145+ $ this ->assertEquals ('exchangeratehost ' , $ rate ->getProviderName ());
146+ $ this ->assertSame ($ pair , $ rate ->getCurrencyPair ());
147+ }
148+
149+ /**
150+ * @test
151+ */
152+ public function it_fetches_uses_a_specific_places_option ()
153+ {
154+ $ pair = CurrencyPair::createFromString ('EUR/AUD ' );
155+ $ uri = 'https://api.exchangerate.host/2000-01-03?base=EUR&places=6 ' ;
156+ $ content = file_get_contents (__DIR__ .'/../../Fixtures/Service/ExchangerateHost/historical.json ' );
157+ $ date = new \DateTime ('2000-01-03 ' );
158+
159+ $ service = new ExchangerateHost ($ this ->getHttpAdapterMock ($ uri , $ content ), null , ['places ' => 6 ]);
160+
161+ $ rate = $ service ->getExchangeRate (new HistoricalExchangeRateQuery ($ pair , $ date ));
162+
163+ $ this ->assertEquals (1.5346 , $ rate ->getValue ());
164+ $ this ->assertEquals ($ date , $ rate ->getDate ());
165+ $ this ->assertEquals ('exchangeratehost ' , $ rate ->getProviderName ());
166+ $ this ->assertSame ($ pair , $ rate ->getCurrencyPair ());
167+ }
168+
89169 /**
90170 * @test
91171 */
0 commit comments