Tutorial by Examples

Imagine that we have a class Math.php with logic of calculating of fiobanacci and factorial numbers. Something like this: <?php class Math { public function fibonacci($n) { if (is_int($n) && $n > 0) { $elements = array(); $elements[1] = 1; ...
Given a simple PHP class: class Car { private $speed = 0; public getSpeed() { return $this->speed; } public function accelerate($howMuch) { $this->speed += $howMuch; } } You can write a PHPUnit test which tests the behavior of the class unde...
The practice of replacing an object with a test double that verifies expectations, for instance asserting that a method has been called, is referred to as mocking. Lets assume we have SomeService to test. class SomeService { private $repository; public function __construct(Repository $r...
Class for which you will create unit test case. class Authorization { /* Observer so that mock object can work. */ public function attach(Curl $observer) { $this->observers = $observer; } /* Method for which we will create test */ public function postAuthorization($url, $met...

Page 1 of 1