public function testReadConfigurationRightConfWithEmpty()
 {
     $reader = new Reader('_files/config.right.deleteone.yaml', array(dirname(__FILE__)));
     $values = $reader->getConfigValues();
     $this->assertInternalType('array', $values);
     $this->assertArrayHasKey('entities', $values);
     $this->assertArrayHasKey('guestbook', $values['entities']);
     $this->assertArrayHasKey('delete', $values['entities']['guestbook']);
     $this->assertArrayHasKey('delete_where', $values['entities']['guestbook']);
     $entities = $reader->getEntities();
     $this->assertInternalType('array', $entities);
     $this->assertContains('guestbook', $entities);
     return $reader;
 }
 public function testGenerateConfWriteable()
 {
     $this->createPrimary();
     $conn = $this->getConnection();
     $pdo = $conn->getConnection();
     $writer = new Writer();
     $writer->setProtectedCols(array('.*\\.user'));
     $writer->protectCols(true);
     $entities = $writer->generateConfFromDB($pdo, new Guesser());
     $this->assertInternalType('array', $entities);
     $this->assertArrayHasKey('entities', $entities);
     $this->assertArrayHasKey('guestbook', $entities['entities']);
     $this->assertArrayHasKey('cols', $entities['entities']['guestbook']);
     $this->assertArrayNotHasKey('id', $entities['entities']['guestbook']['cols']);
     $this->assertArrayNotHasKey('user', $entities['entities']['guestbook']['cols']);
     $this->assertArrayHasKey('content', $entities['entities']['guestbook']['cols']);
     // check the configuration for the date
     $created = $entities['entities']['guestbook']['cols']['created'];
     $this->assertInternalType('array', $created);
     $this->assertArrayHasKey('method', $created);
     $this->assertArrayHasKey('params', $created);
     $this->assertEquals('date', $created['method']);
     $this->assertEquals('Y-m-d H:i:s', $created['params'][0]);
     // save it
     $temp = tempnam(sys_get_temp_dir(), 'phpunit');
     $writer->save($entities, $temp);
     $this->assertFileExists($temp);
     // try to read the file with the reader
     $reader = new Reader($temp);
     $values = $reader->getConfigValues();
     $this->assertInternalType('array', $values);
     $this->assertArrayHasKey('entities', $values);
     // delete it
     unlink($temp);
 }
 /**
  * Set the configuration
  *
  * @param Reader $configuration
  */
 public function setConfiguration(Reader $configuration)
 {
     $this->configuration = $configuration;
     $configEntites = $configuration->getConfigValues();
     $this->configEntites = $configEntites['entities'];
 }
 public function testExecuteProtectId()
 {
     $this->createPrimary();
     $application = new Application();
     $application->add(new Command());
     // We mock the DialogHelper
     $command = $application->find('config:generate');
     $helper = $this->getMock('\\Symfony\\Component\\Console\\Helper\\QuestionHelper', array('ask'));
     $helper->expects($this->any())->method('ask')->willReturn(getenv('DB_PASSWORD'));
     $command->getHelperSet()->set($helper, 'question');
     $temp = tempnam(sys_get_temp_dir(), 'phpunit');
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), '--host' => getenv('DB_HOST'), '--db' => getenv('DB_NAME'), '--user' => getenv('DB_USER'), '--file' => $temp, '--protect' => null));
     $this->assertRegExp('|Configuration written to.*|', $commandTester->getDisplay());
     $this->assertFileExists($temp);
     // try to read the file with the reader
     $reader = new Reader($temp);
     $values = $reader->getConfigValues();
     $this->assertInternalType('array', $values);
     $this->assertArrayHasKey('entities', $values);
     $this->assertArrayHasKey('guestbook', $values['entities']);
     $this->assertArrayHasKey('cols', $values['entities']['guestbook']);
     $this->assertArrayHasKey('user', $values['entities']['guestbook']['cols']);
     $this->assertArrayNotHasKey('id', $values['entities']['guestbook']['cols']);
     // remove the file
     unlink($temp);
 }