/**
  * @test
  */
 public function shouldReplaceClassNameAndNamespace()
 {
     //given
     $generator = new ControllerGenerator('users');
     //when
     $templateContents = $generator->templateContents();
     //then
     Assert::thatString($templateContents)->contains('namespace \\Application\\Controller;')->contains('class UsersController extends Controller');
 }
Ejemplo n.º 2
0
 private function generate()
 {
     $controller = $this->input->getArgument('controller');
     $action = $this->input->getArgument('action');
     $controllerGenerator = new ControllerGenerator($controller);
     $actionGenerator = null;
     if ($action) {
         $actionGenerator = new ActionGenerator($action);
     }
     $this->output->writeln('---------------------------------');
     $this->output->writeln('Class name: <info>' . $controllerGenerator->getClassName() . '</info>');
     $this->output->writeln('Class namespace: <info>' . $controllerGenerator->getClassNamespace() . '</info>');
     $this->output->writeln('---------------------------------');
     if (!$controllerGenerator->isControllerExists()) {
         $this->output->writeln('Create: <info>' . $controllerGenerator->getControllerPath() . '</info>');
         $controllerGenerator->saveController();
     }
     if ($controllerGenerator->appendAction($actionGenerator)) {
         $this->output->writeln('Appened action: <info>' . $controllerGenerator->getClassName() . '::' . $actionGenerator->getActionName() . '</info>');
     }
     $viewGenerator = new ViewGenerator($controller);
     if ($viewGenerator->createViewDirectoryIfNotExists()) {
         $this->output->writeln('Create: <info>' . $viewGenerator->getViewPath() . '</info>');
     }
     if ($viewGenerator->appendAction($actionGenerator)) {
         $this->output->writeln('Appened view file: <info>' . $actionGenerator->getActionViewFile() . '</info>');
     }
 }
Ejemplo n.º 3
0
 public function append()
 {
     if ($this->controllerGenerator) {
         $controllerPath = $this->controllerGenerator->getControllerPath();
         $controllerContents = $this->controllerGenerator->getControllerContents();
         $actionContents = $this->actionGenerator->templateContents();
         $controllerContents = preg_replace('/}\\s*$/', $actionContents . PHP_EOL . '}' . PHP_EOL, $controllerContents);
         file_put_contents($controllerPath, $controllerContents);
     }
     if ($this->viewGenerator) {
         file_put_contents(Path::join($this->viewGenerator->getViewPath(), $this->actionGenerator->getActionViewFile()), PHP_EOL);
     }
     return true;
 }
 public function content()
 {
     $stubContent = file_get_contents($this->stubFilePath());
     $strSubstitutor = new StrSubstitutor(array('namespace' => $this->generator->getClassNamespace(), 'class' => $this->generator->getClassName()));
     return $strSubstitutor->replace($stubContent);
 }
Ejemplo n.º 5
0
 /**
  * @test
  */
 public function shouldNotAppendWhenActionIsExists()
 {
     //given
     $controllerGenerator = new ControllerGenerator('users', $this->controllerPath);
     $controllerGenerator->saveController();
     $controllerGenerator->appendAction(new ActionGenerator('save'));
     //when
     $appendAction = $controllerGenerator->appendAction(new ActionGenerator('save'));
     //then
     $this->assertFalse($appendAction);
 }