laracasts / TestDummy

Easy factories for PHP integration testing.
https://laracasts.com/lessons/whats-new-in-testdummy
MIT License
456 stars 80 forks source link

How to use Faker languageCode? #37

Closed mabasic closed 9 years ago

mabasic commented 10 years ago
Faker\Provider\Miscellaneous

boolean($chanceOfGettingTrue = 50) // true
md5                     // 'de99a620c50f2990e87144735cd357e7'
sha1                    // 'f08e7f04ca1a413807ebc47551a40a20a0b4de5c'
sha256                  // '0061e4c60dac5c1d82db0135a42e00c89ae3a333e7c26485321f24348c7e98a5'
locale                  // en_UK
countryCode             // UK
languageCode            // en

How can I use any one of these in fixtures.yml?

I have tried:

Language:
  locale: $languageCode

But it does not work. Any ideas ?

Rokt33r commented 10 years ago

TestDummy only works with 'string', 'integer', 'date', 'text', 'boolean' and 'uuid' keyword

<?php namespace Laracasts\TestDummy;

use Faker\Factory as Faker;

class DynamicAttributeReplacer {
...
...
    /**
     * Supported fake types
     *
     * @var array
     */
    protected $supportedFakes = [
        'string', 'integer', 'date', 'text', 'boolean', 'uuid',
    ];

This is my solution

Add the keywords you want

    protected $supportedFakes = [
        'string', 'integer', 'date', 'text', 'boolean', 'uuid',
        'latitude', 'longitude', 'address'
    ];

Add some methods for them

    public function getFakeLatitude(){
        return $this->fake->latitude;
    }
    public function getFakeLongitude(){
        return $this->fake->longitude;
    }
    public function getFakeAddress(){
        return $this->fake->address;
    }
sebastiaanluca commented 9 years ago

I cannot get this to work either. And the readme says otherwise?

However, in addition to those, TestDummy will recognize all supported Faker properties. As such, we can do things like:

Yeah, v1.3 only :) My bad.