Listing 3.6 shows the initial testing of our models, although
at this stage we do not have much to test!
Listing 3.6: Places model unit test
class PlacesTest extends PHPUnit_Framework_TestCase
{
public function setUp() |#1
{ |
// reset database to known state |
setupDatabase(); |
} |
public function testFetchAll()
Licensed to Menshu You
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
{
$placesFinder = new Places();
$places = $placesFinder->fetchAll();
$this->assertSame(3, $places->count()); #2
}
}
(annotation) <#1 setUp() is called before every test to ensure a clean slate.>
(annotation) <#2 Use assertSame to check we have the correct row count.>
A PHPUnit test case consists of a number of separate functions that contain each test. These function all
start with the word test, so that PHPUnit can identify them. The member function setUp() is run before each
test and so can be used to initialize the system for the test. This helps to ensure that each test is not dependant
upon any other test and also does not cause problems for subsequent tests. The function tearDown() also exists,
which is run after each test and so can be used for any cleanup required.
Pages:
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109