1

When executing tests separately I have added this functions to make sure sqlite db would be created if it's not there:

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication, DatabaseMigrations;

    public function setUp(): void
    {
        $this->initializeTestDB();
        parent::setUp();
        Notification::fake();

        if ($this->tenancy) {
            $this->initializeTenancy();
        }
    }

    public function initializeTestDB(): void
    {
        $dbname = env('DB_DATABASE');
        $filePath= "./" . $dbname;
        if (!file_exists($filePath)) {
            touch($filePath);
        }
    }

But this does not help when using php artisan test --parallel. I have tried to move this method into AppServiceProvider as in the documentation. Also didn't helped:

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        ParallelTesting::setUpProcess(function ($token) {
            $this->handleTestDB();
        });

Any ideas to handle this properly for both parallel and separate tests ?

mirza
  • 5,685
  • 10
  • 43
  • 73
  • What does "it does not work" mean in context of your question? How does it fail? Silently or with an error? Does it fail at all or are you just not confident with the result? What have you expected instead? – hakre Jun 25 '21 at 13:56
  • I thought it was pretty self-explanatory. The case is when not having a sqlite file the test is failing due to missing db. The expected solution is being able to start tests without creating the file first, it supposed to be created during test execution. – mirza Jun 29 '21 at 11:11

0 Answers0