3

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?

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
  • Did you ever find a solution for this? – DazBaldwin Feb 08 '19 at 14:11
  • @DazBaldwin I think the error was from the test data set not populating the table correctly with a request_id of 1, causing no rows to be selected in the query when run in the test. But I am not 100% sure about this. – rink.attendant.6 Feb 08 '19 at 16:08
  • Thanks for the response. I think I was struggling because the versions differ quite a lot and the docs are a little all over the place. I managed to get it working, as you said, I think the issue may have been the .yml file. – DazBaldwin Feb 11 '19 at 10:00

0 Answers0