Prev | Current Page 162 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

12. I have separated the tests into two separate functions: one to test inserting and
one to test updating.
Listing 5.12: Initializing the database in setUp()
public function testInsert()
{
$users = new Users();
$newUser = $users->fetchNew(); #1
$newUser->first_name = 'Nick'; |#2
$newUser->last_name = 'Lo'; |
$newUser->username = 'nick'; |
$newUser->password = 'nick'; |
$newUser->email = 'nick@example.com'; |
$id = $newUser->save(); #3
$nick = $users->find($id)->current(); |#4
$this->assertSame(3, $nick->id); |
// check that the date_created has been filled in
$this->assertNotNull($nick->date_created); #5
// check that the date_updated has been filled in
$this->assertSame($nick->date_updated, $nick->date_created); #6
}
public function testUpdate()
{
$users = new Users();
$rob = $users->find(1)->current(); |#7
$rob->town = 'Worcester'; |
$rob->save(); |
$rob2 = $users->find(1)->current();
$this->assertTrue(($rob2->date_updated > $rob2->date_created)); #8
}
(annotation) <#1. Create a new empy row object.>
(annotation) <#2. Fill in some data.>
(annotation) <#3. Save the new obejct which will insert the data into the database. >
(annotation) <#4. Retrieve the newly inserted row and check it has the right id>
(annotation) <#5. Ensure the date_created field has been filled in>
(annotation) <#6.


Pages:
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
kompletacja zamówień banki jednoreki bandyta parasole reklamowe pisemne