From a367e983678df383c40dfa0c9175ce129176a16d Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Wed, 14 Feb 2024 14:57:17 +0530 Subject: [PATCH 01/20] GL-2039: Added prompt for nodejs and php project selection. --- .../CodeStudio/CodeStudioCiCdVariables.php | 109 +++++++++++++++++- .../CodeStudio/CodeStudioWizardCommand.php | 71 ++++++++++-- 2 files changed, 170 insertions(+), 10 deletions(-) diff --git a/src/Command/CodeStudio/CodeStudioCiCdVariables.php b/src/Command/CodeStudio/CodeStudioCiCdVariables.php index f81893f59..571c4ea4f 100644 --- a/src/Command/CodeStudio/CodeStudioCiCdVariables.php +++ b/src/Command/CodeStudio/CodeStudioCiCdVariables.php @@ -16,7 +16,114 @@ public static function getList(): array { /** * @return array */ - public static function getDefaults(?string $cloudApplicationUuid = NULL, ?string $cloudKey = NULL, ?string $cloudSecret = NULL, ?string $projectAccessTokenName = NULL, ?string $projectAccessToken = NULL, ?string $phpVersion = NULL): array { + public static function getDefaults(?string $cloudApplicationUuid = NULL, ?string $cloudKey = NULL, ?string $cloudSecret = NULL, ?string $projectAccessTokenName = NULL, ?string $projectAccessToken = NULL, ?string $phpVersion = NULL, ?string $nodeVersion = NULL): array { + return [ + [ + 'key' => 'ACQUIA_APPLICATION_UUID', + 'masked' => TRUE, + 'protected' => FALSE, + 'value' => $cloudApplicationUuid, + 'variable_type' => 'env_var', + ], + [ + 'key' => 'ACQUIA_CLOUD_API_TOKEN_KEY', + 'masked' => TRUE, + 'protected' => FALSE, + 'value' => $cloudKey, + 'variable_type' => 'env_var', + ], + [ + 'key' => 'ACQUIA_CLOUD_API_TOKEN_SECRET', + 'masked' => TRUE, + 'protected' => FALSE, + 'value' => $cloudSecret, + 'variable_type' => 'env_var', + ], + [ + 'key' => 'ACQUIA_GLAB_TOKEN_NAME', + 'masked' => TRUE, + 'protected' => FALSE, + 'value' => $projectAccessTokenName, + 'variable_type' => 'env_var', + ], + [ + 'key' => 'ACQUIA_GLAB_TOKEN_SECRET', + 'masked' => TRUE, + 'protected' => FALSE, + 'value' => $projectAccessToken, + 'variable_type' => 'env_var', + ], + [ + 'key' => 'PHP_VERSION', + 'masked' => FALSE, + 'protected' => FALSE, + 'value' => $phpVersion, + 'variable_type' => 'env_var', + ], + [ + 'key' => 'NODE_VERSION', + 'masked' => FALSE, + 'protected' => FALSE, + 'value' => $nodeVersion, + 'variable_type' => 'env_var', + ], + ]; + } + + /** + * @return array + */ + public static function getDefaultsForNode(?string $cloudApplicationUuid = NULL, ?string $cloudKey = NULL, ?string $cloudSecret = NULL, ?string $projectAccessTokenName = NULL, ?string $projectAccessToken = NULL, ?string $nodeVersion = NULL): array { + return [ + [ + 'key' => 'ACQUIA_APPLICATION_UUID', + 'masked' => TRUE, + 'protected' => FALSE, + 'value' => $cloudApplicationUuid, + 'variable_type' => 'env_var', + ], + [ + 'key' => 'ACQUIA_CLOUD_API_TOKEN_KEY', + 'masked' => TRUE, + 'protected' => FALSE, + 'value' => $cloudKey, + 'variable_type' => 'env_var', + ], + [ + 'key' => 'ACQUIA_CLOUD_API_TOKEN_SECRET', + 'masked' => TRUE, + 'protected' => FALSE, + 'value' => $cloudSecret, + 'variable_type' => 'env_var', + ], + [ + 'key' => 'ACQUIA_GLAB_TOKEN_NAME', + 'masked' => TRUE, + 'protected' => FALSE, + 'value' => $projectAccessTokenName, + 'variable_type' => 'env_var', + ], + [ + 'key' => 'ACQUIA_GLAB_TOKEN_SECRET', + 'masked' => TRUE, + 'protected' => FALSE, + 'value' => $projectAccessToken, + 'variable_type' => 'env_var', + ], + [ + 'key' => 'NODE_VERSION', + 'masked' => FALSE, + 'protected' => FALSE, + 'value' => $nodeVersion, + 'variable_type' => 'env_var', + ], + ]; + } + + /** + * @return array + */ + public static function getDefaultsForPhp(?string $cloudApplicationUuid = NULL, ?string $cloudKey = NULL, ?string $cloudSecret = NULL, ?string $projectAccessTokenName = NULL, ?string $projectAccessToken = NULL, ?string $phpVersion = NULL): array { return [ [ 'key' => 'ACQUIA_APPLICATION_UUID', diff --git a/src/Command/CodeStudio/CodeStudioWizardCommand.php b/src/Command/CodeStudio/CodeStudioWizardCommand.php index 52675b696..098f07089 100644 --- a/src/Command/CodeStudio/CodeStudioWizardCommand.php +++ b/src/Command/CodeStudio/CodeStudioWizardCommand.php @@ -43,13 +43,30 @@ protected function execute(InputInterface $input, OutputInterface $output): int // So we reauthenticate to be sure we're using the provided credentials. $this->reAuthenticate($cloudKey, $cloudSecret, $this->cloudCredentials->getBaseUri(), $this->cloudCredentials->getAccountsUri()); - $phpVersions = [ - 'PHP_version_8.1' => "8.1", - 'PHP_version_8.2' => "8.2", + $projectType = [ + 'Drupal_project', + 'Node_project', ]; - $project = $this->io->choice('Select a PHP version', array_values($phpVersions), $phpVersions['PHP_version_8.1']); - $project = array_search($project, $phpVersions, TRUE); - $phpVersion = $phpVersions[$project]; + $projectSelected = $this->io->choice('Select a project type', $projectType, $projectType[0]); + echo "Selected project is, $projectSelected"; + + if ($projectSelected == 'Drupal_project') { + $phpVersions = [ + 'PHP_version_8.1' => "8.1", + 'PHP_version_8.2' => "8.2", + ]; + $project = $this->io->choice('Select a PHP version', array_values($phpVersions), $phpVersions['PHP_version_8.1']); + $project = array_search($project, $phpVersions, TRUE); + $phpVersion = $phpVersions[$project]; + } elseif ($projectSelected == 'Node_project') { + $nodeVersions = [ + 'NODE_version_18.17.1' => "18.17.1", + 'NODE_version_20.5.1' => "20.5.1", + ]; + $project = $this->io->choice('Select a NODE version', array_values($nodeVersions), $nodeVersions['NODE_version_20.5.1']); + $project = array_search($project, $nodeVersions, TRUE); + $nodeVersion = $nodeVersions[$project]; + } $appUuid = $this->determineCloudApplication(); @@ -97,7 +114,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int $projectAccessTokenName = 'acquia-codestudio'; $projectAccessToken = $this->createProjectAccessToken($project, $projectAccessTokenName); $this->updateGitLabProject($project); - $this->setGitLabCiCdVariables($project, $appUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $phpVersion); + if ($projectSelected == 'Drupal_project') { + $this->setGitLabCiCdVariablesForPhpProject($project, $appUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $phpVersion); + + } elseif ($projectSelected == 'Node_project') { + $this->setGitLabCiCdVariablesForNodeProject($project, $appUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $nodeVersion); + } $this->createScheduledPipeline($project); $this->io->success([ @@ -163,9 +185,37 @@ private function createProjectAccessToken(array $project, string $projectAccessT return $projectAccessToken['token']; } - private function setGitLabCiCdVariables(array $project, string $cloudApplicationUuid, string $cloudKey, string $cloudSecret, string $projectAccessTokenName, string $projectAccessToken, string $phpVersion): void { + private function setGitLabCiCdVariablesForPhpProject(array $project, string $cloudApplicationUuid, string $cloudKey, string $cloudSecret, string $projectAccessTokenName, string $projectAccessToken, string $phpVersion ): void { + $this->io->writeln("Setting GitLab CI/CD variables for {$project['path_with_namespace']}.."); + $gitlabCicdVariables = CodeStudioCiCdVariables::getDefaultsForPhp($cloudApplicationUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $phpVersion); + $gitlabCicdExistingVariables = $this->gitLabClient->projects() + ->variables($project['id']); + $gitlabCicdExistingVariablesKeyed = []; + foreach ($gitlabCicdExistingVariables as $variable) { + $key = $variable['key']; + $gitlabCicdExistingVariablesKeyed[$key] = $variable; + } + + foreach ($gitlabCicdVariables as $variable) { + if ($variable['key'] === 'NODE_VERSION') { + continue; + } + $this->checklist->addItem("Setting CI/CD variable {$variable['key']}"); + if (!array_key_exists($variable['key'], $gitlabCicdExistingVariablesKeyed)) { + $this->gitLabClient->projects() + ->addVariable($project['id'], $variable['key'], $variable['value'], $variable['protected'], NULL, ['masked' => $variable['masked'], 'variable_type' => $variable['variable_type']]); + } + else { + $this->gitLabClient->projects() + ->updateVariable($project['id'], $variable['key'], $variable['value'], $variable['protected'], NULL, ['masked' => $variable['masked'], 'variable_type' => $variable['variable_type']]); + } + $this->checklist->completePreviousItem(); + } + } + + private function setGitLabCiCdVariablesForNodeProject(array $project, string $cloudApplicationUuid, string $cloudKey, string $cloudSecret, string $projectAccessTokenName, string $projectAccessToken, string $nodeVersion ): void { $this->io->writeln("Setting GitLab CI/CD variables for {$project['path_with_namespace']}.."); - $gitlabCicdVariables = CodeStudioCiCdVariables::getDefaults($cloudApplicationUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $phpVersion); + $gitlabCicdVariables = CodeStudioCiCdVariables::getDefaultsForNode($cloudApplicationUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $nodeVersion); $gitlabCicdExistingVariables = $this->gitLabClient->projects() ->variables($project['id']); $gitlabCicdExistingVariablesKeyed = []; @@ -175,6 +225,9 @@ private function setGitLabCiCdVariables(array $project, string $cloudApplication } foreach ($gitlabCicdVariables as $variable) { + if ($variable['key'] === 'PHP_VERSION') { + continue; + } $this->checklist->addItem("Setting CI/CD variable {$variable['key']}"); if (!array_key_exists($variable['key'], $gitlabCicdExistingVariablesKeyed)) { $this->gitLabClient->projects() From 75a720c0c9beb22b78ce43bb3516cd3a5346e130 Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Wed, 14 Feb 2024 16:28:28 +0530 Subject: [PATCH 02/20] GL-2039: Updated getlist for pipeline migrate command to use drupal project as default. --- .../CodeStudio/CodeStudioCiCdVariables.php | 70 ++----------------- 1 file changed, 7 insertions(+), 63 deletions(-) diff --git a/src/Command/CodeStudio/CodeStudioCiCdVariables.php b/src/Command/CodeStudio/CodeStudioCiCdVariables.php index 571c4ea4f..29559668f 100644 --- a/src/Command/CodeStudio/CodeStudioCiCdVariables.php +++ b/src/Command/CodeStudio/CodeStudioCiCdVariables.php @@ -10,69 +10,13 @@ class CodeStudioCiCdVariables { * @return array */ public static function getList(): array { - return array_column(self::getDefaults(), 'key'); + //getlist is being utilised in pipeline-migrate command. By default command is supporting drupal project but going forward need to support both drupal and nodejs project. + return array_column(self::getDefaultsForPhp(), 'key'); } /** - * @return array - */ - public static function getDefaults(?string $cloudApplicationUuid = NULL, ?string $cloudKey = NULL, ?string $cloudSecret = NULL, ?string $projectAccessTokenName = NULL, ?string $projectAccessToken = NULL, ?string $phpVersion = NULL, ?string $nodeVersion = NULL): array { - return [ - [ - 'key' => 'ACQUIA_APPLICATION_UUID', - 'masked' => TRUE, - 'protected' => FALSE, - 'value' => $cloudApplicationUuid, - 'variable_type' => 'env_var', - ], - [ - 'key' => 'ACQUIA_CLOUD_API_TOKEN_KEY', - 'masked' => TRUE, - 'protected' => FALSE, - 'value' => $cloudKey, - 'variable_type' => 'env_var', - ], - [ - 'key' => 'ACQUIA_CLOUD_API_TOKEN_SECRET', - 'masked' => TRUE, - 'protected' => FALSE, - 'value' => $cloudSecret, - 'variable_type' => 'env_var', - ], - [ - 'key' => 'ACQUIA_GLAB_TOKEN_NAME', - 'masked' => TRUE, - 'protected' => FALSE, - 'value' => $projectAccessTokenName, - 'variable_type' => 'env_var', - ], - [ - 'key' => 'ACQUIA_GLAB_TOKEN_SECRET', - 'masked' => TRUE, - 'protected' => FALSE, - 'value' => $projectAccessToken, - 'variable_type' => 'env_var', - ], - [ - 'key' => 'PHP_VERSION', - 'masked' => FALSE, - 'protected' => FALSE, - 'value' => $phpVersion, - 'variable_type' => 'env_var', - ], - [ - 'key' => 'NODE_VERSION', - 'masked' => FALSE, - 'protected' => FALSE, - 'value' => $nodeVersion, - 'variable_type' => 'env_var', - ], - ]; - } - - /** - * @return array - */ + * @return array + */ public static function getDefaultsForNode(?string $cloudApplicationUuid = NULL, ?string $cloudKey = NULL, ?string $cloudSecret = NULL, ?string $projectAccessTokenName = NULL, ?string $projectAccessToken = NULL, ?string $nodeVersion = NULL): array { return [ [ @@ -120,9 +64,9 @@ public static function getDefaultsForNode(?string $cloudApplicationUuid = NULL, ]; } - /** - * @return array - */ + /** + * @return array + */ public static function getDefaultsForPhp(?string $cloudApplicationUuid = NULL, ?string $cloudKey = NULL, ?string $cloudSecret = NULL, ?string $projectAccessTokenName = NULL, ?string $projectAccessToken = NULL, ?string $phpVersion = NULL): array { return [ [ From 5b50c282fd9e4214621a2f70ac652d2cbcbf92d6 Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Wed, 14 Feb 2024 16:47:16 +0530 Subject: [PATCH 03/20] GL-2039: Updated file improving test checks. --- .../CodeStudio/CodeStudioWizardCommand.php | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/Command/CodeStudio/CodeStudioWizardCommand.php b/src/Command/CodeStudio/CodeStudioWizardCommand.php index 098f07089..e4c6cd7ab 100644 --- a/src/Command/CodeStudio/CodeStudioWizardCommand.php +++ b/src/Command/CodeStudio/CodeStudioWizardCommand.php @@ -58,15 +58,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int $project = $this->io->choice('Select a PHP version', array_values($phpVersions), $phpVersions['PHP_version_8.1']); $project = array_search($project, $phpVersions, TRUE); $phpVersion = $phpVersions[$project]; - } elseif ($projectSelected == 'Node_project') { - $nodeVersions = [ - 'NODE_version_18.17.1' => "18.17.1", - 'NODE_version_20.5.1' => "20.5.1", - ]; - $project = $this->io->choice('Select a NODE version', array_values($nodeVersions), $nodeVersions['NODE_version_20.5.1']); - $project = array_search($project, $nodeVersions, TRUE); - $nodeVersion = $nodeVersions[$project]; - } + } + elseif ($projectSelected == 'Node_project') { + $nodeVersions = [ + 'NODE_version_18.17.1' => "18.17.1", + 'NODE_version_20.5.1' => "20.5.1", + ]; + $project = $this->io->choice('Select a NODE version', array_values($nodeVersions), $nodeVersions['NODE_version_20.5.1']); + $project = array_search($project, $nodeVersions, TRUE); + $nodeVersion = $nodeVersions[$project]; + } $appUuid = $this->determineCloudApplication(); @@ -116,10 +117,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->updateGitLabProject($project); if ($projectSelected == 'Drupal_project') { $this->setGitLabCiCdVariablesForPhpProject($project, $appUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $phpVersion); - - } elseif ($projectSelected == 'Node_project') { - $this->setGitLabCiCdVariablesForNodeProject($project, $appUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $nodeVersion); - } + } + elseif ($projectSelected == 'Node_project') { + $this->setGitLabCiCdVariablesForNodeProject($project, $appUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $nodeVersion); + } $this->createScheduledPipeline($project); $this->io->success([ @@ -185,7 +186,7 @@ private function createProjectAccessToken(array $project, string $projectAccessT return $projectAccessToken['token']; } - private function setGitLabCiCdVariablesForPhpProject(array $project, string $cloudApplicationUuid, string $cloudKey, string $cloudSecret, string $projectAccessTokenName, string $projectAccessToken, string $phpVersion ): void { + private function setGitLabCiCdVariablesForPhpProject(array $project, string $cloudApplicationUuid, string $cloudKey, string $cloudSecret, string $projectAccessTokenName, string $projectAccessToken, string $phpVersion): void { $this->io->writeln("Setting GitLab CI/CD variables for {$project['path_with_namespace']}.."); $gitlabCicdVariables = CodeStudioCiCdVariables::getDefaultsForPhp($cloudApplicationUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $phpVersion); $gitlabCicdExistingVariables = $this->gitLabClient->projects() @@ -197,9 +198,6 @@ private function setGitLabCiCdVariablesForPhpProject(array $project, string $clo } foreach ($gitlabCicdVariables as $variable) { - if ($variable['key'] === 'NODE_VERSION') { - continue; - } $this->checklist->addItem("Setting CI/CD variable {$variable['key']}"); if (!array_key_exists($variable['key'], $gitlabCicdExistingVariablesKeyed)) { $this->gitLabClient->projects() @@ -212,8 +210,8 @@ private function setGitLabCiCdVariablesForPhpProject(array $project, string $clo $this->checklist->completePreviousItem(); } } - - private function setGitLabCiCdVariablesForNodeProject(array $project, string $cloudApplicationUuid, string $cloudKey, string $cloudSecret, string $projectAccessTokenName, string $projectAccessToken, string $nodeVersion ): void { + + private function setGitLabCiCdVariablesForNodeProject(array $project, string $cloudApplicationUuid, string $cloudKey, string $cloudSecret, string $projectAccessTokenName, string $projectAccessToken, string $nodeVersion): void { $this->io->writeln("Setting GitLab CI/CD variables for {$project['path_with_namespace']}.."); $gitlabCicdVariables = CodeStudioCiCdVariables::getDefaultsForNode($cloudApplicationUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $nodeVersion); $gitlabCicdExistingVariables = $this->gitLabClient->projects() @@ -225,9 +223,6 @@ private function setGitLabCiCdVariablesForNodeProject(array $project, string $cl } foreach ($gitlabCicdVariables as $variable) { - if ($variable['key'] === 'PHP_VERSION') { - continue; - } $this->checklist->addItem("Setting CI/CD variable {$variable['key']}"); if (!array_key_exists($variable['key'], $gitlabCicdExistingVariablesKeyed)) { $this->gitLabClient->projects() From 6141704c47591b24f85aa7998b0ecf67593fa64f Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Wed, 14 Feb 2024 17:14:38 +0530 Subject: [PATCH 04/20] GL-2039: Updated test file to resolve error in test checks. --- src/Command/CodeStudio/CodeStudioWizardCommand.php | 3 ++- .../CodeStudio/CodeStudioPipelinesMigrateCommandTest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Command/CodeStudio/CodeStudioWizardCommand.php b/src/Command/CodeStudio/CodeStudioWizardCommand.php index e4c6cd7ab..87a1d0d75 100644 --- a/src/Command/CodeStudio/CodeStudioWizardCommand.php +++ b/src/Command/CodeStudio/CodeStudioWizardCommand.php @@ -42,7 +42,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int // But, we specifically need an API Token key-pair of Code Studio. // So we reauthenticate to be sure we're using the provided credentials. $this->reAuthenticate($cloudKey, $cloudSecret, $this->cloudCredentials->getBaseUri(), $this->cloudCredentials->getAccountsUri()); - + $phpVersion = NULL; + $nodeVersion = NULL; $projectType = [ 'Drupal_project', 'Node_project', diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioPipelinesMigrateCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioPipelinesMigrateCommandTest.php index 1c5a0e5a1..25d883f8d 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioPipelinesMigrateCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioPipelinesMigrateCommandTest.php @@ -92,7 +92,7 @@ public function testCommand(mixed $mockedGitlabProjects, mixed $inputs, mixed $a $this->mockRequest('getAccount'); $this->mockGitLabPermissionsRequest($this::$applicationUuid); $projects = $this->mockGetGitLabProjects($this::$applicationUuid, $this->gitLabProjectId, $mockedGitlabProjects); - $projects->variables($this->gitLabProjectId)->willReturn(CodeStudioCiCdVariables::getDefaults()); + $projects->variables($this->gitLabProjectId)->willReturn(CodeStudioCiCdVariables::getDefaultsForPhp()); $projects->update($this->gitLabProjectId, Argument::type('array')); $gitlabClient->projects()->willReturn($projects); $localMachineHelper->getFilesystem()->willReturn(new Filesystem())->shouldBeCalled(); From 60bf6c67023bcee873512fae1c88a952174a9347 Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Wed, 21 Feb 2024 19:05:55 +0530 Subject: [PATCH 05/20] GL-2039: Resolved review commnets and added testcases. --- .../CodeStudio/CodeStudioWizardCommand.php | 1 - .../CodeStudioPipelinesMigrateCommandTest.php | 47 ++++++++++++++++++- .../CodeStudioWizardCommandTest.php | 46 ++++++++++++++++++ 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/src/Command/CodeStudio/CodeStudioWizardCommand.php b/src/Command/CodeStudio/CodeStudioWizardCommand.php index 87a1d0d75..c5524ea4f 100644 --- a/src/Command/CodeStudio/CodeStudioWizardCommand.php +++ b/src/Command/CodeStudio/CodeStudioWizardCommand.php @@ -49,7 +49,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int 'Node_project', ]; $projectSelected = $this->io->choice('Select a project type', $projectType, $projectType[0]); - echo "Selected project is, $projectSelected"; if ($projectSelected == 'Drupal_project') { $phpVersions = [ diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioPipelinesMigrateCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioPipelinesMigrateCommandTest.php index 25d883f8d..1c03be2db 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioPipelinesMigrateCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioPipelinesMigrateCommandTest.php @@ -4,7 +4,6 @@ namespace Acquia\Cli\Tests\Commands\CodeStudio; -use Acquia\Cli\Command\CodeStudio\CodeStudioCiCdVariables; use Acquia\Cli\Command\CodeStudio\CodeStudioPipelinesMigrateCommand; use Acquia\Cli\Command\CommandBase; use Acquia\Cli\Tests\Commands\Ide\IdeRequiredTestTrait; @@ -92,7 +91,51 @@ public function testCommand(mixed $mockedGitlabProjects, mixed $inputs, mixed $a $this->mockRequest('getAccount'); $this->mockGitLabPermissionsRequest($this::$applicationUuid); $projects = $this->mockGetGitLabProjects($this::$applicationUuid, $this->gitLabProjectId, $mockedGitlabProjects); - $projects->variables($this->gitLabProjectId)->willReturn(CodeStudioCiCdVariables::getDefaultsForPhp()); + $gitlabCicdVariables = [ + [ + 'key' => 'ACQUIA_APPLICATION_UUID', + 'masked' => TRUE, + 'protected' => FALSE, + 'value' => NULL, + 'variable_type' => 'env_var', + ], + [ + 'key' => 'ACQUIA_CLOUD_API_TOKEN_KEY', + 'masked' => TRUE, + 'protected' => FALSE, + 'value' => NULL, + 'variable_type' => 'env_var', + ], + [ + 'key' => 'ACQUIA_CLOUD_API_TOKEN_SECRET', + 'masked' => TRUE, + 'protected' => FALSE, + 'value' => NULL, + 'variable_type' => 'env_var', + ], + [ + 'key' => 'ACQUIA_GLAB_TOKEN_NAME', + 'masked' => TRUE, + 'protected' => FALSE, + 'value' => NULL, + 'variable_type' => 'env_var', + ], + [ + 'key' => 'ACQUIA_GLAB_TOKEN_SECRET', + 'masked' => TRUE, + 'protected' => FALSE, + 'value' => NULL, + 'variable_type' => 'env_var', + ], + [ + 'key' => 'PHP_VERSION', + 'masked' => FALSE, + 'protected' => FALSE, + 'value' => NULL, + 'variable_type' => 'env_var', + ], + ]; + $projects->variables($this->gitLabProjectId)->willReturn($gitlabCicdVariables); $projects->update($this->gitLabProjectId, Argument::type('array')); $gitlabClient->projects()->willReturn($projects); $localMachineHelper->getFilesystem()->willReturn(new Filesystem())->shouldBeCalled(); diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php index 40d475eaa..3b8480a65 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php @@ -157,6 +157,29 @@ public function providerTestCommand(): array { $this->key, // Enter Cloud secret, $this->secret, + // Select a project type Drupal_project + '0', + // Select PHP version 8.1 + '0', + // Do you want to continue? + 'y', + ], + // Args + [], + ], + [ + // No projects. + [], + // Inputs + [ + // 'Would you like to create a new Code Studio project? + 'y', + // Enter Cloud Key + $this->key, + // Enter Cloud secret, + $this->secret, + // Select a project type Node_project + '1', // Select PHP version 8.1 '0', // Do you want to continue? @@ -176,6 +199,29 @@ public function providerTestCommand(): array { $this->key, // Enter Cloud secret, $this->secret, + // Select a project type Drupal_project + '0', + // Select PHP version 8.2 + '1', + // Do you want to continue? + 'y', + ], + // Args + [], + ], + [ + // No projects. + [], + // Inputs + [ + // 'Would you like to create a new Code Studio project? + 'y', + // Enter Cloud Key + $this->key, + // Enter Cloud secret, + $this->secret, + // Select a project type Node_project + '1', // Select PHP version 8.2 '1', // Do you want to continue? From 8c0d2da58abc4b140600f4aa9c22b6a8291b7b1c Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Wed, 21 Feb 2024 15:50:33 -0800 Subject: [PATCH 06/20] kill mutant --- tests/phpunit/src/CommandTestBase.php | 11 +++++++++-- .../CodeStudio/CodeStudioWizardCommandTest.php | 7 +++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/src/CommandTestBase.php b/tests/phpunit/src/CommandTestBase.php index 5fb2eebde..1a86adc6e 100644 --- a/tests/phpunit/src/CommandTestBase.php +++ b/tests/phpunit/src/CommandTestBase.php @@ -648,7 +648,7 @@ protected function getMockGitLabVariables(): array { 'key' => 'ACQUIA_APPLICATION_UUID', 'masked' => TRUE, 'protected' => FALSE, - 'value' => '2b3f7cf0-6602-4590-948b-3b07b1b005ef', + 'value' => 'a47ac10b-58cc-4372-a567-0e02b2c3d470', 'variable_type' => 'env_var', ], 1 => [ @@ -656,7 +656,14 @@ protected function getMockGitLabVariables(): array { 'key' => 'ACQUIA_CLOUD_API_TOKEN_KEY', 'masked' => TRUE, 'protected' => FALSE, - 'value' => '111aae74-e81a-4052-b4b9-a27a62e6b6a6', + 'value' => '17feaf34-5d04-402b-9a67-15d5161d24e1', + 'variable_type' => 'env_var', + ], + 2 => [ + 'key' => 'ACQUIA_CLOUD_API_TOKEN_SECRET', + 'masked' => TRUE, + 'protected' => FALSE, + 'value' => 'X1u\/PIQXtYaoeui.4RJSJpGZjwmWYmfl5AUQkAebYE=', 'variable_type' => 'env_var', ], ]; diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php index 3b8480a65..5a2b4379f 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php @@ -463,9 +463,12 @@ protected function mockGitLabNamespaces(ObjectProphecy $gitlabClient): void { } protected function mockGitLabVariables(int $gitlabProjectId, ObjectProphecy $projects): void { - $projects->variables($gitlabProjectId)->willReturn($this->getMockGitLabVariables()); + $variables = $this->getMockGitLabVariables(); + $projects->variables($gitlabProjectId)->willReturn($variables); $projects->addVariable($gitlabProjectId, Argument::type('string'), Argument::type('string'), Argument::type('bool'), NULL, Argument::type('array'))->shouldBeCalled(); - $projects->updateVariable($this->gitLabProjectId, Argument::type('string'), Argument::type('string'), FALSE, NULL, ["masked" => TRUE, "variable_type" => "env_var"])->shouldBeCalled(); + foreach ($variables as $variable) { + $projects->updateVariable($this->gitLabProjectId, $variable['key'], $variable['value'], FALSE, NULL, ['masked' => TRUE, 'variable_type' => 'env_var'])->shouldBeCalled(); + } } } From 51e08a275fb7732ff6401cc78188a59fd83ed433 Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Fri, 23 Feb 2024 15:57:48 +0530 Subject: [PATCH 07/20] GL-2039: Replace if-else with sw-case to resolve mutation warning. --- .../CodeStudio/CodeStudioWizardCommand.php | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/Command/CodeStudio/CodeStudioWizardCommand.php b/src/Command/CodeStudio/CodeStudioWizardCommand.php index c4af7645c..2c6032e1e 100644 --- a/src/Command/CodeStudio/CodeStudioWizardCommand.php +++ b/src/Command/CodeStudio/CodeStudioWizardCommand.php @@ -50,23 +50,25 @@ protected function execute(InputInterface $input, OutputInterface $output): int ]; $projectSelected = $this->io->choice('Select a project type', $projectType, $projectType[0]); - if ($projectSelected == 'Drupal_project') { - $phpVersions = [ - 'PHP_version_8.1' => "8.1", - 'PHP_version_8.2' => "8.2", - ]; - $project = $this->io->choice('Select a PHP version', array_values($phpVersions), $phpVersions['PHP_version_8.1']); - $project = array_search($project, $phpVersions, TRUE); - $phpVersion = $phpVersions[$project]; - } - elseif ($projectSelected == 'Node_project') { - $nodeVersions = [ - 'NODE_version_18.17.1' => "18.17.1", - 'NODE_version_20.5.1' => "20.5.1", - ]; - $project = $this->io->choice('Select a NODE version', array_values($nodeVersions), $nodeVersions['NODE_version_20.5.1']); - $project = array_search($project, $nodeVersions, TRUE); - $nodeVersion = $nodeVersions[$project]; + switch ($projectSelected) { + case "Drupal_project": + $phpVersions = [ + 'PHP_version_8.1' => "8.1", + 'PHP_version_8.2' => "8.2", + ]; + $project = $this->io->choice('Select a PHP version', array_values($phpVersions), $phpVersions['PHP_version_8.1']); + $project = array_search($project, $phpVersions, TRUE); + $phpVersion = $phpVersions[$project]; + break; + case "Node_project": + $nodeVersions = [ + 'NODE_version_18.17.1' => "18.17.1", + 'NODE_version_20.5.1' => "20.5.1", + ]; + $project = $this->io->choice('Select a NODE version', array_values($nodeVersions), $nodeVersions['NODE_version_20.5.1']); + $project = array_search($project, $nodeVersions, TRUE); + $nodeVersion = $nodeVersions[$project]; + break; } $appUuid = $this->determineCloudApplication(); From 3f0507df28249ae0f471b8b5b547534b042de5d7 Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Tue, 27 Feb 2024 19:52:20 +0530 Subject: [PATCH 08/20] GL-2039: Tried adding testcase to kill mutant. --- .../CodeStudio/CodeStudioWizardCommand.php | 16 ++++++++++++---- tests/phpunit/src/CommandTestBase.php | 10 ++++++++++ .../CodeStudio/CodeStudioWizardCommandTest.php | 7 ++++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Command/CodeStudio/CodeStudioWizardCommand.php b/src/Command/CodeStudio/CodeStudioWizardCommand.php index 2c6032e1e..337827a2c 100644 --- a/src/Command/CodeStudio/CodeStudioWizardCommand.php +++ b/src/Command/CodeStudio/CodeStudioWizardCommand.php @@ -44,10 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->reAuthenticate($cloudKey, $cloudSecret, $this->cloudCredentials->getBaseUri(), $this->cloudCredentials->getAccountsUri()); $phpVersion = NULL; $nodeVersion = NULL; - $projectType = [ - 'Drupal_project', - 'Node_project', - ]; + $projectType = $this->getListOfProjectType(); $projectSelected = $this->io->choice('Select a project type', $projectType, $projectType[0]); switch ($projectSelected) { @@ -168,6 +165,17 @@ private function getGitLabProjectAccessTokenByName(array $project, string $name) return NULL; } + /** + * @return array|null ? + */ + private function getListOfProjectType(): ?array { + $array = [ + 'Drupal_project', + 'Node_project', + ]; + return $array; + } + private function createProjectAccessToken(array $project, string $projectAccessTokenName): string { $this->io->writeln("Creating project access token..."); diff --git a/tests/phpunit/src/CommandTestBase.php b/tests/phpunit/src/CommandTestBase.php index 1a86adc6e..ccc940049 100644 --- a/tests/phpunit/src/CommandTestBase.php +++ b/tests/phpunit/src/CommandTestBase.php @@ -669,6 +669,16 @@ protected function getMockGitLabVariables(): array { ]; } + /** + * @return array + */ + protected function getMockProjectTypeValue(): array { + return [ + 'Drupal_project', + 'Node_project', + ]; + } + /** * Normalize strings for Windows tests. * diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php index 5a2b4379f..7fd83c528 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php @@ -302,7 +302,7 @@ public function testCommand(array $mockedGitlabProjects, array $inputs, array $a /** @var Filesystem|ObjectProphecy $fileSystem */ $fileSystem = $this->prophet->prophesize(Filesystem::class); - + $this->mockGitlabProjectType($this->gitLabProjectId); // Set properties and execute. $this->executeCommand($args, $inputs); @@ -462,6 +462,11 @@ protected function mockGitLabNamespaces(ObjectProphecy $gitlabClient): void { $gitlabClient->namespaces()->willReturn($namespaces->reveal()); } + protected function mockGitlabProjectType(int $gitlabProjectId): void { + $projectType = $this->getMockProjectTypeValue(); + $this->assertCount(2, $projectType); + } + protected function mockGitLabVariables(int $gitlabProjectId, ObjectProphecy $projects): void { $variables = $this->getMockGitLabVariables(); $projects->variables($gitlabProjectId)->willReturn($variables); From 828996eca125f5cc2f95d9cd645ff3bc10f71ab6 Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Tue, 27 Feb 2024 21:32:51 +0530 Subject: [PATCH 09/20] GL-2039: Updated testcases and alternate logic. --- .../CodeStudio/CodeStudioWizardCommand.php | 12 +++-- .../CodeStudioWizardCommandTest.php | 52 ++++++++++++++++++- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/Command/CodeStudio/CodeStudioWizardCommand.php b/src/Command/CodeStudio/CodeStudioWizardCommand.php index 337827a2c..81807fe01 100644 --- a/src/Command/CodeStudio/CodeStudioWizardCommand.php +++ b/src/Command/CodeStudio/CodeStudioWizardCommand.php @@ -114,11 +114,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $projectAccessTokenName = 'acquia-codestudio'; $projectAccessToken = $this->createProjectAccessToken($project, $projectAccessTokenName); $this->updateGitLabProject($project); - if ($projectSelected == 'Drupal_project') { - $this->setGitLabCiCdVariablesForPhpProject($project, $appUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $phpVersion); - } - elseif ($projectSelected == 'Node_project') { - $this->setGitLabCiCdVariablesForNodeProject($project, $appUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $nodeVersion); + switch ($projectSelected) { + case "Drupal_project": + $this->setGitLabCiCdVariablesForPhpProject($project, $appUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $phpVersion); + break; + case "Node_project": + $this->setGitLabCiCdVariablesForNodeProject($project, $appUuid, $cloudKey, $cloudSecret, $projectAccessTokenName, $projectAccessToken, $nodeVersion); + break; } $this->createScheduledPipeline($project); diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php index 7fd83c528..865576678 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php @@ -95,6 +95,8 @@ public function providerTestCommand(): array { [ // 'Would you like to create a new Code Studio project? 'y', + // Select a project type Drupal_project + '0', // Select PHP version 8.1 '0', // Do you want to continue? @@ -115,6 +117,8 @@ public function providerTestCommand(): array { [ // 'Would you like to create a new Code Studio project? 'y', + // Select a project type Drupal_project + '0', // Select PHP version 8.2 '1', // Do you want to continue? @@ -128,6 +132,50 @@ public function providerTestCommand(): array { '--secret' => $this->secret, ], ], + [ + // No projects. + [], + // Inputs. + [ + // 'Would you like to create a new Code Studio project? + 'y', + // Select a project type Node_project + '1', + // Select NODE version 18.17.1 + '0', + // Do you want to continue? + 'y', + // Would you like to perform a one time push of code from Acquia Cloud to Code Studio now? (yes/no) [yes]: + 'y', + ], + // Args. + [ + '--key' => $this->key, + '--secret' => $this->secret, + ], + ], + [ + // No projects. + [], + // Inputs. + [ + // 'Would you like to create a new Code Studio project? + 'y', + // Select a project type Node_project + '1', + // Select NODE version 20.5.1 + '1', + // Do you want to continue? + 'y', + // Would you like to perform a one time push of code from Acquia Cloud to Code Studio now? (yes/no) [yes]: + 'y', + ], + // Args. + [ + '--key' => $this->key, + '--secret' => $this->secret, + ], + ], [ // No projects. [], @@ -180,7 +228,7 @@ public function providerTestCommand(): array { $this->secret, // Select a project type Node_project '1', - // Select PHP version 8.1 + // Select NODE version 18.17.1 '0', // Do you want to continue? 'y', @@ -222,7 +270,7 @@ public function providerTestCommand(): array { $this->secret, // Select a project type Node_project '1', - // Select PHP version 8.2 + // Select NODE version 20.5.1 '1', // Do you want to continue? 'y', From 931563e91529dc9a2664bea11851ba4dbf67bd40 Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Wed, 28 Feb 2024 17:56:50 +0530 Subject: [PATCH 10/20] GL-2039: Add assertion to kill mutant FalseValue and TrueValue. --- .../src/Commands/CodeStudio/CodeStudioWizardCommandTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php index 865576678..fee9dde1d 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php @@ -521,6 +521,10 @@ protected function mockGitLabVariables(int $gitlabProjectId, ObjectProphecy $pro $projects->addVariable($gitlabProjectId, Argument::type('string'), Argument::type('string'), Argument::type('bool'), NULL, Argument::type('array'))->shouldBeCalled(); foreach ($variables as $variable) { $projects->updateVariable($this->gitLabProjectId, $variable['key'], $variable['value'], FALSE, NULL, ['masked' => TRUE, 'variable_type' => 'env_var'])->shouldBeCalled(); + $maskedValue = $variable['masked']; + $this->assertEquals(TRUE, $maskedValue); + $protectedValue = $variable['protected']; + $this->assertEquals(FALSE, $protectedValue); } } From 6ed1e9f617849edc774e30ea1b770b3f0e762975 Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Wed, 28 Feb 2024 20:32:50 +0530 Subject: [PATCH 11/20] GL-2039: Applied fix for mutant TRUEVAL and FLASEVAL. --- .../src/Commands/CodeStudio/CodeStudioWizardCommandTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php index fee9dde1d..466ecde89 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php @@ -525,6 +525,12 @@ protected function mockGitLabVariables(int $gitlabProjectId, ObjectProphecy $pro $this->assertEquals(TRUE, $maskedValue); $protectedValue = $variable['protected']; $this->assertEquals(FALSE, $protectedValue); + + $projects->updateVariable($this->gitLabProjectId, $variable['key'], $variable['value'], TRUE, NULL, ['masked' => FALSE, 'variable_type' => 'env_var'])->shouldBeCalled(); + $maskedValue = $variable['masked']; + $this->assertNotEquals(TRUE, $maskedValue); + $protectedValue = $variable['protected']; + $this->assertNotEquals(FALSE, $protectedValue); } } From 56167cf41bb3ac1ee09d749e67518128cbd0c583 Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Wed, 28 Feb 2024 20:42:30 +0530 Subject: [PATCH 12/20] Revert "GL-2039: Applied fix for mutant TRUEVAL and FLASEVAL." This reverts commit 6ed1e9f617849edc774e30ea1b770b3f0e762975. --- .../src/Commands/CodeStudio/CodeStudioWizardCommandTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php index 466ecde89..fee9dde1d 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php @@ -525,12 +525,6 @@ protected function mockGitLabVariables(int $gitlabProjectId, ObjectProphecy $pro $this->assertEquals(TRUE, $maskedValue); $protectedValue = $variable['protected']; $this->assertEquals(FALSE, $protectedValue); - - $projects->updateVariable($this->gitLabProjectId, $variable['key'], $variable['value'], TRUE, NULL, ['masked' => FALSE, 'variable_type' => 'env_var'])->shouldBeCalled(); - $maskedValue = $variable['masked']; - $this->assertNotEquals(TRUE, $maskedValue); - $protectedValue = $variable['protected']; - $this->assertNotEquals(FALSE, $protectedValue); } } From 0dac450ad6b83df7307ce3d7b520a6953f7f4e6a Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Wed, 28 Feb 2024 20:56:15 +0530 Subject: [PATCH 13/20] GL-2039: Applied fix for mutant TRUEVAL and FLASEVAL. --- .../Commands/CodeStudio/CodeStudioWizardCommandTest.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php index fee9dde1d..ef28ceab0 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php @@ -357,6 +357,11 @@ public function testCommand(array $mockedGitlabProjects, array $inputs, array $a // Assertions. $this->assertEquals(0, $this->getStatusCode()); + + $this->mockGitLabVariables($this->gitLabProjectId, $projects, FALSE, TRUE); + $this->executeCommand($args, $inputs); + $this->assertEquals(1, $this->getStatusCode()); + } /** @@ -515,12 +520,12 @@ protected function mockGitlabProjectType(int $gitlabProjectId): void { $this->assertCount(2, $projectType); } - protected function mockGitLabVariables(int $gitlabProjectId, ObjectProphecy $projects): void { + protected function mockGitLabVariables(int $gitlabProjectId, ObjectProphecy $projects, bool $masked = TRUE, bool $protected = FALSE): void { $variables = $this->getMockGitLabVariables(); $projects->variables($gitlabProjectId)->willReturn($variables); $projects->addVariable($gitlabProjectId, Argument::type('string'), Argument::type('string'), Argument::type('bool'), NULL, Argument::type('array'))->shouldBeCalled(); foreach ($variables as $variable) { - $projects->updateVariable($this->gitLabProjectId, $variable['key'], $variable['value'], FALSE, NULL, ['masked' => TRUE, 'variable_type' => 'env_var'])->shouldBeCalled(); + $projects->updateVariable($this->gitLabProjectId, $variable['key'], $variable['value'], $protected, NULL, ['masked' => $masked, 'variable_type' => 'env_var'])->shouldBeCalled(); $maskedValue = $variable['masked']; $this->assertEquals(TRUE, $maskedValue); $protectedValue = $variable['protected']; From 84f8b6094b5ffe2953227d0b7150e916ee9bd739 Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Wed, 28 Feb 2024 20:59:52 +0530 Subject: [PATCH 14/20] Revert "GL-2039: Applied fix for mutant TRUEVAL and FLASEVAL." This reverts commit 0dac450ad6b83df7307ce3d7b520a6953f7f4e6a. --- .../Commands/CodeStudio/CodeStudioWizardCommandTest.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php index ef28ceab0..fee9dde1d 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php @@ -357,11 +357,6 @@ public function testCommand(array $mockedGitlabProjects, array $inputs, array $a // Assertions. $this->assertEquals(0, $this->getStatusCode()); - - $this->mockGitLabVariables($this->gitLabProjectId, $projects, FALSE, TRUE); - $this->executeCommand($args, $inputs); - $this->assertEquals(1, $this->getStatusCode()); - } /** @@ -520,12 +515,12 @@ protected function mockGitlabProjectType(int $gitlabProjectId): void { $this->assertCount(2, $projectType); } - protected function mockGitLabVariables(int $gitlabProjectId, ObjectProphecy $projects, bool $masked = TRUE, bool $protected = FALSE): void { + protected function mockGitLabVariables(int $gitlabProjectId, ObjectProphecy $projects): void { $variables = $this->getMockGitLabVariables(); $projects->variables($gitlabProjectId)->willReturn($variables); $projects->addVariable($gitlabProjectId, Argument::type('string'), Argument::type('string'), Argument::type('bool'), NULL, Argument::type('array'))->shouldBeCalled(); foreach ($variables as $variable) { - $projects->updateVariable($this->gitLabProjectId, $variable['key'], $variable['value'], $protected, NULL, ['masked' => $masked, 'variable_type' => 'env_var'])->shouldBeCalled(); + $projects->updateVariable($this->gitLabProjectId, $variable['key'], $variable['value'], FALSE, NULL, ['masked' => TRUE, 'variable_type' => 'env_var'])->shouldBeCalled(); $maskedValue = $variable['masked']; $this->assertEquals(TRUE, $maskedValue); $protectedValue = $variable['protected']; From c5d2a07df10942373105c3d44768d0c4bb949e76 Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Thu, 29 Feb 2024 10:48:40 +0530 Subject: [PATCH 15/20] GL-2039-1: Added test file for ci-cd variables. --- .../CodeStudio/CodeStudioCiCdVariables.php | 4 +-- .../CodeStudioCiCdVariablesTest.php | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit/src/Commands/CodeStudio/CodeStudioCiCdVariablesTest.php diff --git a/src/Command/CodeStudio/CodeStudioCiCdVariables.php b/src/Command/CodeStudio/CodeStudioCiCdVariables.php index 29559668f..0ac7319fb 100644 --- a/src/Command/CodeStudio/CodeStudioCiCdVariables.php +++ b/src/Command/CodeStudio/CodeStudioCiCdVariables.php @@ -56,7 +56,7 @@ public static function getDefaultsForNode(?string $cloudApplicationUuid = NULL, ], [ 'key' => 'NODE_VERSION', - 'masked' => FALSE, + 'masked' => TRUE, 'protected' => FALSE, 'value' => $nodeVersion, 'variable_type' => 'env_var', @@ -106,7 +106,7 @@ public static function getDefaultsForPhp(?string $cloudApplicationUuid = NULL, ? ], [ 'key' => 'PHP_VERSION', - 'masked' => FALSE, + 'masked' => TRUE, 'protected' => FALSE, 'value' => $phpVersion, 'variable_type' => 'env_var', diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioCiCdVariablesTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioCiCdVariablesTest.php new file mode 100644 index 000000000..2305f4911 --- /dev/null +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioCiCdVariablesTest.php @@ -0,0 +1,34 @@ +getDefaultsForNode(); + foreach ($variables as $variable) { + $maskedValue = $variable['masked']; + $this->assertEquals(TRUE, $maskedValue); + $protectedValue = $variable['protected']; + $this->assertEquals(FALSE, $protectedValue); + } + } + + public function testGetDefaultsForPhp(): void { + $codeStudioCiCdVariablesObj = new CodeStudioCiCdVariables(); + $variables = $codeStudioCiCdVariablesObj->getDefaultsForPhp(); + foreach ($variables as $variable) { + $maskedValue = $variable['masked']; + $this->assertEquals(TRUE, $maskedValue); + $protectedValue = $variable['protected']; + $this->assertEquals(FALSE, $protectedValue); + } + } + +} From badf8a5da6f1acae6f7c9e994ff05bd2a5b21d74 Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Thu, 29 Feb 2024 14:31:06 +0530 Subject: [PATCH 16/20] GL-2039-1: Refactor testcase. --- tests/phpunit/src/CommandTestBase.php | 10 ---------- .../CodeStudio/CodeStudioCiCdVariablesTest.php | 13 ++++--------- .../CodeStudio/CodeStudioWizardCommandTest.php | 10 ---------- 3 files changed, 4 insertions(+), 29 deletions(-) diff --git a/tests/phpunit/src/CommandTestBase.php b/tests/phpunit/src/CommandTestBase.php index ccc940049..1a86adc6e 100644 --- a/tests/phpunit/src/CommandTestBase.php +++ b/tests/phpunit/src/CommandTestBase.php @@ -669,16 +669,6 @@ protected function getMockGitLabVariables(): array { ]; } - /** - * @return array - */ - protected function getMockProjectTypeValue(): array { - return [ - 'Drupal_project', - 'Node_project', - ]; - } - /** * Normalize strings for Windows tests. * diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioCiCdVariablesTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioCiCdVariablesTest.php index 2305f4911..197eec768 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioCiCdVariablesTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioCiCdVariablesTest.php @@ -12,17 +12,12 @@ class CodeStudioCiCdVariablesTest extends TestBase { public function testGetDefaultsForNode(): void { $codeStudioCiCdVariablesObj = new CodeStudioCiCdVariables(); $variables = $codeStudioCiCdVariablesObj->getDefaultsForNode(); - foreach ($variables as $variable) { - $maskedValue = $variable['masked']; - $this->assertEquals(TRUE, $maskedValue); - $protectedValue = $variable['protected']; - $this->assertEquals(FALSE, $protectedValue); - } + $this->testBooleanValues($variables); + $variables = $codeStudioCiCdVariablesObj->getDefaultsForPhp(); + $this->testBooleanValues($variables); } - public function testGetDefaultsForPhp(): void { - $codeStudioCiCdVariablesObj = new CodeStudioCiCdVariables(); - $variables = $codeStudioCiCdVariablesObj->getDefaultsForPhp(); + protected function testBooleanValues(array $variables): void { foreach ($variables as $variable) { $maskedValue = $variable['masked']; $this->assertEquals(TRUE, $maskedValue); diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php index fee9dde1d..7f931751a 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php @@ -350,7 +350,6 @@ public function testCommand(array $mockedGitlabProjects, array $inputs, array $a /** @var Filesystem|ObjectProphecy $fileSystem */ $fileSystem = $this->prophet->prophesize(Filesystem::class); - $this->mockGitlabProjectType($this->gitLabProjectId); // Set properties and execute. $this->executeCommand($args, $inputs); @@ -510,21 +509,12 @@ protected function mockGitLabNamespaces(ObjectProphecy $gitlabClient): void { $gitlabClient->namespaces()->willReturn($namespaces->reveal()); } - protected function mockGitlabProjectType(int $gitlabProjectId): void { - $projectType = $this->getMockProjectTypeValue(); - $this->assertCount(2, $projectType); - } - protected function mockGitLabVariables(int $gitlabProjectId, ObjectProphecy $projects): void { $variables = $this->getMockGitLabVariables(); $projects->variables($gitlabProjectId)->willReturn($variables); $projects->addVariable($gitlabProjectId, Argument::type('string'), Argument::type('string'), Argument::type('bool'), NULL, Argument::type('array'))->shouldBeCalled(); foreach ($variables as $variable) { $projects->updateVariable($this->gitLabProjectId, $variable['key'], $variable['value'], FALSE, NULL, ['masked' => TRUE, 'variable_type' => 'env_var'])->shouldBeCalled(); - $maskedValue = $variable['masked']; - $this->assertEquals(TRUE, $maskedValue); - $protectedValue = $variable['protected']; - $this->assertEquals(FALSE, $protectedValue); } } From c44450f403cc0afc4af05689e82d7864a40fa828 Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Thu, 29 Feb 2024 14:55:40 +0530 Subject: [PATCH 17/20] GL-2039-1: Addressed integer increment mutant. --- src/Command/CodeStudio/CodeStudioWizardCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Command/CodeStudio/CodeStudioWizardCommand.php b/src/Command/CodeStudio/CodeStudioWizardCommand.php index 81807fe01..d9c7850a3 100644 --- a/src/Command/CodeStudio/CodeStudioWizardCommand.php +++ b/src/Command/CodeStudio/CodeStudioWizardCommand.php @@ -53,7 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int 'PHP_version_8.1' => "8.1", 'PHP_version_8.2' => "8.2", ]; - $project = $this->io->choice('Select a PHP version', array_values($phpVersions), $phpVersions['PHP_version_8.1']); + $project = $this->io->choice('Select a PHP version', array_values($phpVersions), "8.1"); $project = array_search($project, $phpVersions, TRUE); $phpVersion = $phpVersions[$project]; break; @@ -62,7 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int 'NODE_version_18.17.1' => "18.17.1", 'NODE_version_20.5.1' => "20.5.1", ]; - $project = $this->io->choice('Select a NODE version', array_values($nodeVersions), $nodeVersions['NODE_version_20.5.1']); + $project = $this->io->choice('Select a NODE version', array_values($nodeVersions), "18.17.1"); $project = array_search($project, $nodeVersions, TRUE); $nodeVersion = $nodeVersions[$project]; break; From 64950f877217145cc6b954f9231a2339a1da88ae Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Thu, 29 Feb 2024 16:44:45 +0530 Subject: [PATCH 18/20] GL-2039-1: Added default value instead of fetching it from array. --- src/Command/CodeStudio/CodeStudioWizardCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/CodeStudio/CodeStudioWizardCommand.php b/src/Command/CodeStudio/CodeStudioWizardCommand.php index d9c7850a3..bd200fdf8 100644 --- a/src/Command/CodeStudio/CodeStudioWizardCommand.php +++ b/src/Command/CodeStudio/CodeStudioWizardCommand.php @@ -45,7 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $phpVersion = NULL; $nodeVersion = NULL; $projectType = $this->getListOfProjectType(); - $projectSelected = $this->io->choice('Select a project type', $projectType, $projectType[0]); + $projectSelected = $this->io->choice('Select a project type', $projectType, "Drupal_project"); switch ($projectSelected) { case "Drupal_project": From d4c44fbcb8560faa3466d72ddfd205bc6e07475f Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Fri, 1 Mar 2024 15:28:56 +0530 Subject: [PATCH 19/20] GL-2039-1: Added assertion to kill MethodCallRemoval mutant. --- src/Command/CodeStudio/CodeStudioWizardCommand.php | 2 +- .../CodeStudio/CodeStudioWizardCommandTest.php | 5 +++++ tests/phpunit/src/Commands/WizardTestBase.php | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Command/CodeStudio/CodeStudioWizardCommand.php b/src/Command/CodeStudio/CodeStudioWizardCommand.php index bd200fdf8..604759eb2 100644 --- a/src/Command/CodeStudio/CodeStudioWizardCommand.php +++ b/src/Command/CodeStudio/CodeStudioWizardCommand.php @@ -210,7 +210,7 @@ private function setGitLabCiCdVariablesForPhpProject(array $project, string $clo } foreach ($gitlabCicdVariables as $variable) { - $this->checklist->addItem("Setting CI/CD variable {$variable['key']}"); + $this->checklist->addItem("Setting GitLab CI/CD variables for {$variable['key']}"); if (!array_key_exists($variable['key'], $gitlabCicdExistingVariablesKeyed)) { $this->gitLabClient->projects() ->addVariable($project['id'], $variable['key'], $variable['value'], $variable['protected'], NULL, ['masked' => $variable['masked'], 'variable_type' => $variable['variable_type']]); diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php index 7f931751a..c519ce54f 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php @@ -352,6 +352,11 @@ public function testCommand(array $mockedGitlabProjects, array $inputs, array $a $fileSystem = $this->prophet->prophesize(Filesystem::class); // Set properties and execute. $this->executeCommand($args, $inputs); + $output = $this->getDisplay(); + $output_strings = $this->getOutputStrings(); + foreach ($output_strings as $output_string) { + self::assertStringContainsString($output_string, $output); + } // Assertions. diff --git a/tests/phpunit/src/Commands/WizardTestBase.php b/tests/phpunit/src/Commands/WizardTestBase.php index a4d2daefb..e12109de3 100644 --- a/tests/phpunit/src/Commands/WizardTestBase.php +++ b/tests/phpunit/src/Commands/WizardTestBase.php @@ -153,4 +153,14 @@ protected function runTestSshKeyAlreadyUploaded(): void { $this->executeCommand(); } + /** + * @return string[] + * An array of strings to inspect the output for. + */ + protected function getOutputStrings(): array { + return [ + "Setting GitLab CI/CD variables for", + ]; + } + } From 529da4eaf5343961cf3eac1d56d6b7b1f8be6f69 Mon Sep 17 00:00:00 2001 From: Akash Karangale Date: Mon, 4 Mar 2024 18:23:27 +0530 Subject: [PATCH 20/20] GL-2039: modified testcase. --- .../src/Commands/CodeStudio/CodeStudioWizardCommandTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php index c519ce54f..ee709894a 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php @@ -517,7 +517,10 @@ protected function mockGitLabNamespaces(ObjectProphecy $gitlabClient): void { protected function mockGitLabVariables(int $gitlabProjectId, ObjectProphecy $projects): void { $variables = $this->getMockGitLabVariables(); $projects->variables($gitlabProjectId)->willReturn($variables); - $projects->addVariable($gitlabProjectId, Argument::type('string'), Argument::type('string'), Argument::type('bool'), NULL, Argument::type('array'))->shouldBeCalled(); + foreach ($variables as $variable) { + $projects->addVariable($this->gitLabProjectId, Argument::type('string'), Argument::type('string'), FALSE, NULL, ['masked' => $variable['masked'], 'variable_type' => $variable['variable_type']])->shouldBeCalled(); + } + // $projects->addVariable($gitlabProjectId, Argument::type('string'), Argument::type('string'), Argument::type('bool'), NULL, Argument::type('array'))->shouldBeCalled(); foreach ($variables as $variable) { $projects->updateVariable($this->gitLabProjectId, $variable['key'], $variable['value'], FALSE, NULL, ['masked' => TRUE, 'variable_type' => 'env_var'])->shouldBeCalled(); }