2

My unit tests work fine as long as I do not try to mock a DB object. I created a Factory and am trying to use it in one of my tests. However, I keep getting a could not find driver error. I have looked up a couple of stack answers and my version of php is 7.1, so not really sure what is causing the error.

Here is my testing class.

<?php
/**
 * Created by PhpStorm.
 */

namespace Tests\Unit\Helper\Results;

use Jobscan\Helper\Results\FormatHelper;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Jobscan\Models\Document\Cv;
use Tests\TestCase;

class FormatHelperTest extends TestCase
{
    public function testFindingsForUploadedDocxResume_whenFontTypeIsNotStandard_resultFontTypeShowsNegativeResult()
    {
        $cv = factory(Cv::class)->create([
            'content' => "Testing Test test",
        ]);
        dd($cv);



 }
}

In my phpunit test

<env name="DB_CONNECTION" value="test_db"/>
<env name="DB_DATABASE" value=":memory:"/>

This is the error I keep getting

 Caused by
 Doctrine\DBAL\Driver\PDOException: could not find driver

database.php file

 // This database is ephemeral and used for testing purposes.
        'test_db' => [
            'driver'   => 'sqlite',
            'database' => ':memory:',
            'prefix'   => '',
        ],
Aaron
  • 4,380
  • 19
  • 85
  • 141

2 Answers2

0

Define a setUp method in your test:

public function setUp()
{
    parent::setUp();
}
Adam Rodriguez
  • 1,850
  • 1
  • 12
  • 15
0

Your error means it doesn't find the sqlite driver within your PHP lib which means the extension is not properly loaded. Look into your php.ini file (find its path by doing : php --ini) and find :

extension=pdo_sqlite

If this is written as :

;extension=pdo_sqlite, then you should remove the ;.

Steve Chamaillard
  • 2,289
  • 17
  • 32