在一些PHPUnit测试用例中,我试图在每次测试之前重新创建数据库.我使用的是Laravel 5.3.以下是测试用例:

class CourseTypesTest extends TestCase
{
    public function setUp()
    {
        parent::setUp();
        Artisan::call('migrate');
        Artisan::call('db:seed', ['--class' => 'TestDatabaseSeeder ', '--database' => 'testing']);
    }

    /**
     * A basic functional test example.
     *
     * @return void
     */
    public function test_list_course_types()
    {
        $httpRequest = $this->json('GET', '/api/course-types');
        $httpRequest->assertResponseOk();
        $httpRequest->seeJson();

    }

    public function tearDown()
    {
        Artisan::call('migrate:reset');
        parent::tearDown();
    }
}

运行phpunit失败,并出现错误:

$phpunit phpunit 5.7.5由塞巴斯蒂安·伯格曼和贡献者 compose .

E 1 / 1 (100%)

时间:2.19秒,内存:12.00MB

有一个错误:

1) CourseTyPestTest::test_list_course_types ReflectionException:类

D:\www\learn-laravel\my-folder-api\vendor\laravel\framework\src\Illuminate\Container\Container.php:749 D:\www\learn-laravel\my-folder-api\vendor\laravel\framework\src\Illuminate\Container\Container.php:644 D:\www\learn-laravel\my-folder-api\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:709 D:\www\learn-laravel\my-folder-api\vendor\laravel\framework\src\Illuminate\Database\Console\Seeds\SeedCommand.php:74 D:\www\learn-laravel\my-folder-api\vendor\laravel\framework\src\Illuminate\Database\Console\Seeds\SeedCommand.php:63 D:\www\learn-laravel\my-folder-api\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php:2292 D:\www\learn-laravel\my-folder-api\vendor\laravel\framework\src\Illuminate\Database\Console\Seeds\SeedCommand.php:64 D:\www\learn-laravel\my-folder-api\vendor\laravel\framework\src\Illuminate\Container\Container.php:508 D:\www\learn-laravel\my-folder-api\vendor\laravel\framework\src\Illuminate\Console\Command.php:169 D:\www\learn-laravel\my-folder-api\vendor\symfony\console\Command\Command.php:254 D:\www\learn-laravel\my-folder-api\vendor\laravel\framework\src\Illuminate\Console\Command.php:155 D:\www\learn-laravel\my-folder-api\vendor\symfony\console\Application.php:821 D:\www\learn-laravel\my-folder-api\vendor\symfony\console\Application.php:187 D:\www\learn-laravel\my-folder-api\vendor\symfony\console\Application.php:118 D:\www\learn-laravel\my-folder-api\vendor\laravel\framework\src\Illuminate\Console\Application.php:107 D:\www\learn-laravel\my-folder-api\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php:218 D:\www\learn-laravel\my-folder-api\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:237 D:\www\learn-laravel\my-folder-api\tests\rest\CourseTypesTest.php:17

错误!测试:1,断言:0,错误:1.

but this class exists:
TestDatabaseSeeder inside database/seeds

推荐答案

The problem is empty space in your --class argument. If you take close look at array '--class' => 'TestDatabaseSeeder ' there is space in the end ... this is the problem. Change it to '--class' => 'TestDatabaseSeeder' and it should work fine.

Laravel相关问答推荐

如何重置laravel ui密码

在 Laravel 中排序的集合在 Vue 中突然不再排序

Laravel 数据未传递到下拉框

将 ID 传递给资源控制器进行编辑

如何从@foreach 循环中捕获所有数据并将其传递给 值? - Laravel

前端和管理员分开时未加载laravel 9中间件

Laravel - 出于某种原因,max 打破了我的查询

具有实时和 WebSockets 的 Angular2 + Laravel

Laravel - 验证 - 如果字段为空则需要

使用 Laravel Socialite 登录 Facebook

Laravel Electron邮件验证模板位置

你如何在自定义 Laravel Nova 工具中使用确认对话?

不支持驱动Driver[] - Laravel 5.3

如何处理 laravel 5 中的私有图像?

在 AWS 上找不到 Laravel 5 类Collective\Html\HtmlServiceProvider

如何在 Laravel 中实现数组类型路由?

Laravel 存储文件的公共 url

向 Laravel 重定向添加一个锚点

开发中的 Laravel 和视图缓存 - 无法立即看到更改

Laravel Eloquent 多对多查询 whereIn