fzaninotto / Faker

Faker is a PHP library that generates fake data for you
MIT License
26.8k stars 3.57k forks source link

Got 'Unknown formatter "tollFreePhoneNumber"' using es_ES locale #2030

Open carlos-mora opened 3 years ago

carlos-mora commented 3 years ago

Summary

In a Laravel project, Faker is provided using a config parameter, 'faker_locale', so the dependency is well instantiated. If not set, fallsback to en_US

Tracking the error message, it seems that there is a typo in Faker\Provider\es_ES\PhoneNumber: function is called tollFreeNumber instead of tollFreePhoneNumber

Changing the function's name solves the issue.

Versions

Version
PHP 7.3.18
fzaninotto/faker 1.9.1

Self-enclosed code snippet for reproduction

// file config\app.php
    /*
    |--------------------------------------------------------------------------
    | Facker Locale Configuration
    |--------------------------------------------------------------------------
    |
    | The facker locale determines the default locale that will be used
    | by the generators.
    |
    */

    'faker_locale' => 'es_ES',
// file database\factory\PersonaFactory.php
$factory->define(Persona::class, function (Faker $faker) {
    return [
        'nombre' => $faker->firstName(),
        'apellidos' => $faker->lastName(),
        'siglas' => $faker->title(),
        'email' => $faker->safeEmail(),
    'observaciones' => $faker->paragraph(1, true),
    // ... more attributes ...
    ];
});
// trrying to use it anywhere, even tinker
$sample = factory('App\Models\Persona')->create()

Expected output

=> App\Models\Persona {#3539
     nombre: "Cristina",
     apellidos: "Robledo",
     siglas: "Lic.",
    ...
}

Actual output

InvalidArgumentException with message 'Unknown formatter "tollFreePhoneNumber"'
carlos-mora commented 3 years ago

I've made a PR https://github.com/fzaninotto/Faker/pull/2031 fixing the typo. Test failed because other langauges issues.