小编jim*_*o99的帖子

Laravel - 如何在PHPUnit测试中使用faker?

我在运行测试时给出了这个错误:

未定义的变量$ faker.

这是WithFaker文件.

https://github.com/laravel/framework/blob/5.5/src/Illuminate/Foundation/Testing/WithFaker.php

<?php

namespace Tests\Unit;

use App\User;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class LoginTest extends TestCase
{

    use WithFaker;

    /**
     * A basic test example.
     *
     * @return void
     */

    /** @test */
    public function test_example()
    {

        $user = User::create([
            'username' => $faker->firstName(),
        ]);

    }

}
Run Code Online (Sandbox Code Playgroud)

laravel laravel-5

24
推荐指数
3
解决办法
8596
查看次数

标签 统计

laravel ×1

laravel-5 ×1