protected function process($data) { $fakeTag = FakerinoConf::get('fakerinoTag'); /** * When an element in the configuration is not present, * FakerinoConf returns an exception. * Because the Handler needs a null value to continue the chain handling, * the catch block will intercept that exception. */ try { $elementInConf = FakerinoConf::get($fakeTag); if (array_key_exists($data->getName(), $elementInConf)) { $firstChain = self::getFirstChain(); if ($firstChain !== null) { $classes = array(); foreach ($elementInConf[$data->getName()] as $key => $val) { $element = new FakeElement($key, $val); $classes[] = $firstChain->handle($element); } return $classes; } } } catch (ConfValueNotFoundException $e) { } return; }
/** * {@inheritdoc} */ protected function process($data) { $elementName = $data->getName(); $fakeFilePath = FakerinoConf::get('fakeFilePath') . DIRECTORY_SEPARATOR . FakerinoConf::get('locale') . DIRECTORY_SEPARATOR . $this->createFilename($elementName); if (file_exists($fakeFilePath)) { return $this->getOutput('Fakerino\\FakeData\\Core\\FileFake', $elementName); } return; }
/** * {@inheritdoc} */ public function generate() { $fileName = strtolower($this->caller->getOption('filename')); $path = FakerinoConf::get('fakeFilePath') . DIRECTORY_SEPARATOR . FakerinoConf::get('locale') . DIRECTORY_SEPARATOR; if ($fakeFile = FakeTxtFile::getSource($fileName, $path)) { $lines = file($fakeFile); $index = mt_rand(0, count($lines) - 1); $element = $lines[$index]; return preg_replace("/\r|\n/", "", $element); } else { return; } }
public function testHandler() { $handler = new FileFakerClass(); $customClass = new FakeElement('Surname'); $fakeFile = FakerinoConf::get('fakeFilePath') . DIRECTORY_SEPARATOR . FakerinoConf::get('locale') . DIRECTORY_SEPARATOR . strtolower($customClass->getName()) . '.txt'; $fileContentRaw = file($fakeFile); $fileContent = array(); foreach ($fileContentRaw as $val) { $fileContent[] = $this->cleanExtraChar($val); } $result = $handler->handle($customClass); $valueExists = in_array($result, $fileContent); $this->assertInstanceOf('Fakerino\\Core\\FakeHandler\\Handler', $handler); $this->assertInternalType('string', $result); $this->assertTrue($valueExists); }
/** * Fills the given table with fake data. * * @param string|null $tableName * * @return array $rows * @throws \Fakerino\FakeData\Exception\MissingRequiredOptionException */ public function fakeTable($tableName = null) { if ($tableName === null) { throw new MissingRequiredOptionException('table name'); } $connectionParams = FakerinoConf::get('database'); $dbFiller = new DbFiller($connectionParams, $this->db, $tableName, $this, $this->num); $rows = $dbFiller->fill(); return $rows; }