単純なDatamapperクラスのテストを作成していて、メソッドが機能していることはわかっていますが、テストが失敗してエラーが発生します " Fatal error: Call to a member function fetchAll() on a non-object in C:\xampp\htdocs\Call log\tests\model_tests.php on line 13.
"明らかに、メソッドが機能することを確認できるため、これは正しくありません。
エラーが発生していると思われるコードは次のとおりです。
function all() {
$calls = $this->pdo->query('SELECT * from calls');
return $calls->fetchAll();
}
これが私のテストコードです:
class TestOfCallMapper extends UnitTestCase {
function testOfReturnsAll() {
$this->createSchema();
$mapper = Callmapper::getInstance();
$results = $mapper->all();
print_r($results);
}
private function createSchema() {
$mapper = CallMapper::getInstance();
$mapper->pdo->exec(file_get_contents('../database/create_schema.sql'));
}
private function destroySchema() {
$mapper = CallMapper::getInstance();
$mapper->pdo->exec(file_get_contents('../database/destroy_schema.sql'));
}
}
$test = new TestOfCallMapper('Test of CallMapper Methods');
$test->run(new HTMLReporter());
私がこれを行う場合、それはうまく機能します:
$mapper = CallMapper::getInstance();
$test = $mapper->all();
print_r($test->fetchAll());