HardDrive's avatar

Localised Faker in Test - Laravel 5.5

Please can someone help me to use an en_GB instance of faker within tests. I have tried reading the docs but can only find examples of using Faker in Factories and not using WithFaker in a test like below. Here is an example of where I would like to implement it :)

<?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([
            'mob_no' => $faker-> mobileNumber(),
        ]);

    }

}
0 likes
1 reply
HardDrive's avatar
HardDrive
OP
Best Answer
Level 2

I sorted this using the following, not sure if this the best way

$this->faker('en_GB')->phoneNumber;

Please or to participate in this conversation.