diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 85d7c2d6d..5556e92cc 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -136,13 +136,13 @@ jobs: sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional - name: "Run PHPUnit tests" - if: ${{ matrix.drupal-core != '9.5.x' || matrix.php-version != '8.1' }} + if: ${{ matrix.drupal-core != '10.1.x' || matrix.php-version != '8.1' }} run: | cd drupal vendor/bin/phpunit -c core --verbose --color --group apigee_edge --testsuite unit,kernel,functional,functional-javascript modules/contrib/apigee_edge - name: "Run PHPUnit tests with Code Coverage" - if: ${{ matrix.drupal-core == '9.5.x' && matrix.php-version == '8.1' }} + if: ${{ matrix.drupal-core == '10.1.x' && matrix.php-version == '8.1' }} run: | cd drupal cp modules/contrib/apigee_edge/phpunit.core.xml.dist core/phpunit.xml @@ -156,7 +156,7 @@ jobs: path: drupal/sites/simpletest/browser_output/* - name: Upload coverage to Codecov - if: ${{ matrix.drupal-core == '9.5.x' && matrix.php-version == '8.1' }} + if: ${{ matrix.drupal-core == '10.1.x' && matrix.php-version == '8.1' }} uses: codecov/codecov-action@v3 with: files: /tmp/coverage_${{ matrix.instance-type }}.xml diff --git a/src/Command/CommandBase.php b/src/Command/CommandBase.php deleted file mode 100644 index 941d56da6..000000000 --- a/src/Command/CommandBase.php +++ /dev/null @@ -1,129 +0,0 @@ -cliService = $cli_service; - $this->logMessageParser = $log_message_parser; - $this->loggerChannelFactory = $logger_channel_factory; - } - - /** - * Sets up the IO interface. - * - * @param \Symfony\Component\Console\Input\InputInterface $input - * The input interface. - * @param \Symfony\Component\Console\Output\OutputInterface $output - * The output interface. - */ - protected function setupIo(InputInterface $input, OutputInterface $output) { - $this->io = new DrupalStyle($input, $output); - $this->setupLogger($output); - } - - /** - * Sets up the logger service. - * - * The service redirects Drupal logging messages to the console output. - * - * @param \Symfony\Component\Console\Output\OutputInterface $output - * The output interface. - */ - protected function setupLogger(OutputInterface $output) { - $drupal_console_logger = new ConsoleLogger($output); - $logger = new DrupalConsoleLog($this->logMessageParser, $drupal_console_logger); - $this->loggerChannelFactory->addLogger($logger); - } - - /** - * Gets the IO interface. - * - * @return \Symfony\Component\Console\Style\StyleInterface - * The IO interface. - */ - public function getIo(): StyleInterface { - return $this->io; - } - -} diff --git a/src/Command/CreateEdgeRoleCommand.php b/src/Command/CreateEdgeRoleCommand.php deleted file mode 100644 index 0e74c35c0..000000000 --- a/src/Command/CreateEdgeRoleCommand.php +++ /dev/null @@ -1,116 +0,0 @@ -setName('apigee_edge:role:create') - ->setDescription($this->trans('commands.apigee_edge.role.create.description')) - ->setHelp('commands.apigee_edge.role.create.help') - ->addArgument( - 'org', - InputArgument::REQUIRED, - $this->trans('commands.apigee_edge.role.create.arguments.org') - ) - ->addArgument( - 'email', - InputArgument::REQUIRED, - $this->trans('commands.apigee_edge.role.create.arguments.email') - ) - ->addOption( - 'password', - 'p', - InputArgument::OPTIONAL, - $this->trans('commands.apigee_edge.role.create.options.password') - ) - ->addOption( - 'base-url', - 'b', - InputArgument::OPTIONAL, - $this->trans('commands.apigee_edge.role.create.options.base-url') - ) - ->addOption( - 'role-name', - 'r', - InputArgument::OPTIONAL, - $this->trans('commands.apigee_edge.role.create.options.role-name') - )->addOption( - 'force', - 'f', - InputOption::VALUE_NONE, - $this->trans('commands.apigee_edge.role.create.options.force') - ); - - } - - /** - * {@inheritdoc} - */ - public function interact(InputInterface $input, OutputInterface $output) { - $this->setupIo($input, $output); - $password = $input->getOption('password'); - if (!$password) { - $password = $this->getIo()->askHidden( - $this->trans('commands.apigee_edge.role.create.questions.password') - ); - $input->setOption('password', $password); - } - } - - /** - * {@inheritdoc} - */ - public function execute(InputInterface $input, OutputInterface $output) { - $this->setupIo($input, $output); - $org = $input->getArgument('org'); - $email = $input->getArgument('email'); - $password = $input->getOption('password'); - $base_url = $input->getOption('base-url'); - $role_name = $input->getOption('role-name'); - $force = $input->getOption('force'); - - $this->cliService->createEdgeRoleForDrupal($this->getIo(), 't', $org, $email, $password, $base_url, $role_name, $force); - } - -} diff --git a/src/Command/DeveloperSyncCommand.php b/src/Command/DeveloperSyncCommand.php deleted file mode 100644 index c07a3bf3e..000000000 --- a/src/Command/DeveloperSyncCommand.php +++ /dev/null @@ -1,58 +0,0 @@ -setName('apigee_edge:sync') - ->setDescription($this->trans('commands.apigee_edge.sync.description')); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) { - $this->setupIo($input, $output); - $this->cliService->sync($this->getIo(), 't'); - } - -} diff --git a/src/Command/DrupalConsoleLog.php b/src/Command/DrupalConsoleLog.php deleted file mode 100644 index ea4322fed..000000000 --- a/src/Command/DrupalConsoleLog.php +++ /dev/null @@ -1,106 +0,0 @@ -logMessageParser = $log_message_parser; - $this->logger = $logger; - } - - /** - * {@inheritdoc} - */ - public function log($level, $message, array $context = []) { - switch ($level) { - case RfcLogLevel::ERROR: - $error_type = LogLevel::ERROR; - break; - - case RfcLogLevel::WARNING: - $error_type = LogLevel::WARNING; - break; - - case RfcLogLevel::DEBUG: - $error_type = LogLevel::DEBUG; - break; - - case RfcLogLevel::INFO: - $error_type = LogLevel::INFO; - break; - - case RfcLogLevel::NOTICE: - $error_type = LogLevel::NOTICE; - break; - - default: - $error_type = $level; - break; - } - - $message_placeholders = $this->logMessageParser->parseMessagePlaceholders($message, $context); - $message_placeholders = array_filter($message_placeholders, function ($element) { - return is_scalar($element) || is_callable([$element, '__toString']); - }); - $message = empty($message_placeholders) ? $message : strtr($message, $message_placeholders); - - $this->logger->log($error_type, $message, $context); - } - -} diff --git a/tests/src/Unit/Command/CreateEdgeRoleCommandTest.php b/tests/src/Unit/Command/CreateEdgeRoleCommandTest.php deleted file mode 100644 index 8ffd42b88..000000000 --- a/tests/src/Unit/Command/CreateEdgeRoleCommandTest.php +++ /dev/null @@ -1,243 +0,0 @@ -markTestSkipped('Skipping because Drupal Console is not installed.'); - } - - parent::setUp(); - $this->prophet = new Prophet(); - $this->cliService = $this->prophet->prophesize(CliServiceInterface::class); - $this->logMessageParser = $this->prophet->prophesize(LogMessageParserInterface::class); - $this->loggerChannelFactory = $this->prophet->prophesize(LoggerChannelFactoryInterface::class); - $this->createEdgeRoleCommand = new CreateEdgeRoleCommand($this->cliService->reveal(), - $this->logMessageParser->reveal(), $this->loggerChannelFactory->reveal()); - - $this->input = $this->prophet->prophesize(InputInterface::class); - $this->output = $this->prophet->prophesize(OutputInterface::class); - $this->io = $this->prophet->prophesize(DrupalStyle::class); - - $this->outputFormatter = $this->prophet->prophesize(OutputFormatterInterface::class)->reveal(); - $this->output->getFormatter()->willReturn($this->outputFormatter); - $this->output->getVerbosity()->willReturn(OutputInterface::VERBOSITY_DEBUG); - } - - /** - * Calls to Drush command should pass through to CLI service. - */ - public function testCreateEdgeRole() { - $this->input->getArgument(Argument::type('string'))->willReturn('XXX'); - $this->input->getOption(Argument::type('string'))->willReturn('XXX'); - - $this->createEdgeRoleCommand->execute($this->input->reveal(), $this->output->reveal()); - - $this->cliService->createEdgeRoleForDrupal( - Argument::type(DrupalStyle::class), - Argument::type('string'), - Argument::type('string'), - Argument::type('string'), - Argument::type('string'), - Argument::type('string'), - Argument::type('string'), - Argument::type('bool') - )->shouldHaveBeenCalledTimes(1); - } - - /** - * Calls to Drush command should pass through to CLI service. - */ - public function testCreateEdgeRoleForceParam() { - $this->input->getArgument(Argument::is('org'))->willReturn('myorg'); - $this->input->getArgument(Argument::is('email'))->willReturn('email@example.com'); - $this->input->getOption(Argument::is('password'))->willReturn('secret'); - $this->input->getOption(Argument::is('base-url'))->willReturn('http://base-url'); - $this->input->getOption(Argument::is('role-name'))->willReturn('custom_drupal_role'); - $this->input->getOption(Argument::is('force'))->willReturn('true'); - - $this->createEdgeRoleCommand->execute($this->input->reveal(), $this->output->reveal()); - - $this->cliService->createEdgeRoleForDrupal( - Argument::type(DrupalStyle::class), - Argument::type('string'), - Argument::type('string'), - Argument::type('string'), - Argument::type('string'), - Argument::type('string'), - Argument::type('string'), - Argument::type('bool') - )->shouldHaveBeenCalledTimes(1); - } - - /** - * Test validateCreateEdgeRole function does not prompt for password. - * - * When password option is set, do not prompt for password. - */ - public function testInteractWithPasswordParam() { - - $this->input->getArgument(Argument::type('string'))->willReturn('XXX'); - $this->input->getOption('password')->willReturn('secret'); - $this->input->getOption(Argument::type('string'))->willReturn('XXX'); - $this->input->isInteractive()->willReturn(FALSE); - - $this->createEdgeRoleCommand->interact($this->input->reveal(), $this->output->reveal()); - - // Interact should not change password since it was passed in. - $this->input->getOption('password')->shouldHaveBeenCalled(); - $this->input->setOption('password')->shouldNotHaveBeenCalled(); - } - - /** - * Test validateCreateEdgeRole prompts for password. - * - * When password option not set, password should be inputted by user. - */ - public function testInteractPasswordParamEmpty() { - - $this->input->getArgument(Argument::type('string'))->willReturn('XXX'); - $this->input->getOption('password')->willReturn(NULL); - $this->input->getOption(Argument::type('string'))->willReturn('XXX'); - $this->input->setOption(Argument::type('string'), NULL)->willReturn(NULL); - $this->input->isInteractive()->willReturn(FALSE); - - $this->createEdgeRoleCommand->interact($this->input->reveal(), $this->output->reveal()); - - // Interact should not change password since it was passed in. - $this->input->getOption('password')->shouldHaveBeenCalled(); - $this->input->setOption('password', NULL)->shouldHaveBeenCalled(); - } - - } -} - -namespace { - - // phpcs:disable PSR2.Namespaces.UseDeclaration.UseAfterNamespace - use Drush\Utils\StringUtils; - - if (!function_exists('t')) { - - /** - * Mock out t() so function exists for tests. - * - * @param string $message - * The string with placeholders to be interpolated. - * @param array $context - * An associative array of values to be inserted into the message. - * - * @return string - * The resulting string with all placeholders filled in. - */ - function t(string $message, array $context = []): string { - return StringUtils::interpolate($message, $context); - } - - } - -}