public function testGenerateWithoutDependencies()
 {
     $author = new Author();
     $author->setId(2);
     $author->setUsername('Username');
     $models = array($author);
     $fieldNames = array('username');
     $classMetadata = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
     $classMetadata->expects($this->any())->method('getName')->will($this->returnValue('Sp\\FixtureDumper\\Tests\\Fixture\\Author'));
     $classMetadata->expects($this->any())->method('getFieldNames')->will($this->returnValue($fieldNames));
     $classMetadata->expects($this->any())->method('isSingleValuedAssociation')->will($this->returnValue(true));
     $classMetadata->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array()));
     $classMetadata->expects($this->any())->method('getIdentifierValues')->will($this->returnCallback(function ($model) {
         return array('id' => $model->getId());
     }));
     $this->repository->expects($this->once())->method('findAll')->will($this->returnValue($models));
     $this->manager->expects($this->once())->method('getRepository')->will($this->returnValue($this->repository));
     $output = $this->generator->generate($classMetadata, null, $this->getOptions());
     $this->assertEquals($this->getContent('author_data'), $output);
 }
Example #2
0
 /**
  * @param Generator\AbstractGenerator $generator
  * @param string                      $fixture
  * @param string                      $path
  * @param string                      $fileName
  */
 protected function writeFixture(AbstractGenerator $generator, $fixture, $path, $fileName)
 {
     $filesystem = new Filesystem();
     if (!$filesystem->exists($path)) {
         $filesystem->mkdir($path);
     }
     $fixture = $generator->prepareForWrite($fixture);
     file_put_contents($path . DIRECTORY_SEPARATOR . $fileName, $fixture);
 }
 /**
  * Asks the user to enter a value for every required option for the used generator.
  *
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @param \Sp\FixtureDumper\Generator\AbstractGenerator     $generator
  *
  * @return array
  */
 protected function askForOptions(OutputInterface $output, AbstractGenerator $generator)
 {
     $dialog = $this->getHelperSet()->get('dialog');
     $options = array();
     foreach ($generator->getRequiredOptions() as $requiredOption) {
         $options[$requiredOption] = $dialog->ask($output, sprintf('<question>Please enter a value for the required option "%s": </question>', $requiredOption));
     }
     return $options;
 }