Slide 30
Slide 30 text
UNIT TESTING THE CURRENCY CONVERTER
PriceCalculator
CurrencyConverter
class AcmeApiCurrencyConverterTest extends \PHPUnit_Framework_TestCase
{
public function test_it_returns_the_original_price_if_no_conversion_
{
$price = new Price(200, new Currency('GBP'));
$targetCurrency = new Currency('GBP');
$acmeApi = $this->prophesize(AcmeApi::class);
$converter = new AcmeApiCurrencyConverter($acmeApi);
$actualPrice = $converter->convert($price, $targetCurrency);
$this->assertSame($price, $actualPrice);
}
public function test_it_calls_the_api_to_convert_the_currency()
{
$price = new Price(200, new Currency('GBP'));
$targetCurrency = new Currency('GBP');
$acmeApi = $this->prophesize(AcmeApi::class);
$acmeApi->convert(200, 'GBP', 'EUR')->willReturn(277);
$converter = new AcmeApiCurrencyConverter($acmeApi);
$actualPrice = $converter->convert($price, $targetCurrency);
$this->assertEquals(new Price(277, 'EUR'), $actualPrice);
}
}
ProductRepository
DoctrineProductRepository AcmeApiCurrencyConverter
GuzzleCurrencyConverter
AcmeApi