11. setUp() & tearDown()
setUp() method is called before every test
case, which means that this method can be
called few times per one test class.
Similarly, tearDown() method is called after
every test case.
13. setUpBeforeClass() & tearDownAfterClass()
setUpBeforeClass() method is executed only once per
class, and even before object is constructed, and that is the
reason why it is marked as static public function.
Similarly, tearDownAfterClass() method is called after all
tests in class finish, and after last tearDown() method is
called.
15. @dataProvider()
A test method can accept arbitrary arguments. These
arguments are to be provided by a data provider method.
The data provider method to be used is specified using the
@dataProvider annotation.
17. @expectedException & @expectedExceptionMessage
The @expectedException annotation is used to test
whether an exception is thrown inside the tested code.
The @expectedExceptionMessage annotation lets you
make an assertion on the error message of an exception.
21. Be descriptive when writing test
cases.
public function testCreateReturnsTrue() { … }
public function testCaseOne() { … }
22. Make use of the PHPUnit’s built-in
methods.
$this->assertTrue($isValidStatus);
$this->assertEquals(true, $isValidStatus);
23. Try splitting up your test cases as
much as possible for the sake of
readability.
// Case 1
public function testCreateException() { … }
// Case 2
public function testCreateSuccess() { … }
// Case3
public function testCreateReturnsFalse() { … }