laravelphpunitlaragon

Laravel and PHPUnit: could not find driver (SQL: PRAGMA foreign_keys = ON;)


I have run my Laravel application with PHPUnit.

Everything is fine until at some point, when I run my test again, it turns out with this error.

Illuminate\Database\QueryException: could not find driver (SQL: PRAGMA foreign_keys = ON;)

Enter image description here

Caused by PDOException: could not find driver

Here's my phpunit.xml file:

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
     bootstrap="vendor/autoload.php"
     colors="true">

    <testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <server name="APP_ENV" value="testing"/>
        <server name="BCRYPT_ROUNDS" value="4"/>
        <server name="CACHE_DRIVER" value="array"/>
        <server name="DB_CONNECTION" value="sqlite"/>
        <server name="DB_DATABASE" value=":memory:"/>
        <server name="MAIL_MAILER" value="array"/>
        <server name="QUEUE_CONNECTION" value="sync"/>
        <server name="SESSION_DRIVER" value="array"/>
        <server name="TELESCOPE_ENABLED" value="false"/>
    </php>
</phpunit>

How can I fix this error in Laravel 6 and PHPUnit?


Solution

  • This is actually happening after I upgraded my PHP version in Laragon. The solution is to enable pdo_sqlite in the PHP extension in Laragon.

    That's it. This answer was found on PHPUnit SQLite error after updating Laragon (PDOException: could not find driver).