library/Garp/Model/Db/Faker.php
public function getFakeValueForField(array $config) {
        if (!f\prop('required', $config)) {
            // Give optional fields a 10% chance (more or less) to be NULL
            $diceRoll = $this->_faker->numberBetween(1, 100);
            if ($diceRoll < 10) {
                return f\prop('default', $config) ?: null;
            }
        }

        if (f\prop('origin', $config) === 'relation') {
            // TODO Do something intelligent here?
            // I don't want to tightly couple this class to a database or model, but a random
            // integer for a foreign key will most definitely result in an
            // Integrity constraint violation when there's no seed data.
            return null;
        }

        if ($config['type'] === 'text') {
            return $this->_getFakeText($config);
        }

        if ($config['type'] === 'html') {
            $value = $this->_faker->randomHtml(2, 3);
            $htmlFilterable = new Garp_Model_Behavior_HtmlFilterable();
            $config = $htmlFilterable->getDefaultConfig();
            return $htmlFilterable->filter($value, $config);
        }

        if ($config['type'] === 'enum' || $config['type'] === 'set') {
            $options = $config['options'];
            $isAssoc = f\every('is_string', array_keys($options));
            $randomPool = $isAssoc ? array_keys($options) : array_values($options);
            return $this->_faker->randomElement($randomPool);
        }

        if ($config['type'] === 'email') {
            return $this->_faker->email;
        }

        if ($config['type'] === 'url') {
            return $this->_faker->url;
        }

        if ($config['type'] === 'checkbox') {
            return $this->_faker->randomElement(array(0, 1));
        }

        if ($config['type'] === 'date' || $config['type'] === 'datetime') {
            $value = $this->_faker->dateTimeBetween('-1 year', '+1 year');
            $format = $config['type'] === 'date' ? 'Y-m-d' : 'Y-m-d H:i:s';
            return $value->format($format);
        }

        if ($config['type'] === 'time') {
            return $this->_faker->time;
        }

        if ($config['type'] === 'imagefile') {
            return 'image.jpg';
        }

        if ($config['type'] === 'document') {
            return 'document.txt';
        }

        if ($config['type'] === 'numeric') {
            return $this->_faker->randomDigit;
        }

        throw new InvalidArgumentException("Unknown type encountered: {$config['type']}");
    }
public function getFakeValueForField(array $config) {
        if (!f\prop('required', $config)) {
            // Give optional fields a 10% chance (more or less) to be NULL
            $diceRoll = $this->_faker->numberBetween(1, 100);
            if ($diceRoll < 10) {
                return f\prop('default', $config) ?: null;
            }
        }

        if (f\prop('origin', $config) === 'relation') {
            // TODO Do something intelligent here?
            // I don't want to tightly couple this class to a database or model, but a random
            // integer for a foreign key will most definitely result in an
            // Integrity constraint violation when there's no seed data.
            return null;
        }

        if ($config['type'] === 'text') {
            return $this->_getFakeText($config);
        }

        if ($config['type'] === 'html') {
            $value = $this->_faker->randomHtml(2, 3);
            $htmlFilterable = new Garp_Model_Behavior_HtmlFilterable();
            $config = $htmlFilterable->getDefaultConfig();
            return $htmlFilterable->filter($value, $config);
        }

        if ($config['type'] === 'enum' || $config['type'] === 'set') {
            $options = $config['options'];
            $isAssoc = f\every('is_string', array_keys($options));
            $randomPool = $isAssoc ? array_keys($options) : array_values($options);
            return $this->_faker->randomElement($randomPool);
        }

        if ($config['type'] === 'email') {
            return $this->_faker->email;
        }

        if ($config['type'] === 'url') {
            return $this->_faker->url;
        }

        if ($config['type'] === 'checkbox') {
            return $this->_faker->randomElement(array(0, 1));
        }

        if ($config['type'] === 'date' || $config['type'] === 'datetime') {
            $value = $this->_faker->dateTimeBetween('-1 year', '+1 year');
            $format = $config['type'] === 'date' ? 'Y-m-d' : 'Y-m-d H:i:s';
            return $value->format($format);
        }

        if ($config['type'] === 'time') {
            return $this->_faker->time;
        }

        if ($config['type'] === 'imagefile') {
            return 'image.jpg';
        }

        if ($config['type'] === 'document') {
            return 'document.txt';
        }

        if ($config['type'] === 'numeric') {
            return $this->_faker->randomDigit;
        }

        throw new InvalidArgumentException("Unknown type encountered: {$config['type']}");
    }
public function getFakeValueForField ( array $ config ) { if ( ! f \ prop ( 'required' , $ config ) ) { // Give optional fields a 10% chance (more or less) to be NULL $ diceRoll = $ this -> _faker -> numberBetween ( 1 , 100 ) ; if ( $ diceRoll < 10 ) { return f \ prop ( 'default' , $ config ) ? : null ; } } if ( f \ prop ( 'origin' , $ config ) === 'relation' ) { // TODO Do something intelligent here? // I don't want to tightly couple this class to a database or model, but a random // integer for a foreign key will most definitely result in an // Integrity constraint violation when there's no seed data. return null ; } if ( $ config [ 'type' ] === 'text' ) { return $ this -> _getFakeText ( $ config ) ; } if ( $ config [ 'type' ] === 'html' ) { $ value = $ this -> _faker -> randomHtml ( 2 , 3 ) ; $ htmlFilterable = new Garp_Model_Behavior_HtmlFilterable ( ) ; $ config = $ htmlFilterable -> getDefaultConfig ( ) ; return $ htmlFilterable -> filter ( $ value , $ config ) ; } if ( $ config [ 'type' ] === 'enum' || $ config [ 'type' ] === 'set' ) { $ options = $ config [ 'options' ] ; $ isAssoc = f \ every ( 'is_string' , array_keys ( $ options ) ) ; $ randomPool = $ isAssoc ? array_keys ( $ options ) : array_values ( $ options ) ; return $ this -> _faker -> randomElement ( $ randomPool ) ; } if ( $ config [ 'type' ] === 'email' ) { return $ this -> _faker -> email ; } if ( $ config [ 'type' ] === 'url' ) { return $ this -> _faker -> url ; } if ( $ config [ 'type' ] === 'checkbox' ) { return $ this -> _faker -> randomElement ( array ( 0 , 1 ) ) ; } if ( $ config [ 'type' ] === 'date' || $ config [ 'type' ] === 'datetime' ) { $ value = $ this -> _faker -> dateTimeBetween ( '-1 year' , '+1 year' ) ; $ format = $ config [ 'type' ] === 'date' ? 'Y-m-d' : 'Y-m-d H:i:s' ; return $ value -> format ( $ format ) ; } if ( $ config [ 'type' ] === 'time' ) { return $ this -> _faker -> time ; } if ( $ config [ 'type' ] === 'imagefile' ) { return 'image.jpg' ; } if ( $ config [ 'type' ] === 'document' ) { return 'document.txt' ; } if ( $ config [ 'type' ] === 'numeric' ) { return $ this -> _faker -> randomDigit ; } throw new InvalidArgumentException ( "Unknown type encountered: {$config['type']}" ) ; }
Get single fake value for a field configuration.

@param array $config Configuration as taken from Garp_Model_Db::getFieldConfiguration()
@return mixed
Get single fake value for a field configuration .