Example #1
0
 /**
  * @dataProvider templateOptions
  */
 public function testCompiledTemplate($templateOptions)
 {
     $container = new \Mockery\Container();
     $faker = \Faker\Factory::create();
     $filePath = $this->workingPath . DS . $faker->lexify . '.' . $faker->fileExtension;
     /**
      * @var $template AbstractTemplate
      */
     $template = $container->mock($templateOptions['template'])->shouldDeferMissing()->shouldAllowMockingProtectedMethods();
     $template->shouldReceive('getDefaultTemplateData')->atLeast(1)->andReturn($templateOptions['defaultTemplateData']);
     $template->setTemplateData($templateOptions['templateData']);
     $template->setFilePath($filePath);
     $generator = new Generator($template);
     $generator->setAbsolutePath(__DIR__ . DS . 'fixtures');
     $this->assertEquals($templateOptions['stub'], $generator->getCompiledTemplate());
     $generator->make();
     $this->assertFileExists($filePath);
 }
Example #2
0
 /**
  * @return $this
  */
 protected function generate()
 {
     $template = new Generator\Template\ControllerTemplate();
     $template->setFilePath($this->getFilePath());
     $generator = new Generator\Generator($template);
     $generator->make();
     $template = new Generator\Template\ViewTemplate();
     $template->setFilePath($this->getViewPath());
     $template->setTemplateData(['name' => $this->getOption('name')]);
     $generator = new Generator\Generator($template);
     $generator->make();
     return $this;
 }
Example #3
0
 /**
  * @return $this
  * @throws InputException
  */
 protected function generate()
 {
     $modelName = ucfirst($this->getOption('name'));
     $input = $this->getInput();
     $output = $this->getOutput();
     if ($this->getApplication()->isModelExists($modelName)) {
         $helper = $this->getHelperSet()->get("question");
         $question = new ConfirmationQuestion("\n<question>Model " . $modelName . " would be overwritten. y/N?:</question>\n> ", false);
         if (!$helper->ask($input, $output, $question)) {
             return $this;
         }
     }
     $primaryKey = $this->getPrimaryKey($this->getOption('table'));
     $columns = $this->getColumns($this->getOption('table'));
     // generate table
     $template = $this->getObjTemplate('TableTemplate');
     $template->setFilePath($this->getFilePath() . 'Table.php');
     $data = ['name' => ucfirst($this->getOption('name')), 'table' => $this->getOption('table'), 'primaryKey' => $primaryKey];
     $template->setTemplateData($data);
     $generator = new Generator\Generator($template);
     $generator->make();
     // generate row
     $template = $this->getObjTemplate('RowTemplate');
     $template->setFilePath($this->getFilePath() . 'Row.php');
     unset($data);
     $data = ['name' => ucfirst($this->getOption('name')), 'table' => $this->getOption('table'), "columns" => $columns];
     $template->setTemplateData($data);
     $generator = new Generator\Generator($template);
     $generator->make();
     return $this;
 }