From 01103b81e40e2a89f53b0c85cbe142b934f4547e Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Tue, 12 Dec 2023 13:26:23 -0800 Subject: [PATCH] back towards boilerplate tests --- .../src/Commands/Pull/PullDatabaseCommandTest.php | 13 ++++++++----- .../src/Commands/Push/PushArtifactCommandTest.php | 2 +- tests/phpunit/src/TestBase.php | 12 ++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php b/tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php index 4849b6eab..fbb36ac39 100644 --- a/tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php +++ b/tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php @@ -9,6 +9,7 @@ use Acquia\Cli\Exception\AcquiaCliException; use Acquia\Cli\Helpers\LocalMachineHelper; use Acquia\Cli\Helpers\SshHelper; +use AcquiaCloudApi\Response\BackupsResponse; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\Uri; use Prophecy\Argument; @@ -43,14 +44,16 @@ public function providerTestPullDatabaseWithInvalidSslCertificate(): array { } public function mockGetBackup(mixed $environment): void { - $databases = $this->mockRequest('getEnvironmentsDatabases', $environment->id); + $databases = $this->mockGetEnvironmentsDatabases($environment->id); $tamper = function ($backups): void { $backups[0]->completedAt = $backups[0]->completed_at; }; - $backups = $this->mockRequest('getEnvironmentsDatabaseBackups', [ - $environment->id, - 'my_db', - ], NULL, NULL, $tamper); + $backups = new BackupsResponse( + $this->mockRequest('getEnvironmentsDatabaseBackups', [ + $environment->id, + 'my_db', + ], NULL, NULL, $tamper) + ); $this->mockDownloadBackup($databases[0], $environment, $backups[0]); } diff --git a/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php b/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php index 8e367a7c9..b1ed2df39 100644 --- a/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php +++ b/tests/phpunit/src/Commands/Push/PushArtifactCommandTest.php @@ -30,7 +30,7 @@ public function testNoAuthenticationRequired(): void { public function testPushArtifact(): void { $applications = $this->mockRequest('getApplications'); $this->mockRequest('getApplicationByUuid', $applications[0]->uuid); - $environments = $this->mockRequest('getApplicationEnvironments', $applications[0]->uuid); + $environments = $this->mockGetApplicationEnvironments($applications[0]->uuid); $localMachineHelper = $this->mockLocalMachineHelper(); $this->setUpPushArtifact($localMachineHelper, $environments[0]->vcs->path, [$environments[0]->vcs->url]); $inputs = [ diff --git a/tests/phpunit/src/TestBase.php b/tests/phpunit/src/TestBase.php index 707b77d0a..09a2e52a1 100644 --- a/tests/phpunit/src/TestBase.php +++ b/tests/phpunit/src/TestBase.php @@ -20,6 +20,8 @@ use Acquia\Cli\Helpers\TelemetryHelper; use AcquiaCloudApi\Connector\Client; use AcquiaCloudApi\Exception\ApiErrorException; +use AcquiaCloudApi\Response\DatabasesResponse; +use AcquiaCloudApi\Response\EnvironmentsResponse; use AcquiaCloudApi\Response\IdeResponse; use AcquiaLogstream\LogstreamManager; use Closure; @@ -437,6 +439,16 @@ protected function createMockAcliConfigFile(string $cloudAppUuid): void { $this->datastoreAcli->set('cloud_app_uuid', $cloudAppUuid); } + protected function mockGetEnvironmentsDatabases(string $id): DatabasesResponse { + $databases = $this->mockRequest('getEnvironmentsDatabases', $id); + return new DatabasesResponse($databases); + } + + protected function mockGetApplicationEnvironments(string $id): EnvironmentsResponse { + $environments = $this->mockRequest('getApplicationEnvironments', $id); + return new EnvironmentsResponse($environments); + } + protected function mockRequest(string $operationId, string|array|null $params = NULL, ?array $body = NULL, ?string $exampleResponse = NULL, Closure $tamper = NULL): object|array { if (is_string($params)) { $params = [$params];