diff --git a/tests/phpunit/src/CommandTestBase.php b/tests/phpunit/src/CommandTestBase.php index 6a88930ae..50d4a8d36 100644 --- a/tests/phpunit/src/CommandTestBase.php +++ b/tests/phpunit/src/CommandTestBase.php @@ -16,8 +16,6 @@ use Gitlab\Api\Projects; use Gitlab\Api\Users; use Gitlab\Exception\RuntimeException; -use GuzzleHttp\Client; -use GuzzleHttp\Psr7\Response; use PHPUnit\Framework\Constraint\StringContains; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; diff --git a/tests/phpunit/src/Commands/App/AppOpenCommandTest.php b/tests/phpunit/src/Commands/App/AppOpenCommandTest.php index fd77fc9b6..cb7d4c15c 100644 --- a/tests/phpunit/src/Commands/App/AppOpenCommandTest.php +++ b/tests/phpunit/src/Commands/App/AppOpenCommandTest.php @@ -30,17 +30,11 @@ public function testAppOpenCommand(): void $this->executeCommand(['applicationUuid' => $applicationUuid]); } - /** - * @group brokenProphecy - */ public function testAppOpenNoBrowser(): void { - $applicationUuid = 'a47ac10b-58cc-4372-a567-0e02b2c3d470'; $localMachineHelper = $this->mockLocalMachineHelper(); $localMachineHelper->isBrowserAvailable()->willReturn(false); - $this->mockApplicationRequest(); - $this->createMockAcliConfigFile($applicationUuid); $this->expectException(AcquiaCliException::class); $this->expectExceptionMessage('No browser is available on this machine'); $this->executeCommand(); diff --git a/tests/phpunit/src/Commands/App/LinkCommandTest.php b/tests/phpunit/src/Commands/App/LinkCommandTest.php index e51cb2e2a..1f9a518f7 100644 --- a/tests/phpunit/src/Commands/App/LinkCommandTest.php +++ b/tests/phpunit/src/Commands/App/LinkCommandTest.php @@ -43,6 +43,8 @@ public function testLinkCommand(): void public function testLinkCommandAlreadyLinked(): void { $this->createMockAcliConfigFile('a47ac10b-58cc-4372-a567-0e02b2c3d470'); + $this->createDataStores(); + $this->command = $this->injectCommand(LinkCommand::class); $this->mockApplicationRequest(); $this->executeCommand(); $output = $this->getDisplay(); diff --git a/tests/phpunit/src/Commands/App/UnlinkCommandTest.php b/tests/phpunit/src/Commands/App/UnlinkCommandTest.php index 067e331f0..52e8dc37d 100644 --- a/tests/phpunit/src/Commands/App/UnlinkCommandTest.php +++ b/tests/phpunit/src/Commands/App/UnlinkCommandTest.php @@ -29,6 +29,8 @@ public function testUnlinkCommand(): void $cloudApplication = $applicationsResponse->{'_embedded'}->items[0]; $cloudApplicationUuid = $cloudApplication->uuid; $this->createMockAcliConfigFile($cloudApplicationUuid); + $this->createDataStores(); + $this->command = $this->injectCommand(UnlinkCommand::class); $this->mockApplicationRequest(); // Assert we set it correctly. diff --git a/tests/phpunit/src/Commands/CommandBaseTest.php b/tests/phpunit/src/Commands/CommandBaseTest.php index 7073b3ea7..04fe9c99e 100644 --- a/tests/phpunit/src/Commands/CommandBaseTest.php +++ b/tests/phpunit/src/Commands/CommandBaseTest.php @@ -41,9 +41,10 @@ public function testUnauthenticatedFailure(): void public function testCloudAppFromLocalConfig(): void { - $this->command = $this->injectCommand(IdeListCommand::class); $this->mockRequest('getApplicationIdes', 'a47ac10b-58cc-4372-a567-0e02b2c3d470'); $this->createMockAcliConfigFile('a47ac10b-58cc-4372-a567-0e02b2c3d470'); + $this->createDataStores(); + $this->command = $this->injectCommand(IdeListCommand::class); $this->executeCommand(); } diff --git a/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php b/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php index 1d14a2135..6c85126d5 100644 --- a/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php +++ b/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php @@ -122,12 +122,15 @@ public function testPushTagArtifact(): void public function testPushArtifactWithAcquiaCliFile(): void { - $this->datastoreAcli->set('push.artifact.destination_git_urls', [ + $destinationGitUrls = [ 'https://github.com/example1/cli.git', 'https://github.com/example2/cli.git', - ]); + ]; + $this->createMockAcliConfigFile(['push' => ['artifact' => ['destination_git_urls' => $destinationGitUrls],],]); + $this->createDataStores(); + $this->command = $this->injectCommand(PushArtifactCommand::class); $localMachineHelper = $this->mockLocalMachineHelper(); - $this->setUpPushArtifact($localMachineHelper, 'master', $this->datastoreAcli->get('push.artifact.destination_git_urls')); + $this->setUpPushArtifact($localMachineHelper, 'master', $destinationGitUrls); $this->executeCommand([ '--destination-git-branch' => 'master', ]); diff --git a/tests/phpunit/src/Commands/Remote/AliasesDownloadCommandTest.php b/tests/phpunit/src/Commands/Remote/AliasesDownloadCommandTest.php index 1a4982ee5..4fdf77ff7 100644 --- a/tests/phpunit/src/Commands/Remote/AliasesDownloadCommandTest.php +++ b/tests/phpunit/src/Commands/Remote/AliasesDownloadCommandTest.php @@ -77,6 +77,8 @@ public function testRemoteAliasesDownloadCommand(array $inputs, array $args, str $cloudApplication = $applicationsResponse->{'_embedded'}->items[0]; $cloudApplicationUuid = $cloudApplication->uuid; $this->createMockAcliConfigFile($cloudApplicationUuid); + $this->createDataStores(); + $this->command = $this->injectCommand(AliasesDownloadCommand::class); $this->mockApplicationRequest(); } diff --git a/tests/phpunit/src/Commands/TelemetryCommandTest.php b/tests/phpunit/src/Commands/TelemetryCommandTest.php index e612ac2f2..937952544 100644 --- a/tests/phpunit/src/Commands/TelemetryCommandTest.php +++ b/tests/phpunit/src/Commands/TelemetryCommandTest.php @@ -68,8 +68,7 @@ public function providerTestTelemetryPrompt(): array */ public function testTelemetryPrompt(array $inputs, mixed $message): void { - $this->cloudConfig = [DataStoreContract::SEND_TELEMETRY => null]; - $this->createMockConfigFiles(); + $this->createMockCloudConfigFile([DataStoreContract::SEND_TELEMETRY => null]); $this->createMockAcliConfigFile('a47ac10b-58cc-4372-a567-0e02b2c3d470'); $this->createDataStores(); $this->mockApplicationRequest(); @@ -86,8 +85,6 @@ public function testTelemetryPrompt(array $inputs, mixed $message): void */ public function testAmplitudeDisabled(): void { - $this->cloudConfig = [DataStoreContract::SEND_TELEMETRY => false]; - $this->createMockConfigFiles(); $this->executeCommand(); $this->assertEquals(0, $this->getStatusCode()); @@ -95,8 +92,7 @@ public function testAmplitudeDisabled(): void public function testMigrateLegacyTelemetryPreference(): void { - $this->cloudConfig = [DataStoreContract::SEND_TELEMETRY => null]; - $this->createMockConfigFiles(); + $this->createMockCloudConfigFile([DataStoreContract::SEND_TELEMETRY => null]); $this->fs->remove($this->legacyAcliConfigFilepath); $legacyAcliConfig = ['send_telemetry' => false]; $contents = json_encode($legacyAcliConfig); diff --git a/tests/phpunit/src/TestBase.php b/tests/phpunit/src/TestBase.php index 7ffb0beb0..e43c1ab5b 100644 --- a/tests/phpunit/src/TestBase.php +++ b/tests/phpunit/src/TestBase.php @@ -69,16 +69,6 @@ abstract class TestBase extends TestCase protected Client|ObjectProphecy $clientProphecy; - /** - * @var array - */ - protected array $acliConfig = []; - - /** - * @var array - */ - protected array $cloudConfig = []; - protected string $key = '17feaf34-5d04-402b-9a67-15d5161d24e1'; protected string $secret = 'X1u\/PIQXtYaoeui.4RJSJpGZjwmWYmfl5AUQkAebYE='; @@ -425,18 +415,13 @@ protected function createLocalSshKey(mixed $contents): string protected function createMockConfigFiles(): void { $this->createMockCloudConfigFile(); - - $defaultValues = []; - $acliConfig = array_merge($defaultValues, $this->acliConfig); - $contents = json_encode($acliConfig, JSON_THROW_ON_ERROR); - $filepath = $this->acliConfigFilepath; - $this->fs->dumpFile($filepath, $contents); + $this->createMockAcliConfigFile(); } - protected function createMockCloudConfigFile(mixed $defaultValues = []): void + protected function createMockCloudConfigFile(mixed $cloudConfig = []): void { - if (!$defaultValues) { - $defaultValues = [ + if (!$cloudConfig) { + $cloudConfig = [ 'acli_key' => $this->key, 'keys' => [ (string) ($this->key) => [ @@ -448,15 +433,20 @@ protected function createMockCloudConfigFile(mixed $defaultValues = []): void DataStoreContract::SEND_TELEMETRY => false, ]; } - $cloudConfig = array_merge($defaultValues, $this->cloudConfig); $contents = json_encode($cloudConfig, JSON_THROW_ON_ERROR); $filepath = $this->cloudConfigFilepath; $this->fs->dumpFile($filepath, $contents); } - protected function createMockAcliConfigFile(string $cloudAppUuid): void + protected function createMockAcliConfigFile(mixed $cloudAppUuid = null): void { - $this->datastoreAcli->set('cloud_app_uuid', $cloudAppUuid); + $acliConfig = []; + if (is_string($cloudAppUuid)) { + $acliConfig['cloud_app_uuid'] = $cloudAppUuid; + } elseif (is_array($cloudAppUuid)) { + $acliConfig = $cloudAppUuid; + } + $this->fs->dumpFile($this->acliConfigFilepath, json_encode($acliConfig, JSON_THROW_ON_ERROR)); } /**