minortechnologies's avatar

No Tables Specified Error Following Successful Test

I am running into a strange error when unit testing my Lumen 5.5 application. The message I am getting in the console is:

Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no tables specified (SQL: select * where "batch" = batch order by "migration" desc).

Note: I am using DatabaseMigrations in the test class and I am also using a sqlite database for testing.

Here is my phpunit.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="bootstrap/app.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false"
         syntaxCheck="false">
    <testsuites>
        <testsuite name="Application Test Suite">
            <directory suffix="Test.php">./tests</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
        <env name="DB_CONNECTION" value="sqlite" />
        <!-- <env name="DB_DATABASE" value=":memory:"/> -->
    </php>
</phpunit>

Here is my database.php config file:

'sqlite' => [
    'driver' => 'sqlite',
    'database' => database_path('database.sqlite'),
    'prefix' => '',
]

Here is my TestCase.php file:

<?php

abstract class TestCase extends Laravel\Lumen\Testing\TestCase
{
    /**
     * Creates the application.
     *
     * @return \Laravel\Lumen\Application
     */
    public function createApplication()
    {
        return require __DIR__.'/../bootstrap/app.php';
    }
}

Here is my actual unit test:

<?php

namespace Tests\Unit\Controllers;

use Laravel\Lumen\Testing\DatabaseMigrations;
use Laravel\Lumen\Testing\DatabaseTransactions;
use TestCase;

class WaterTestsControllerTest extends TestCase
{
    use DatabaseMigrations;

    /**
     * Test that the index method fails for an unauthenticated user.
     *
     * @return void
     */
    public function testIndexMethodFailsForUnauthenticatedGuests()
    {
        $response = $this->call('POST', '/api/water-testing/test', []);

        $responseContent = json_decode($response->getContent());

        $this->assertEquals(401, $response->status());
        $this->seeJsonEquals(['Unauthorized.']);
    }
}

I have created the database.sqlite file within my database folder and it is receiving data from other tests. The error mentioned above is generated after a test runs successfully. Instead of returning green, it throws the error in question. Anybody have this happen to them before?

0 likes
1 reply
minortechnologies's avatar

I resolved this by altering my TestCase.php file as below:

<?php

abstract class TestCase extends Laravel\Lumen\Testing\TestCase
{
    /**
     * Creates the application.
     *
     * @return \Laravel\Lumen\Application
     */
    public function createApplication()
    {
        return require __DIR__.'/../bootstrap/app.php';
    }

    public function setUp()
    {
        parent::setUp();
        $this->createApplication();
    }

    public function tearDown()
    {
        //
    }
}

Please or to participate in this conversation.