How would you test the following code with phpUnit?
class Product {
protected $id = null;
public function __construct($id) {
$this->id = $id;
}
public function getDescription($language_id) {
$db_query = mysql_query("SELECT * FROM products_description WHERE products_id = " . (int) $this->id . " AND language = " . (int) $language_id);
return mysql_fetch_array($db_query);
}
}
$product = new Product(1);
$product->getDescription(1); // Test this
At the moment I test it like this:
public function testShouldGetProductsDescription() {
$product = new Product(1);
$description = $product->getDescription(1);
$expected_description = array(
'name' => 'car',
'short_text' => 'this is a car',
'long_text' => 'longer description for the car'
);
$this->assertEquals($description, $expected_description);
}
But it doesn't seem to be a good solution for me. (This code is only a example and might not work correctly)