protected function execute(InputInterface $input, OutputInterface $output)
 {
     $codeLocation = $input->getArgument('code-location');
     $codeDestination = $input->getOption('code-destination');
     $createNamespace = $input->getOption('create-namespace');
     $offset = $input->getOption('offset');
     $length = $input->getOption('length');
     $classyfile = new ClassyFile();
     $dispatcher = new EventDispatcher();
     if ($input->getOption('constants-to-upper')) {
         $plugin = new ConstantNamesToUpper();
         $dispatcher->addSubscriber($plugin);
     }
     if ($input->getOption('psr-fix')) {
         $plugin = new PhpCsFixer($input, $output);
         $dispatcher->addSubscriber($plugin);
     }
     if ($input->getOption('remove-top-comment')) {
         $classyfile->setTemplate(new BasicClassTemplate(''), 'getTemplate');
     }
     $classyfile->setEventDispatcher($dispatcher);
     if ($createNamespace) {
         $classyfile->generateClassFiles($codeDestination, $codeLocation, $offset, $length);
     } else {
         $classyfile->generateClassFiles($codeDestination, $codeLocation);
     }
 }
Exemple #2
0
 public function testGenerateClassEvent()
 {
     // Delete all files
     $this->deleteFiles('/tmp/', '/Service/');
     $dispatcher = new EventDispatcher();
     $dispatcher->addListener(GenerateClassesEvent::AFTER, function (GenerateClassesEvent $event) {
         $finder = $event->getFinder();
         $this->assertInstanceOf('\\Symfony\\Component\\Finder\\Finder', $finder);
         $classes = $event->getClasses();
         $this->assertTrue(is_array($classes));
         $this->assertArrayHasKey('mock_classes_style1.php', $classes);
         $this->assertArrayHasKey('ServiceSettings', $classes['mock_classes_style1.php']);
         $this->assertArrayHasKey('TimeInterval', $classes['mock_classes_style1.php']);
         $this->assertArrayHasKey('Scale', $classes['mock_classes_style1.php']);
     });
     $classyfile = new ClassyFile($dispatcher);
     $codeLocation = __DIR__ . '/mock/';
     $codeDestination = '/tmp/';
     $classyfile->generateClassFiles($codeDestination, $codeLocation);
     $this->assertFileExists('/tmp/Service/WithBad/ClassFiles/Scale.php', 'File was not created in the right location.');
     $this->assertFileExists('/tmp/Service/WithBad/ClassFiles/ServiceSettings.php', 'File was not created in the right location.');
     $this->assertFileExists('/tmp/Service/WithBad/ClassFiles/TimeInterval.php', 'File was not created in the right location.');
     $this->assertEquals($dispatcher, $classyfile->getEventDispatcher());
     // Delete all files
     $this->deleteFiles($codeDestination, '/Service/');
 }