orchestral / testbench

Laravel Testing Helper for Packages Development
https://packages.tools/testbench
MIT License
2.1k stars 136 forks source link

It somehow forces to use MySQL for Job Batching #361

Closed askdkc closed 1 year ago

askdkc commented 1 year ago

Description:

Since testbench v8.3.0, the testbench-code/laravel/config/queue.php file contains the following code:

https://github.com/orchestral/testbench-core/blob/6f83101da503e5ecbb63a42f3533f91cecf64a04/laravel/config/queue.php#L87-L90

Testbench is supposed to use SQLite as its default database for testing, but it seems to be ignoring this and using MySQL for job batching regardless.

Steps To Reproduce:

It might be easier to provide a package that includes job batching tests, so please allow me to use my package. You can find my package at:

https://github.com/askdkc/livewire-csv

To use it, simply clone the repository and follow these steps:

cd livewire-csv
composer install
./vendor/bin/pest

It will output something like this (See strange Connection: mysql outputs):

 • Tests\CsvImporterTest > it can handled none required column even when column is empty
   Illuminate\Database\QueryException 

  SQLSTATE[HY000] [2002] Connection refused (Connection: mysql, SQL: insert into `job_batches` 

Now you edit the vendor/orchestra/testbench-core/laravel/config/queue.php and comment out follwoing.

     'batching' => [
         'database' => env('DB_CONNECTION', 'mysql'),
         'table' => 'job_batches',
     ],

to

    // 'batching' => [
    //     'database' => env('DB_CONNECTION', 'mysql'),
    //     'table' => 'job_batches',
    // ],

Then run ./vendor/bin/pest again. This time test passes perfectly.

Is there any way to fix testbench to use SQLite for Job Batching?

crynobone commented 1 year ago

Testbench is supposed to use SQLite as its default database for testing, but it seems to be ignoring this and using MySQL for job batching regardless.

This is incorrect, Testbench depends on DB_CONNECTION value for the default database connection.

Also suggested in the documentation: https://packages.tools/testbench/getting-started/configuration.html#in-memory-sqlite-connection

askdkc commented 1 year ago

@crynobone

This is incorrect, Testbench depends on DB_CONNECTION value for the default database connection.

Oops. Thank you for clarifying this.

I added following and run the test again, and it worked without any errors.

    <php>
        <env name="DB_CONNECTION" value="testing"/>
    </php>