0
我有一些使用mysqli的數據庫類。例如:用phpunit sqlite內存數據庫測試mysqli數據庫類
class MyDB
{
function __construct($db)
{
$this->db = $db;
}
function add($name)
{
$sql = "INSERT INTO mytable (name) VALUES ('$name');"
$this->db->query($sql);
if ($this->db->affected_rows) {
return $this->db->insert_id;
}
return 0;
}
...
我想用phpunit測試它們,使用sqlite內存數據庫。然而,正如所料,我得到這個錯誤:
Undefined property: PDO::$affected_rows
根據文檔:
PDO is only required for the fixture clean- and set-up and for assertions. You can use whatever database abstraction you want inside your own code.
我懷疑這只是意味着我必須創造一個mysqli的一個包裝,是與PDO兼容。或者有沒有一種方法可以測試我的代碼而無需將其轉換爲使用PDO?