/** * Service generator test * * @param $module * @param $name * @param $class * @param $interface * @param $services * * @dataProvider commandData */ public function testGenerateService($module, $name, $class, $interface, $services) { $generator = new ServiceGenerator(); $this->getHelperSet()->get('renderer')->setSkeletonDirs($this->getSkeletonDirs()); $this->getHelperSet()->get('renderer')->setTranslator($this->getTranslatorHelper()); $generator->setHelpers($this->getHelperSet()); $generator->generate($module, $name, $class, $interface, $services); $files = [$generator->getSite()->getModulePath($module) . '/' . $module . '.services.yml', $generator->getSite()->getModulePath($module) . '/src/' . $class . '.php']; foreach ($files as $file) { $this->assertTrue(file_exists($file), sprintf('%s does not exist', $file)); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration if (!$this->confirmGeneration($io)) { return; } $module = $input->getOption('module'); $name = $input->getOption('name'); $class = $input->getOption('class'); $interface = $input->getOption('interface'); $services = $input->getOption('services'); $path_service = $input->getOption('path_service'); $available_services = $this->container->getServiceIds(); if (in_array($name, array_values($available_services))) { throw new \Exception(sprintf($this->trans('commands.generate.service.messages.service-already-taken'), $module)); } // @see Drupal\Console\Command\Shared\ServicesTrait::buildServices $build_services = $this->buildServices($services); $this->generator->generate($module, $name, $class, $interface, $build_services, $path_service); $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); }