/** * Get single fake value for a field configuration. * * @param array $config Configuration as taken from Garp_Model_Db::getFieldConfiguration() * @return mixed */ public function getFakeValueForField(array $config) { if (!array_get($config, 'required')) { // Give optional fields a 10% chance (more or less) to be NULL $diceRoll = $this->_faker->numberBetween(1, 100); if ($diceRoll < 10) { return null; } } if (array_get($config, 'origin') === '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(); return $htmlFilterable->filter($value); } if ($config['type'] === 'enum') { return $this->_faker->randomElement($config['options']); } 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: {$field['type']}"); }