php';
require_once "PHPUnit/Framework/TestSuite.php";
$suite = new PHPUnit_Framework_TestSuite();
$suite->addTestSuite("DBTester");
PHPUnit_TextUI_TestRunner::run($suite);
?>
Chapter 5
[ 123 ]
So what result will you get?
PHPUnit 3.0.5 by Sebastian Bergmann.
....
Time: 00:00
OK (4 tests)
However, these are basic functionality tests. We must make more versatile tests and
find out how our objects may fail. Let's add two more tests as shown below:
public function testInvalidUpdate()
{
$data = array("name"=>"afif","pass"=>md5("hello world"));
mysql_query("truncate table users");
$this->Db->insertData($data);
$data = array("name"=>"afif2","pass"=>md5("hello world"));
$result = $this->Db->updateData(2, $data);
$affected_rows = mysql_affected_rows($this->connection);
$this->assertEquals(0, $affected_rows);
}
public function testInvalidDelete()
{
$data = array("name"=>"afif","pass"=>md5("hello world"));
mysql_query("truncate table users");
$this->Db->insertData($data);
$result = $this->Db->deleteData("*");
$this->assertNotNull($result);
$affected_rows = mysql_affected_rows($this->connection);
$this->assertEquals(-1, $affected_rows);
}
Now if you run the test suite you will get the following result:
PHPUnit 3.
Pages:
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138