I'm getting a very strange error when running a unit test:
PDOException : SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test.result' doesn't exist
/var/www/html/project1/rami/tests/Data/Models/DataImportTest.php:60
The test code in question (simplified to try to isolate the problem):
/**
* @covers \Project1\Rami\Data\Models\DataImport::insertData
*/
public function testInsertData(): void {
$this->object->insertData(1);
$sql = 'SELECT request_id
FROM requests
WHERE request_id = 1;';
$queryTable = $this->getConnection()->createQueryTable('result', $sql);
$expectedTable = $this->createArrayDataSet([
'result' => [
[
'request_id' => '1'
]
]
])->getTable('result');
static::assertTablesEqual($expectedTable, $queryTable);
}
What's even more strangely is that assertions in other tests that use assertTablesEqual
run and pass fine, it is only this test that is failing. PHPUnit appears to be introspecting a table on the database called "result" when creating the expected table (which does not exist on the database), but it doesn't do that for any of the other tests.
I have tried dropping the database and recreating it, reloading the dev/test environment (a Vagrant box), and even reprovisioning the Vagrant box with a fresh install of MariaDB, all without success.
Googling the error only shows Laravel related problems, with a small handful of similar problems in other PHP frameworks, but nothing related to testing.
The implementation works fine as far as I can tell, and running the query manually on the test database doesn't cause any error.
Any ideas?