public function testGenerate()
 {
     $this->controllerGenerator->generate($this->bundleMock, 'ModelAdminController');
     $file = $this->controllerGenerator->getFile();
     $this->assertSame('Sonata\\AdminBundle\\Tests\\Fixtures\\Controller\\ModelAdminController', $this->controllerGenerator->getClass());
     $this->assertSame('ModelAdminController.php', basename($file));
     $this->assertFileEquals(__DIR__ . '/../Fixtures/Controller/ModelAdminController.php', $file);
     try {
         $this->controllerGenerator->generate($this->bundleMock, 'ModelAdminController');
     } catch (\RuntimeException $e) {
         $this->assertContains('already exists', $e->getMessage());
         return;
     }
     $this->fail('Failed asserting that exception of type "\\RuntimeException" is thrown.');
 }
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $modelClass = Validators::validateClass($input->getArgument('model'));
     $modelClassBasename = current(array_slice(explode('\\', $modelClass), -1));
     $bundle = $this->getBundle($input->getOption('bundle') ?: $this->getBundleNameFromClass($modelClass));
     $adminClassBasename = $input->getOption('admin') ?: $modelClassBasename . 'Admin';
     $adminClassBasename = Validators::validateAdminClassBasename($adminClassBasename);
     $managerType = $input->getOption('manager') ?: $this->getDefaultManagerType();
     $modelManager = $this->getModelManager($managerType);
     $skeletonDirectory = __DIR__ . '/../Resources/skeleton';
     $adminGenerator = new AdminGenerator($modelManager, $skeletonDirectory);
     try {
         $adminGenerator->generate($bundle, $adminClassBasename, $modelClass);
         $output->writeln(sprintf('%sThe admin class "<info>%s</info>" has been generated under the file "<info>%s</info>".', PHP_EOL, $adminGenerator->getClass(), realpath($adminGenerator->getFile())));
     } catch (\Exception $e) {
         $this->writeError($output, $e->getMessage());
     }
     if ($controllerClassBasename = $input->getOption('controller')) {
         $controllerClassBasename = Validators::validateControllerClassBasename($controllerClassBasename);
         $controllerGenerator = new ControllerGenerator($skeletonDirectory);
         try {
             $controllerGenerator->generate($bundle, $controllerClassBasename);
             $output->writeln(sprintf('%sThe controller class "<info>%s</info>" has been generated under the file "<info>%s</info>".', PHP_EOL, $controllerGenerator->getClass(), realpath($controllerGenerator->getFile())));
         } catch (\Exception $e) {
             $this->writeError($output, $e->getMessage());
         }
     }
     if ($servicesFile = $input->getOption('services')) {
         $adminClass = $adminGenerator->getClass();
         $file = sprintf('%s/Resources/config/%s', $bundle->getPath(), $servicesFile);
         $servicesManipulator = new ServicesManipulator($file);
         $controllerName = $controllerClassBasename ? sprintf('%s:%s', $bundle->getName(), substr($controllerClassBasename, 0, -10)) : 'SonataAdminBundle:CRUD';
         try {
             $id = $input->getOption('id') ?: $this->getAdminServiceId($bundle->getName(), $adminClassBasename);
             $servicesManipulator->addResource($id, $modelClass, $adminClass, $controllerName, $managerType);
             $output->writeln(sprintf('%sThe service "<info>%s</info>" has been appended to the file <info>"%s</info>".', PHP_EOL, $id, realpath($file)));
         } catch (\Exception $e) {
             $this->writeError($output, $e->getMessage());
         }
     }
     return 0;
 }