/** * @param InputInterface $input * @param OutputInterface $output * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { /** @var FormHelper $formHelper */ $formHelper = $this->getHelper('form'); $output->writeln("\n<comment>Generating the code for:</comment> <info>{$input->getArgument('class')}</info>\n"); $this->metadata->populate($input->getArgument('class'), $formHelper->addElements($input, $output)); $this->metadata->setTargetDirectory($input->getArgument('directory')); $this->generator->generate($this->metadata); $formHelper->showForm($this->metadata, $output); }
function it_should_generate_code_for_the_given_metadata(Twig $view, Filesystem $fileSystem, Loader $loader) { $view->getLoader()->willReturn($loader); $this->beConstructedWith($view, $fileSystem); $formMetadata = new FormMetadata(); $formMetadata->populate('My\\Awesome\\LoginForm', ['username' => ['type' => 'text', 'optional' => false, 'multipleSelection' => false, 'value' => null], 'languages' => ['type' => 'select', 'optional' => true, 'multipleSelection' => true, 'value' => null], 'remember_me' => ['type' => 'checkbox', 'optional' => true, 'multipleSelection' => false, 'value' => null]]); $formMetadata->setTargetDirectory('src/'); $view->render('templates/class.php.twig', ['form' => $formMetadata])->willReturn($code = <<<CODE <?php namespace My\\Awesome; use EasyForms\\Elements\\Text; use EasyForms\\Elements\\Select; use EasyForms\\Elements\\Checkbox; use EasyForms\\Form; class LoginForm extends Form { public function __construct() { \$this ->add(new Text('username')) ->add((new Select('languages'))->makeOptional()->enableMultipleSelection()) ->add((new Checkbox('remember_me', 'remember'))->makeOptional()) ; } } CODE ); $this->generate($formMetadata); $fileSystem->mkdir('src/My/Awesome')->shouldHaveBeenCalled(); $fileSystem->dumpFile('src/My/Awesome/LoginForm.php', $code)->shouldHaveBeenCalled(); }