Author: Nicola Pietroluongo (nik.longstone@gmail.com)
Beispiel #1
0
 public function testAdditionalConfValues()
 {
     $testAdditional = array('test' => 1);
     $this->default = array_merge($this->default, $testAdditional);
     $conf = new FakerinoConf($testAdditional);
     $conf->loadConfiguration();
     $this->assertEquals(array_keys($this->default), array_keys($conf->toArray()));
 }
 public function setUp()
 {
     $this->conf['fake'] = array('fake1' => array('Name' => array('length' => 3), 'Surname' => null), 'fake2' => array('Name' => array('length' => 30), 'Surname' => null), 'fake3' => array('fake1', 'fake2'));
     $fakerinoDefaultConf = new FakerinoConf();
     $fakerinoDefaultConf->loadConfiguration();
     $fileFakePath = $this->getFileFakePath($fakerinoDefaultConf);
     $fakeHandler = new FakeHandler\FakeHandler();
     $fakeHandler->setSuccessor(new FakeHandler\FileFakerClass($fileFakePath));
     $fakeHandler->setSuccessor(new FakeHandler\CustomFakerClass());
     $fakeHandler->setSuccessor(new FakeHandler\ConfFakerClass($this->conf['fake']));
     $fakeHandler->setSuccessor(new FakeHandler\DefaultFakerClass());
     $this->fakeGenerator = new FakeDataFactory($fakeHandler, new DoctrineLayer(null), new TwigTemplate());
 }
 public function testHandler()
 {
     $elementToFake = 'Surname';
     $fakerinoDefaultConf = new FakerinoConf();
     $fakerinoDefaultConf->loadConfiguration();
     $fileFakePath = $this->getFileFakePath($fakerinoDefaultConf);
     $fakeFile = $fileFakePath . strtolower($elementToFake) . '.txt';
     $handler = new FileFakerClass($fileFakePath);
     $customClass = new FakeElement($elementToFake);
     $fileContent = $this->getFileContent($fakeFile);
     $result = $handler->handle($customClass);
     $isResultValueExistsInFile = in_array($result, $fileContent);
     $this->assertInstanceOf('Fakerino\\Core\\FakeHandler\\Handler', $handler);
     $this->assertInternalType('string', $result);
     $this->assertTrue($isResultValueExistsInFile);
 }
Beispiel #4
0
 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;
 }
Beispiel #5
0
 /**
  * {@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;
 }
 public function testHandlerWithConfiguration()
 {
     $fakeConf['fake'] = array('fakeTest' => array('Unknown', 'Surname' => null));
     FakerinoConf::loadConfiguration($fakeConf);
     $firstHandler = new CustomFakerClass();
     $handler = new ConfFakerClass();
     $firstHandler->setSuccessor($handler);
     $this->assertInstanceOf('Fakerino\\Core\\FakeHandler\\Handler', $firstHandler);
     $this->assertInternalType('array', $firstHandler->handle(new FakeElement('fakeTest')));
 }
 /**
  * {@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);
 }
Beispiel #9
0
 /**
  * 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;
 }
 public function setUp()
 {
     FakerinoConf::loadConfiguration();
     $this->FileFakeGenerator = new FileFakeGenerator();
     $this->FileFakeGenerator->setCaller(new Text());
 }