Exemple #1
0
 /**
  * Ask for a parameter's value
  *
  * @param  Structure           $structure
  * @param  InputInterface      $input
  * @param  OutputInterface     $output
  * @return array[string]string the parameter set as a key/value hash for use in a generator
  **/
 public function askParameters(Structure $structure, InputInterface $input, OutputInterface $output)
 {
     $parameters = array();
     foreach ($structure->getParameterDefinition() as $parameter) {
         $parameters[$parameter->getName()] = $this->askParameter($parameter, $input, $output);
     }
     return $parameters;
 }
Exemple #2
0
 /**
  * Test already exists
  *
  * @expectedException Naneau\FileGen\Generator\Exception\NodeExists
  *
  * @return void
  **/
 public function testAlreadyExists()
 {
     $structure = new Structure();
     $structure->file('foo', 'foo');
     $generator = $this->createGenerator();
     // dir exists already... oh noes.
     file_put_contents($generator->getRoot() . '/foo', 'foo');
     $generator->generate($structure);
 }
Exemple #3
0
 /**
  * Test simple creation
  *
  * @return void
  **/
 public function testCreation()
 {
     $generator = $this->createGenerator();
     $structure = new Structure();
     $structure->file('foo', 'foo contents')->link($generator->getRoot() . '/foo', 'bar');
     $generator->generate($structure);
     // See if structure was generated
     $this->assertEquals(file_get_contents($generator->getRoot() . '/bar'), 'foo contents');
 }
Exemple #4
0
 /**
  * Parameters
  *
  * @return void
  **/
 public function testMissingParameters()
 {
     $generator = $this->createGenerator();
     $structure = new Structure();
     $structure->file('foo', new TwigContents($this->createTwig()->loadTemplate('template_two.twig'), array('foo' => 'foo', 'baz' => 'baz')));
     $generator->generate($structure);
     // See if structure was generated
     $this->assertEquals(file_get_contents($generator->getRoot() . '/foo'), "foo  baz\n");
 }
Exemple #5
0
 /**
  * Test copy fail
  *
  * @expectedException Naneau\FileGen\File\Contents\Exception
  * @return void
  **/
 public function testNotReadable()
 {
     $generator = $this->createGenerator();
     // Create unreadable file
     touch($generator->getRoot() . '/not-readable');
     chmod($generator->getRoot() . '/not-readable', 00);
     $structure = new Structure();
     $structure->file('bar', new CopyContents($generator->getRoot() . '/not-readable'));
     $generator->generate($structure);
 }
 public function testExecute()
 {
     $application = new Application();
     $application->getHelperSet()->set(new ParameterHelper(), 'filegenParameters');
     $command = new ParameterCommand();
     $application->add($command);
     $structure = new Structure();
     $structure->parameter('foo', 'foo description')->parameter('bar', 'bar description')->parameter('baz', 'baz description');
     $structure->getParameterDefinition()->get('baz')->setDefaultValue('BazValue');
     $command->setStructure($structure);
     $commandTester = new CommandTester($command);
     // Set the input stream
     $helper = $command->getHelper('question');
     $helper->setInputStream($this->getInputStream("FooValue\nBarValue\n\n"));
     $commandTester->execute(array('command' => $command->getName()));
     $this->assertEquals('foo descriptionbar descriptionbaz description', $commandTester->getDisplay());
     $received = $command->getReceived();
     $this->assertArrayHasKey('foo', $received);
     $this->assertEquals('FooValue', $received['foo']);
     $this->assertArrayHasKey('bar', $received);
     $this->assertEquals('BarValue', $received['bar']);
     $this->assertArrayHasKey('baz', $received);
     $this->assertEquals('BazValue', $received['baz']);
 }
Exemple #7
0
 /**
  * @return void
  **/
 public function testParameterDefinition()
 {
     // Note leading slashes in some
     $structure = new Structure();
     $structure->directory('foo')->file('bar')->parameter('foo', 'The foo parameter')->parameter('bar', 'The bar parameter');
     $this->assertInstanceOf('Naneau\\FileGen\\Directory', $structure->scan('foo'));
     $this->assertInstanceOf('Naneau\\FileGen\\File', $structure->scan('bar'));
     $this->assertInstanceOf('Naneau\\FileGen\\Parameter\\Parameter', $structure->getParameterDefinition()->get('foo'));
     $this->assertInstanceOf('Naneau\\FileGen\\Parameter\\Parameter', $structure->getParameterDefinition()->get('bar'));
 }
Exemple #8
0
 /**
  * Test already exists
  *
  * @expectedException Naneau\FileGen\Generator\Exception\NodeExists
  *
  * @return void
  **/
 public function testAlreadyExists()
 {
     $structure = new Structure();
     $structure->directory('foo');
     $generator = $this->createGenerator();
     // dir exists already... oh noes.
     mkdir($generator->getRoot() . '/foo');
     $generator->generate($structure);
 }