From 46b41845d68c3e8a707994931d14a6c846447657 Mon Sep 17 00:00:00 2001 From: Prakhar Jain Date: Thu, 11 Jul 2024 13:06:45 +0530 Subject: [PATCH 1/3] GL-2753 : CS Wizard updated node version select values --- src/Command/CodeStudio/CodeStudioWizardCommand.php | 6 +++--- .../Commands/CodeStudio/CodeStudioWizardCommandTest.php | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Command/CodeStudio/CodeStudioWizardCommand.php b/src/Command/CodeStudio/CodeStudioWizardCommand.php index 1e1c4ded8..602115949 100644 --- a/src/Command/CodeStudio/CodeStudioWizardCommand.php +++ b/src/Command/CodeStudio/CodeStudioWizardCommand.php @@ -62,10 +62,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int break; case "Node_project": $nodeVersions = [ - 'NODE_version_18.17.1' => "18.17.1", - 'NODE_version_20.5.1' => "20.5.1", + 'NODE_version_18' => "18", + 'NODE_version_20' => "20", ]; - $project = $this->io->choice('Select a NODE version', array_values($nodeVersions), "18.17.1"); + $project = $this->io->choice('Select a NODE version', array_values($nodeVersions), "20"); $project = array_search($project, $nodeVersions, true); $nodeVersion = $nodeVersions[$project]; break; diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php index 531a80f0e..b9f4d591e 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php @@ -145,7 +145,7 @@ public function providerTestCommand(): array 'y', // Select a project type Node_project. '1', - // Select NODE version 18.17.1. + // Select NODE version 18. '0', // Do you want to continue? 'y', @@ -167,7 +167,7 @@ public function providerTestCommand(): array 'y', // Select a project type Node_project. '1', - // Select NODE version 20.5.1. + // Select NODE version 20. '1', // Do you want to continue? 'y', @@ -232,7 +232,7 @@ public function providerTestCommand(): array $this->secret, // Select a project type Node_project. '1', - // Select NODE version 18.17.1. + // Select NODE version 18. '0', // Do you want to continue? 'y', @@ -274,7 +274,7 @@ public function providerTestCommand(): array $this->secret, // Select a project type Node_project. '1', - // Select NODE version 20.5.1. + // Select NODE version 20. '1', // Do you want to continue? 'y', From de5d2b1004a3f4c359ac2cd3c720728a4c4c925f Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Thu, 11 Jul 2024 12:20:25 -0700 Subject: [PATCH 2/3] undo style changes --- .../CodeStudio/CodeStudioWizardCommand.php | 63 ++++++++++++------- .../CodeStudioWizardCommandTest.php | 48 ++++++++++---- 2 files changed, 76 insertions(+), 35 deletions(-) diff --git a/src/Command/CodeStudio/CodeStudioWizardCommand.php b/src/Command/CodeStudio/CodeStudioWizardCommand.php index e951cd893..8de74f368 100644 --- a/src/Command/CodeStudio/CodeStudioWizardCommand.php +++ b/src/Command/CodeStudio/CodeStudioWizardCommand.php @@ -152,7 +152,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int */ private function getGitLabScheduleByDescription(array $project, string $scheduledPipelineDescription): ?array { - $existingSchedules = $this->gitLabClient->schedules()->showAll($project['id']); + $existingSchedules = $this->gitLabClient->schedules() + ->showAll($project['id']); foreach ($existingSchedules as $schedule) { if ($schedule['description'] == $scheduledPipelineDescription) { return $schedule; @@ -166,7 +167,8 @@ private function getGitLabScheduleByDescription(array $project, string $schedule */ private function getGitLabProjectAccessTokenByName(array $project, string $name): ?array { - $existingProjectAccessTokens = $this->gitLabClient->projects()->projectAccessTokens($project['id']); + $existingProjectAccessTokens = $this->gitLabClient->projects() + ->projectAccessTokens($project['id']); foreach ($existingProjectAccessTokens as $key => $token) { if ($token['name'] == $name) { return $token; @@ -224,10 +226,16 @@ private function setGitLabCiCdVariablesForPhpProject(array $project, string $clo $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']]); + ->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']]); + ->updateVariable($project['id'], $variable['key'], $variable['value'], $variable['protected'], null, [ + 'masked' => $variable['masked'], + 'variable_type' => $variable['variable_type'], + ]); } $this->checklist->completePreviousItem(); } @@ -249,10 +257,16 @@ private function setGitLabCiCdVariablesForNodeProject(array $project, string $cl $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']]); + ->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']]); + ->updateVariable($project['id'], $variable['key'], $variable['value'], $variable['protected'], null, [ + 'masked' => $variable['masked'], + 'variable_type' => $variable['variable_type'], + ]); } $this->checklist->completePreviousItem(); } @@ -265,20 +279,23 @@ private function createScheduledPipeline(array $project): void if (!$this->getGitLabScheduleByDescription($project, $scheduledPipelineDescription)) { $this->checklist->addItem("Creating scheduled pipeline $scheduledPipelineDescription"); - $pipeline = $this->gitLabClient->schedules()->create($project['id'], [ - // Every Thursday at midnight. - 'cron' => '0 0 * * 4', - 'description' => $scheduledPipelineDescription, - 'ref' => $project['default_branch'], - ]); - $this->gitLabClient->schedules()->addVariable($project['id'], $pipeline['id'], [ - 'key' => 'ACQUIA_JOBS_DEPRECATED_UPDATE', - 'value' => 'true', - ]); - $this->gitLabClient->schedules()->addVariable($project['id'], $pipeline['id'], [ - 'key' => 'ACQUIA_JOBS_COMPOSER_UPDATE', - 'value' => 'true', - ]); + $pipeline = $this->gitLabClient->schedules() + ->create($project['id'], [ + // Every Thursday at midnight. + 'cron' => '0 0 * * 4', + 'description' => $scheduledPipelineDescription, + 'ref' => $project['default_branch'], + ]); + $this->gitLabClient->schedules() + ->addVariable($project['id'], $pipeline['id'], [ + 'key' => 'ACQUIA_JOBS_DEPRECATED_UPDATE', + 'value' => 'true', + ]); + $this->gitLabClient->schedules() + ->addVariable($project['id'], $pipeline['id'], [ + 'key' => 'ACQUIA_JOBS_COMPOSER_UPDATE', + 'value' => 'true', + ]); } else { $this->checklist->addItem("Scheduled pipeline named $scheduledPipelineDescription already exists"); } @@ -289,9 +306,11 @@ private function updateGitLabProject(array $project): void { // Setting the description to match the known pattern will allow us to automatically find the project next time. if ($project['description'] !== $this->gitLabProjectDescription) { - $this->gitLabClient->projects()->update($project['id'], $this->getGitLabProjectDefaults()); + $this->gitLabClient->projects() + ->update($project['id'], $this->getGitLabProjectDefaults()); try { - $this->gitLabClient->projects()->uploadAvatar($project['id'], __DIR__ . '/drupal_icon.png'); + $this->gitLabClient->projects() + ->uploadAvatar($project['id'], __DIR__ . '/drupal_icon.png'); } catch (ValidationFailedException) { $this->io->warning("Failed to upload project avatar"); } diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php index 3f037c226..f91348535 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php @@ -29,9 +29,11 @@ class CodeStudioWizardCommandTest extends WizardTestBase use IdeRequiredTestTrait; private string $gitLabHost = 'gitlabhost'; + private string $gitLabToken = 'gitlabtoken'; private int $gitLabProjectId = 33; + private int $gitLabTokenId = 118; public function setUp(): void @@ -76,7 +78,10 @@ public function providerTestCommand(): array ], // Two projects. [ - [$this->getMockedGitLabProject($this->gitLabProjectId), $this->getMockedGitLabProject($this->gitLabProjectId)], + [ + $this->getMockedGitLabProject($this->gitLabProjectId), + $this->getMockedGitLabProject($this->gitLabProjectId), + ], // Inputs. [ // Found multiple projects that could match the Sample application 1 application. Choose which one to configure. @@ -290,7 +295,8 @@ public function providerTestCommand(): array */ public function testCommand(array $mockedGitlabProjects, array $inputs, array $args): void { - $this->clientServiceProphecy->setConnector(Argument::type(Connector::class))->shouldBeCalled(); + $this->clientServiceProphecy->setConnector(Argument::type(Connector::class)) + ->shouldBeCalled(); $this->mockRequest('getAccount'); $this->mockGitLabPermissionsRequest($this::$applicationUuid); @@ -308,7 +314,8 @@ public function testCommand(array $mockedGitlabProjects, array $inputs, array $a 'namespace_id' => 47, 'topics' => 'Acquia Cloud Application', ]; - $projects->create('Sample-application-1', $parameters)->willReturn($this->getMockedGitLabProject($this->gitLabProjectId)); + $projects->create('Sample-application-1', $parameters) + ->willReturn($this->getMockedGitLabProject($this->gitLabProjectId)); $this->mockGitLabProjectsTokens($projects); $parameters = [ 'container_registry_access_level' => 'disabled', @@ -317,7 +324,8 @@ public function testCommand(array $mockedGitlabProjects, array $inputs, array $a 'initialize_with_readme' => true, 'topics' => 'Acquia Cloud Application', ]; - $projects->update($this->gitLabProjectId, $parameters)->shouldBeCalled(); + $projects->update($this->gitLabProjectId, $parameters) + ->shouldBeCalled(); $projects->uploadAvatar( 33, Argument::type('string'), @@ -328,7 +336,8 @@ public function testCommand(array $mockedGitlabProjects, array $inputs, array $a $parameters = [ 'ci_config_path' => 'gitlab-ci/Auto-DevOps.acquia.gitlab-ci.yml@acquia/node-template', ]; - $projects->update($this->gitLabProjectId, $parameters)->shouldBeCalled(); + $projects->update($this->gitLabProjectId, $parameters) + ->shouldBeCalled(); } else { $schedules = $this->prophet->prophesize(Schedules::class); $schedules->showAll($this->gitLabProjectId)->willReturn([]); @@ -339,7 +348,8 @@ public function testCommand(array $mockedGitlabProjects, array $inputs, array $a 'description' => 'Code Studio Automatic Updates', 'ref' => 'master', ]; - $schedules->create($this->gitLabProjectId, $parameters)->willReturn($pipeline); + $schedules->create($this->gitLabProjectId, $parameters) + ->willReturn($pipeline); $schedules->addVariable($this->gitLabProjectId, $pipeline['id'], [ 'key' => 'ACQUIA_JOBS_DEPRECATED_UPDATE', 'value' => 'true', @@ -359,8 +369,10 @@ public function testCommand(array $mockedGitlabProjects, array $inputs, array $a $localMachineHelper->checkRequiredBinariesExist(['git']); $this->mockExecuteGlabExists($localMachineHelper); $process = $this->mockProcess(); - $localMachineHelper->execute(Argument::containing('remote'), Argument::type('callable'), '/home/ide/project', false)->willReturn($process->reveal()); - $localMachineHelper->execute(Argument::containing('push'), Argument::type('callable'), '/home/ide/project', false)->willReturn($process->reveal()); + $localMachineHelper->execute(Argument::containing('remote'), Argument::type('callable'), '/home/ide/project', false) + ->willReturn($process->reveal()); + $localMachineHelper->execute(Argument::containing('push'), Argument::type('callable'), '/home/ide/project', false) + ->willReturn($process->reveal()); $this->mockGetCurrentBranchName($localMachineHelper); $this->mockGitlabGetHost($localMachineHelper, $this->gitLabHost); @@ -434,11 +446,15 @@ protected function mockGitLabProjectsTokens(ObjectProphecy $projects): void 'user_id' => 154, ], ]; - $projects->projectAccessTokens($this->gitLabProjectId)->willReturn($tokens)->shouldBeCalled(); - $projects->deleteProjectAccessToken($this->gitLabProjectId, $this->gitLabTokenId)->shouldBeCalled(); + $projects->projectAccessTokens($this->gitLabProjectId) + ->willReturn($tokens) + ->shouldBeCalled(); + $projects->deleteProjectAccessToken($this->gitLabProjectId, $this->gitLabTokenId) + ->shouldBeCalled(); $token = $tokens[0]; $token['token'] = 'token'; - $projects->createProjectAccessToken($this->gitLabProjectId, Argument::type('array'))->willReturn($token); + $projects->createProjectAccessToken($this->gitLabProjectId, Argument::type('array')) + ->willReturn($token); } protected function mockGetCurrentBranchName(mixed $localMachineHelper): void @@ -542,10 +558,16 @@ protected function mockGitLabVariables(int $gitlabProjectId, ObjectProphecy $pro $variables = $this->getMockGitLabVariables(); $projects->variables($gitlabProjectId)->willReturn($variables); foreach ($variables as $variable) { - $projects->addVariable($gitlabProjectId, Argument::type('string'), Argument::type('string'), Argument::type('bool'), null, ['masked' => $variable['masked'], 'variable_type' => $variable['variable_type']])->shouldBeCalled(); + $projects->addVariable($gitlabProjectId, Argument::type('string'), Argument::type('string'), Argument::type('bool'), null, [ + 'masked' => $variable['masked'], + 'variable_type' => $variable['variable_type'], + ])->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'], false, null, [ + 'masked' => true, + 'variable_type' => 'env_var', + ])->shouldBeCalled(); } } } From 9780a6605ae1ec6052084fe36711a02dee1fb3f2 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Thu, 11 Jul 2024 13:03:01 -0700 Subject: [PATCH 3/3] kill mutant --- .../CodeStudioWizardCommandTest.php | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php index f91348535..af42d76f9 100644 --- a/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php +++ b/tests/phpunit/src/Commands/CodeStudio/CodeStudioWizardCommandTest.php @@ -65,6 +65,8 @@ public function providerTestCommand(): array [$this->getMockedGitLabProject($this->gitLabProjectId)], // Inputs. [ + 0, + 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]: @@ -84,6 +86,9 @@ public function providerTestCommand(): array ], // Inputs. [ + 0, + 0, + 'n', // Found multiple projects that could match the Sample application 1 application. Choose which one to configure. '0', // Do you want to continue? @@ -102,6 +107,8 @@ public function providerTestCommand(): array [], // Inputs. [ + 0, + 0, // 'Would you like to create a new Code Studio project? 'y', // Select a project type Drupal_project. @@ -124,8 +131,6 @@ public function providerTestCommand(): array [], // Inputs. [ - // 'Would you like to create a new Code Studio project? - 'y', // Select a project type Drupal_project. '0', // Select PHP version 8.2. @@ -146,8 +151,6 @@ public function providerTestCommand(): array [], // Inputs. [ - // 'Would you like to create a new Code Studio project? - 'y', // Select a project type Node_project. '1', // Select NODE version 18. @@ -168,8 +171,6 @@ public function providerTestCommand(): array [], // Inputs. [ - // 'Would you like to create a new Code Studio project? - 'y', // Select a project type Node_project. '1', // Select NODE version 20. @@ -190,8 +191,10 @@ public function providerTestCommand(): array [], // Inputs. [ - // 'Would you like to create a new Code Studio project? - 'n', + 0, + 0, + 'y', + 'y', // Choose project. '0', // Do you want to continue? @@ -208,8 +211,6 @@ public function providerTestCommand(): array [], // Inputs. [ - // 'Would you like to create a new Code Studio project? - 'y', // Enter Cloud Key. $this->key, // Enter Cloud secret,. @@ -229,8 +230,6 @@ public function providerTestCommand(): array [], // Inputs. [ - // 'Would you like to create a new Code Studio project? - 'y', // Enter Cloud Key. $this->key, // Enter Cloud secret,. @@ -250,8 +249,6 @@ public function providerTestCommand(): array [], // Inputs. [ - // 'Would you like to create a new Code Studio project? - 'y', // Enter Cloud Key. $this->key, // Enter Cloud secret,. @@ -271,8 +268,6 @@ public function providerTestCommand(): array [], // Inputs. [ - // 'Would you like to create a new Code Studio project? - 'y', // Enter Cloud Key. $this->key, // Enter Cloud secret,. @@ -332,7 +327,7 @@ public function testCommand(array $mockedGitlabProjects, array $inputs, array $a )->shouldBeCalled(); $this->mockGitLabVariables($this->gitLabProjectId, $projects); - if ($inputs[0] === 'y' && ($inputs[1] === '1' || (array_key_exists(3, $inputs) && $inputs[3] === '1'))) { + if (($inputs[0] === '1' || (array_key_exists(2, $inputs) && $inputs[2] === '1'))) { $parameters = [ 'ci_config_path' => 'gitlab-ci/Auto-DevOps.acquia.gitlab-ci.yml@acquia/node-template', ]; @@ -387,6 +382,7 @@ public function testCommand(array $mockedGitlabProjects, array $inputs, array $a foreach ($output_strings as $output_string) { self::assertStringContainsString($output_string, $output); } + self::assertStringNotContainsString('[ERROR]', $output); // Assertions. $this->assertEquals(0, $this->getStatusCode());