Author: Nicola Pietroluongo (nik.longstone@gmail.com)
Exemplo n.º 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()));
 }
Exemplo n.º 2
0
 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());
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 6
0
 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')));
 }
Exemplo n.º 7
0
 /**
  * {@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;
     }
 }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 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;
 }
Exemplo n.º 10
0
 public function setUp()
 {
     FakerinoConf::loadConfiguration();
     $this->FileFakeGenerator = new FileFakeGenerator();
     $this->FileFakeGenerator->setCaller(new Text());
 }