【发布时间】:2019-04-17 20:46:44
【问题描述】:
只要我不尝试模拟数据库对象,我的单元测试就可以正常工作。我创建了一个工厂,并试图在我的一个测试中使用它。但是,我不断收到a could not find driver error。我查了几个堆栈答案,我的 php 版本是 7.1,所以不太确定是什么导致了错误。
这是我的测试课。
<?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);
}
}
在我的 phpunit 测试中
<env name="DB_CONNECTION" value="test_db"/>
<env name="DB_DATABASE" value=":memory:"/>
这是我不断收到的错误
Caused by
Doctrine\DBAL\Driver\PDOException: could not find driver
database.php 文件
// This database is ephemeral and used for testing purposes.
'test_db' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
],
【问题讨论】:
-
可以直接使用模型吗?没有工厂?
-
@adam nope,我尝试直接使用模型。
-
你能出示你的
config/database.php文件吗? -
@SteveChamaillard,我刚刚添加了 config/database.php。
-
@SteveChamaillard,谢谢,但现在我得到一个 PHP Startup: Unable to load dynamic library 'pdo_sqlite' 错误。
标签: laravel driver factory phpunit