Laravel-如何在phpunit测试中设置伪造者区域设置?

Laravel-如何在phpunit测试中设置伪造者区域设置?,laravel,phpunit,faker,Laravel,Phpunit,Faker,我可以在config/app.php中将我的应用程序中的faker locale更改为pt_BR更改'faker_locale'=>'pt_BR',它在我的工厂中运行良好,但在我的测试用例中不起作用。这就是我在测试中导入faker的方式: namespace Tests\Unit; use Tests\TestCase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\RefreshD

我可以在config/app.php中将我的应用程序中的faker locale更改为pt_BR更改'faker_locale'=>'pt_BR',它在我的工厂中运行良好,但在我的测试用例中不起作用。这就是我在测试中导入faker的方式:

namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Models\Proprietario;

class ProprietarioTest extends TestCase
{
    use WithFaker, RefreshDatabase;


    public function testStore(){


        $attributes = [
            'name' => $this->faker->name,
            'email' => $this->faker->email,
            'address' => $this->faker->city,
            'phone' => $this->faker->cellPhoneNumber,
            'municipio' => $this->faker->randomDigit,
        ];
        $response = $this->post('/api/v1/proprietario', $attributes);

        $response->assertStatus(201);
        $createdArea = Proprietario::latest();
        $this->assertDatabaseHas('proprietarios', $attributes);
    }

测试将在$this->faker->cellPhoneNumber中失败,因为它在默认语言环境中不可用。我使用的是Laravel5.8和PHP7.2,WithFaker特性为您提供了一种可以使用的方法

$this->faker'nl_nl'->邮政编码//荷兰邮政编码 如果要在所有测试中使用它,请在测试中覆盖setupFaker

protected function setUpFaker()
{
    $this->faker = $this->makeFaker('nl_NL');
}

WithFaker特性为您提供了一种可以使用的方法

$this->faker'nl_nl'->邮政编码//荷兰邮政编码 如果要在所有测试中使用它,请在测试中覆盖setupFaker

protected function setUpFaker()
{
    $this->faker = $this->makeFaker('nl_NL');
}

你应该检查一下,看看WithFaker的特质给了你什么。您可能需要在自己的安装方法中修改faker实例。您应该检查并查看WithFaker特性为您提供了什么。您可能需要在自己的安装方法中修改faker实例。