需要登录的测试方法



我想测试一些类似用户的方法(方法需要登录用户(。

$user = User::find(1);
$response = $this->actingAs($user)->json('POST', '/store/post', [
'title' => 'Hello World',
'description' => 'Hello World. We are Anonymous.',
'user_id' => 1
]);
$response
->assertStatus(201)
->assertJson([
'created' => true,
]);

我有这个错误(我不知道如何添加所有错误,所以我显示了部分错误(:

1) TestsFeatureExampleTest::testBasicExample
IlluminateDatabaseQueryException: could not find driver (SQL: PRAGMA foreign_keys = ON;)
//...
Caused by
DoctrineDBALDriverPDOException: could not find driver
//...
Caused by
PDOException: could not find driver

如果我试着在文档上使用Factory,我也会遇到同样的问题。我该如何解决我的问题?

我相信您正在使用sqlite来模拟PHPUnit中的数据库在php5 的情况下

sudo apt-get install php5-sqlite

在php7 的情况下

sudo apt-get install php7-sqlite

而不是重新启动apache服务器

sudo service apache2 restart

我认为您必须在应用程序中安装以下软件包。尝试运行

composer update
composer require doctrine/dbal

您可能还需要安装php-mysql扩展。

尝试运行

sudo apt-get install php-mysql.

最新更新