protected function execute(InputInterface $input, OutputInterface $output) { // throw new \Exception('boo'); $directory = realpath($input->getArgument('directory')); $directoryOutput = $input->getArgument('outputdirectory'); /* @var $logger Psr\Log\LoggerInterface */ $this->logger = $this->getContainer()->get('logger'); $io = new SymfonyStyle($input, $output); $io->title('DDD Model Generation'); $clean = $input->hasOption('clean'); if ($clean) { $io->section('Clean output directoty'); $fs = new \Symfony\Component\Filesystem\Filesystem(); try { $fs->remove($directoryOutput); } catch (IOExceptionInterface $e) { $io->error($e->getMessage()); } $io->text('clean of ' . $directoryOutput . ' completed'); } if (is_dir($directory)) { $finder = new Finder(); $finder->search($directory); foreach ($finder->getFindedFiles() as $file) { if (pathinfo($file, PATHINFO_FILENAME) == 'model.yml') { $io->text('Analizzo model.yml in ' . pathinfo($file, PATHINFO_DIRNAME)); $dddGenerator = new DDDGenerator(); $dddGenerator->setLogger($this->logger); $dddGenerator->analyze($file); $dddGenerator->generate($directoryOutput); } } $io->section('Php-Cs-Fixer on generated files'); $fixer = new \Symfony\CS\Console\Command\FixCommand(); $input = new ArrayInput(['path' => $directoryOutput, '--level' => 'psr2', '--fixers' => 'eof_ending,strict_param,short_array_syntax,trailing_spaces,indentation,line_after_namespace,php_closing_tag']); $output = new BufferedOutput(); $fixer->run($input, $output); $content = $output->fetch(); $io->text($content); if (count($this->errors) == 0) { $io->success('Completed generation'); } else { $io->error($this->errors); } } else { $io->caution('Directory ' . $directory . ' not valid'); } // PER I WARNING RECUPERABILI //$io->note('Generate Class'); }
public function testGenerateDDDOnVfsEventsSpecific() { $directoryOutput = self::$directoryV->url() . '/output'; $directorySrcGen = self::$directoryV->url() . '/src-gen-event'; $resourcesDir = __DIR__ . '/../Resources'; if (!file_exists($directoryOutput)) { mkdir($directoryOutput, 0700, true); } if (!file_exists($directorySrcGen)) { mkdir($directorySrcGen, 0700, true); } $data = file_get_contents($resourcesDir . '/ddd/realEvents.yml'); file_put_contents($directoryOutput . '/test.yml', $data); $dddg = new DDDGenerator(); $dddg->setLogger($this->logger); $dddg->analyze($directoryOutput . '/test.yml'); $dddg->generate(new VfsAdapter($directorySrcGen)); // $finderV = new Finder(); // $finderV->search($directorySrcGen, 'php'); // foreach ($finderV->getFindedFiles() as $file) { // $namespace = str_replace('vfs://root/src-gen-event/', '', pathinfo($file, PATHINFO_DIRNAME)); // $name = str_replace('.php', '', pathinfo($file, PATHINFO_FILENAME)); // $this->logger->info('$mappaToCheck[\''.$namespace.'\'] = \''.$name.'\';'); // } // echo $this->readLog(); // exit; $mappaToCheck = []; $mappaToCheck['BitPrepared/Bundle/EventBundle/Domain/Events'][] = 'DomainEvent'; $mappaToCheck['BitPrepared/Bundle/EventBundle/Domain/Events'][] = 'SpiegazioneSessioneCampoCreateEvent'; $mappaToCheck['BitPrepared/Bundle/EventBundle/Domain/Events'][] = 'SpiegazioneSessioneCampoDeleteEvent'; $mappaToCheck['BitPrepared/Bundle/EventBundle/Domain/Events'][] = 'SpiegazioneSessioneCampoAddDocumentEvent'; $mappaToCheck['BitPrepared/Bundle/EventBundle/Domain/Aggregate'][] = 'SpiegazioneSessioneCampo'; foreach ($mappaToCheck as $namespace => $classList) { foreach ($classList as $className) { $this->compareClassPhp($resourcesDir . '/ddd/generated/' . $namespace, $namespace, $className, $directorySrcGen); } } $errors = $dddg->getErrors(); $this->assertCount(0, $errors, 'errori durante la generazione'); }