for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Tests;
use CurrencyConverter\Rates;
class RatesTest extends \PHPUnit\Framework\TestCase
{
public function testReturnsZeroWheneverApiProvideEmptyResponse()
$this->apiCaller = $this
apiCaller
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
->getMockBuilder('CurrencyConverter\ApiCaller')
->disableOriginalConstructor()
->getMock();
$this->rates = new Rates($this->apiCaller);
rates
$this->apiCaller->expects($this->once())
->method('convert')
->with('FOO', 'BAR');
->method('isLastCallEmpty')
->willReturn(true);
$result = $this->rates->getRates('FOO', 'BAR');
$this->assertEquals(0, $result);
}
public function testReturnRates()
$from = 'FOO';
$to = 'BAR';
$expected = 100;
->willReturn(false);
->method('getLastResponse')
->willReturn(json_encode([$from . '_' . $to => $expected]));
$result = $this->rates->getRates($from, $to);
$this->assertEquals($expected, $result);
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: