I have some database classes that are using mysqli. For example:
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;
}
...
I would like to test them with phpunit, using an sqlite in-memory database. However, as expected, I get this error:
Undefined property: PDO::$affected_rows
According to the documentation:
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.
I suspect that just means that I have to create a wrapper for mysqli that is compatible with PDO. Or is there a way I can test my code without converting it to use PDO?