Skip to content

Commit

Permalink
back towards boilerplate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Dec 12, 2023
1 parent 835f643 commit 01103b8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
13 changes: 8 additions & 5 deletions tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
12 changes: 12 additions & 0 deletions tests/phpunit/src/TestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 01103b8

Please sign in to comment.