PetroGromovo's avatar

Why running tests main mysql database is currupted ?

Working with mysql in laravel 8 app I make tests with controller:

<?php

namespace Tests\Feature;


use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;

class ItemsController extends TestCase
{
    use DatabaseMigrations;

    /** @test */
    public function index_test()
    {
        ...

and having “sqlite” in phpunit.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
    </testsuites>
    <coverage processUncoveredFiles="true">
        <include>
            <directory suffix=".php">./app</directory>
        </include>
    </coverage>
    <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>

I texpect that sqlite will be used, but running tests I see that my main mysql database is currupted

in config/database.php :

        'sqlite' => [
            'driver' => 'sqlite',
            'url' => env('DATABASE_URL'),
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],

I have no any sqlite parameters inb my .env, I suppose with DB_CONNECTION = sqlite I do not need any additive parameters in .env. What is wrong and how that can be checked ? In phpinfo output I see :

PDO
PDO support	enabled
PDO drivers	dblib, firebird, mysql, odbc, pgsql, sqlite


pdo_sqlite
PDO Driver for SQLite 3.x	enabled
SQLite Library	3.31.1


sqlite3
SQLite3 support	enabled
SQLite Library	3.31.1
Directive	Local Value	Master Value
sqlite3.defensive	On	On
sqlite3.extension_dir	no value	no value

Thanks in advance!

0 likes
2 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Maybe your config is cached. If it's cached, it will ignore both env and phpunit.xml

php artisan config:clear 
1 like

Please or to participate in this conversation.