Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gl 2039: Fixed mutants. #3

Merged
merged 5 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Command/CodeStudio/CodeStudioCiCdVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 4 additions & 4 deletions src/Command/CodeStudio/CodeStudioWizardCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@
$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":
$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 = $this->io->choice('Select a PHP version', array_values($phpVersions), "8.1");
$project = array_search($project, $phpVersions, TRUE);
$phpVersion = $phpVersions[$project];
break;
Expand All @@ -62,7 +62,7 @@
'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;
Expand Down Expand Up @@ -210,16 +210,16 @@
}

foreach ($gitlabCicdVariables as $variable) {
$this->checklist->addItem("Setting CI/CD variable <comment>{$variable['key']}</comment>");
$this->checklist->addItem("Setting GitLab CI/CD variables for <comment>{$variable['key']}</comment>");

Check warning on line 213 in src/Command/CodeStudio/CodeStudioWizardCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ $gitlabCicdExistingVariablesKeyed[$key] = $variable; } foreach ($gitlabCicdVariables as $variable) { - $this->checklist->addItem("Setting GitLab CI/CD variables for <comment>{$variable['key']}</comment>"); + 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 {

Check warning on line 213 in src/Command/CodeStudio/CodeStudioWizardCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ $gitlabCicdExistingVariablesKeyed[$key] = $variable; } foreach ($gitlabCicdVariables as $variable) { - $this->checklist->addItem("Setting GitLab CI/CD variables for <comment>{$variable['key']}</comment>"); + 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 {
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']]);

Check warning on line 216 in src/Command/CodeStudio/CodeStudioWizardCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ foreach ($gitlabCicdVariables as $variable) { $this->checklist->addItem("Setting GitLab CI/CD variables for <comment>{$variable['key']}</comment>"); 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']]); + $this->gitLabClient->projects()->addVariable($project['id'], $variable['key'], $variable['value'], $variable['protected'], NULL, ['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']]); }
}
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();

Check warning on line 222 in src/Command/CodeStudio/CodeStudioWizardCommand.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ } 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
}
}

Expand Down
10 changes: 0 additions & 10 deletions tests/phpunit/src/CommandTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,16 +669,6 @@ protected function getMockGitLabVariables(): array {
];
}

/**
* @return array<mixed>
*/
protected function getMockProjectTypeValue(): array {
return [
'Drupal_project',
'Node_project',
];
}

/**
* Normalize strings for Windows tests.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types = 1);

namespace Acquia\Cli\Tests\Commands\CodeStudio;

use Acquia\Cli\Command\CodeStudio\CodeStudioCiCdVariables;
use Acquia\Cli\Tests\TestBase;

class CodeStudioCiCdVariablesTest extends TestBase {

public function testGetDefaultsForNode(): void {
$codeStudioCiCdVariablesObj = new CodeStudioCiCdVariables();
$variables = $codeStudioCiCdVariablesObj->getDefaultsForNode();
$this->testBooleanValues($variables);
$variables = $codeStudioCiCdVariablesObj->getDefaultsForPhp();
$this->testBooleanValues($variables);
}

protected function testBooleanValues(array $variables): void {
foreach ($variables as $variable) {
$maskedValue = $variable['masked'];
$this->assertEquals(TRUE, $maskedValue);
$protectedValue = $variable['protected'];
$this->assertEquals(FALSE, $protectedValue);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,13 @@ 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);
$output = $this->getDisplay();
$output_strings = $this->getOutputStrings();
foreach ($output_strings as $output_string) {
self::assertStringContainsString($output_string, $output);
}

// Assertions.

Expand Down Expand Up @@ -510,21 +514,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);
}
}

Expand Down
10 changes: 10 additions & 0 deletions tests/phpunit/src/Commands/WizardTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
];
}

}
Loading