fill($amount); } class NaturalGas implements IGas { private $content = 0.0; public fill($amount) { $this-‐>content += max(0, (float)$amount); } } class Oil { } class Engine { public function __construct(IGas $gas, Oil $oil) {} } čtvrtek, 25. července 13
Unit testing is about testing single class • Create mocks of IGas and Oil objects • Mock is dummy object which return defined values Original object Mock čtvrtek, 25. července 13
function multiplicationBy2($a) { return $a * 2; } } class FooTest extends \PHPUnit_Framework_TestCase { public function testMultiplicationBy2() { $subject = new Foo(); $result = $subject-‐>multiplicationBy2(2); $this-‐>assertEquals($result, 2); } } Using PHPUnit čtvrtek, 25. července 13