mercredi 1 novembre 2017

phpunit test methods that take data from db

in my app I have a special class to work with DB. And I have methods that SELECT data from BD and return the result as an array. But when I try to cover this methods with PHPUnit, I always have NULL in return.

here is my piece of code

public function getData($id) {
    $selectQuery = $dataBase->query('SELECT * FROM table WHERE id = :id');
    $selectQery->bindInt(':id', $id);
    $selectQuery->execute();

    $result = $selectQuery->toArray();

    return $result;
}

before getting result I can see with debuger that SQL query is ok, ID is binded and the method has to return an array. and it returns if to run the method in my app. But the test gives NULL result.

How can I cove this method with tests?

Aucun commentaire:

Enregistrer un commentaire