Tutorial by Examples

Let's say, we have a simple LoginForm class with rules() method (used in login page as framework template): class LoginForm { public $email; public $rememberMe; public $password; /* rules() method returns an array with what each field has as a requirement. * Login form u...
Test methods often need data to be tested with. To test some methods completely you need to provide different data sets for every possible test condition. Of course, you can do it manually using loops, like this: ... public function testSomething() { $data = [...]; foreach($data as $dat...
Let's say you want to test method which throws an exception class Car { /** * @throws \Exception */ public function drive() { throw new \Exception('Useful message', 1); } } You can do that by enclosing the method call into a try/catch block and making a...

Page 1 of 1