Skip to content

Commit

Permalink
clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Oct 26, 2023
1 parent 013b1ef commit 753710e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 56 deletions.
4 changes: 2 additions & 2 deletions tests/phpunit/src/Application/ExceptionApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function testMissingEnvironmentUuid(): void {
*/
public function testInvalidEnvironmentUuid(): void {
$this->mockRequest('getAccount');
$this->mockApplicationsRequest();
$this->mockRequest('getApplications');
$this->setInput([
'command' => 'log:tail',
'environmentId' => 'aoeuth.aoeu',
Expand All @@ -142,7 +142,7 @@ public function testMissingApplicationUuid(): void {
*/
public function testInvalidApplicationUuid(): void {
$this->mockRequest('getAccount');
$this->mockApplicationsRequest();
$this->mockRequest('getApplications');
$this->setInput([
'applicationUuid' => 'aoeuthao',
'command' => 'ide:open',
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/src/Commands/App/AppVcsInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public function testNoEnvAvailableCommand(): void {
* Test when no branch or tag available for the app.
*/
public function testNoVcsAvailableCommand(): void {
$applicationsResponse = $this->mockApplicationsRequest();
$this->mockApplicationRequest();
$this->mockEnvironmentsRequest($applicationsResponse);
$applications = $this->mockRequest('getApplications');
$this->mockRequest('getApplicationByUuid', $applications[0]->uuid);
$this->mockRequest('getApplicationEnvironments', $applications[0]->uuid);

$this->clientProphecy->request('get',
"/applications/{$applicationsResponse->{'_embedded'}->items[0]->uuid}/code")
"/applications/{$applications[0]->uuid}/code")
->willReturn([])
->shouldBeCalled();

Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/src/Commands/App/LinkCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function createCommand(): Command {
}

public function testLinkCommand(): void {
$applicationsResponse = $this->mockApplicationsRequest();
$applications = $this->mockRequest('getApplications');
$this->mockApplicationRequest();

$inputs = [
Expand All @@ -30,7 +30,7 @@ public function testLinkCommand(): void {
];
$this->executeCommand([], $inputs);
$output = $this->getDisplay();
$this->assertEquals($applicationsResponse->{'_embedded'}->items[0]->uuid, $this->datastoreAcli->get('cloud_app_uuid'));
$this->assertEquals($applications[self::$INPUT_DEFAULT_CHOICE]->uuid, $this->datastoreAcli->get('cloud_app_uuid'));
$this->assertStringContainsString('There is no Cloud Platform application linked to', $output);
$this->assertStringContainsString('Select a Cloud Platform application', $output);
$this->assertStringContainsString('[0] Sample application 1', $output);
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/src/Commands/App/LogTailCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ protected function createCommand(): Command {

public function testLogTailCommand(): void {

$applicationsResponse = $this->mockApplicationsRequest();
$this->mockApplicationRequest();
$this->mockEnvironmentsRequest($applicationsResponse);
$applications = $this->mockRequest('getApplications');
$this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$this->mockRequest('getApplicationEnvironments', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$this->mockLogStreamRequest();
$this->executeCommand([], [
// Would you like Acquia CLI to search for a Cloud application that matches your local git config?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function testEmailInfoForSubscriptionNoApps(): void {
$getDomainsResponse = $this->getMockResponseFromSpec('/subscriptions/{subscriptionUuid}/domains', 'get', '200');
$this->clientProphecy->request('get', "/subscriptions/{$subscriptions[0]->uuid}/domains")->willReturn($getDomainsResponse->_embedded->items);

$this->mockApplicationsRequest();
$this->mockRequest('getApplications');

$this->expectException(AcquiaCliException::class);
$this->expectExceptionMessage('You do not have access');
Expand Down
82 changes: 38 additions & 44 deletions tests/phpunit/src/Commands/Pull/PullCodeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@ public function testCloneRepo(): void {
$this->acliRepoRoot = '';
$this->command = $this->createCommand();
// Client responses.
$applicationsResponse = $this->mockApplicationsRequest();
$this->mockApplicationRequest();
$environmentsResponse = $this->mockEnvironmentsRequest($applicationsResponse);
$selectedEnvironment = $environmentsResponse->_embedded->items[0];
$applications = $this->mockRequest('getApplications');
$this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$environments = $this->mockRequest('getApplicationEnvironments', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$localMachineHelper = $this->mockReadIdePhpVersion();
$process = $this->mockProcess();
$dir = Path::join($this->vfsRoot->url(), 'empty-dir');
mkdir($dir);
$localMachineHelper->checkRequiredBinariesExist(["git"])->shouldBeCalled();
$this->mockExecuteGitClone($localMachineHelper, $selectedEnvironment, $process, $dir);
$this->mockExecuteGitCheckout($localMachineHelper, $selectedEnvironment->vcs->path, $dir, $process);
$this->mockExecuteGitClone($localMachineHelper, $environments[self::$INPUT_DEFAULT_CHOICE], $process, $dir);
$this->mockExecuteGitCheckout($localMachineHelper, $environments[self::$INPUT_DEFAULT_CHOICE]->vcs->path, $dir, $process);
$localMachineHelper->getFinder()->willReturn(new Finder());

$this->command->localMachineHelper = $localMachineHelper->reveal();
Expand All @@ -47,11 +46,11 @@ public function testCloneRepo(): void {
// Would you like to clone a project into the current directory?
'y',
// Select a Cloud Platform application:
0,
self::$INPUT_DEFAULT_CHOICE,
// Would you like to link the project at ... ?
'n',
// Choose an Acquia environment:
0,
self::$INPUT_DEFAULT_CHOICE,
];
$this->executeCommand([
'--dir' => $dir,
Expand All @@ -61,10 +60,9 @@ public function testCloneRepo(): void {
}

public function testPullCode(): void {
$applicationsResponse = $this->mockApplicationsRequest();
$this->mockApplicationRequest();
$environmentsResponse = $this->mockEnvironmentsRequest($applicationsResponse);
$selectedEnvironment = $environmentsResponse->_embedded->items[0];
$applications = $this->mockRequest('getApplications');
$this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$environments = $this->mockRequest('getApplicationEnvironments', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$this->createMockGitConfigFile();

$localMachineHelper = $this->mockReadIdePhpVersion();
Expand All @@ -74,18 +72,18 @@ public function testPullCode(): void {
$this->command->localMachineHelper = $localMachineHelper->reveal();

$process = $this->mockProcess();
$this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $selectedEnvironment->vcs->path);
$this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $environments[self::$INPUT_DEFAULT_CHOICE]->vcs->path);
$this->mockExecuteGitStatus(FALSE, $localMachineHelper, $this->projectDir);

$inputs = [
// Would you like Acquia CLI to search for a Cloud application that matches your local git config?
'n',
// Select a Cloud Platform application:
0,
self::$INPUT_DEFAULT_CHOICE,
// Would you like to link the project at ... ?
'n',
// Choose an Acquia environment:
0,
self::$INPUT_DEFAULT_CHOICE,
];

$this->executeCommand([
Expand All @@ -102,10 +100,9 @@ public function testPullCode(): void {

public function testWithScripts(): void {
touch(Path::join($this->projectDir, 'composer.json'));
$applicationsResponse = $this->mockApplicationsRequest();
$this->mockApplicationRequest();
$environmentsResponse = $this->mockEnvironmentsRequest($applicationsResponse);
$selectedEnvironment = $environmentsResponse->_embedded->items[0];
$applications = $this->mockRequest('getApplications');
$this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$environments = $this->mockRequest('getApplicationEnvironments', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$this->createMockGitConfigFile();

$localMachineHelper = $this->mockReadIdePhpVersion();
Expand All @@ -115,7 +112,7 @@ public function testWithScripts(): void {
$this->command->localMachineHelper = $localMachineHelper->reveal();

$process = $this->mockProcess();
$this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $selectedEnvironment->vcs->path);
$this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $environments[self::$INPUT_DEFAULT_CHOICE]->vcs->path);
$this->mockExecuteGitStatus(FALSE, $localMachineHelper, $this->projectDir);
$process = $this->mockProcess();
$this->mockExecuteComposerExists($localMachineHelper);
Expand All @@ -128,11 +125,11 @@ public function testWithScripts(): void {
// Would you like Acquia CLI to search for a Cloud application that matches your local git config?
'n',
// Select a Cloud Platform application:
0,
self::$INPUT_DEFAULT_CHOICE,
// Would you like to link the project at ... ?
'n',
// Choose an Acquia environment:
0,
self::$INPUT_DEFAULT_CHOICE,
];

$this->executeCommand([], $inputs);
Expand All @@ -146,10 +143,9 @@ public function testWithScripts(): void {
}

public function testNoComposerJson(): void {
$applicationsResponse = $this->mockApplicationsRequest();
$this->mockApplicationRequest();
$environmentsResponse = $this->mockEnvironmentsRequest($applicationsResponse);
$selectedEnvironment = $environmentsResponse->_embedded->items[0];
$applications = $this->mockRequest('getApplications');
$this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$environments = $this->mockRequest('getApplicationEnvironments', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$this->createMockGitConfigFile();

$localMachineHelper = $this->mockReadIdePhpVersion();
Expand All @@ -159,7 +155,7 @@ public function testNoComposerJson(): void {
$this->command->localMachineHelper = $localMachineHelper->reveal();

$process = $this->mockProcess();
$this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $selectedEnvironment->vcs->path);
$this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $environments[self::$INPUT_DEFAULT_CHOICE]->vcs->path);
$this->mockExecuteGitStatus(FALSE, $localMachineHelper, $this->projectDir);
$process = $this->mockProcess();
$this->mockExecuteDrushExists($localMachineHelper);
Expand All @@ -170,11 +166,11 @@ public function testNoComposerJson(): void {
// Would you like Acquia CLI to search for a Cloud application that matches your local git config?
'n',
// Select a Cloud Platform application:
0,
self::$INPUT_DEFAULT_CHOICE,
// Would you like to link the project at ... ?
'n',
// Choose an Acquia environment:
0,
self::$INPUT_DEFAULT_CHOICE,
];

$this->executeCommand([], $inputs);
Expand All @@ -185,10 +181,9 @@ public function testNoComposerJson(): void {

public function testNoComposer(): void {
touch(Path::join($this->projectDir, 'composer.json'));
$applicationsResponse = $this->mockApplicationsRequest();
$this->mockApplicationRequest();
$environmentsResponse = $this->mockEnvironmentsRequest($applicationsResponse);
$selectedEnvironment = $environmentsResponse->_embedded->items[0];
$applications = $this->mockRequest('getApplications');
$this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$environments = $this->mockRequest('getApplicationEnvironments', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$this->createMockGitConfigFile();

$localMachineHelper = $this->mockReadIdePhpVersion();
Expand All @@ -198,7 +193,7 @@ public function testNoComposer(): void {
$this->command->localMachineHelper = $localMachineHelper->reveal();

$process = $this->mockProcess();
$this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $selectedEnvironment->vcs->path);
$this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $environments[self::$INPUT_DEFAULT_CHOICE]->vcs->path);
$this->mockExecuteGitStatus(FALSE, $localMachineHelper, $this->projectDir);
$process = $this->mockProcess();
$localMachineHelper
Expand All @@ -213,11 +208,11 @@ public function testNoComposer(): void {
// Would you like Acquia CLI to search for a Cloud application that matches your local git config?
'n',
// Select a Cloud Platform application:
0,
self::$INPUT_DEFAULT_CHOICE,
// Would you like to link the project at ... ?
'n',
// Choose an Acquia environment:
0,
self::$INPUT_DEFAULT_CHOICE,
];

$this->executeCommand([], $inputs);
Expand All @@ -230,10 +225,9 @@ public function testNoComposer(): void {
public function testWithVendorDir(): void {
touch(Path::join($this->projectDir, 'composer.json'));
touch(Path::join($this->projectDir, 'vendor'));
$applicationsResponse = $this->mockApplicationsRequest();
$this->mockApplicationRequest();
$environmentsResponse = $this->mockEnvironmentsRequest($applicationsResponse);
$selectedEnvironment = $environmentsResponse->_embedded->items[0];
$applications = $this->mockRequest('getApplications');
$this->mockRequest('getApplicationByUuid', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$environments = $this->mockRequest('getApplicationEnvironments', $applications[self::$INPUT_DEFAULT_CHOICE]->uuid);
$this->createMockGitConfigFile();

$localMachineHelper = $this->mockReadIdePhpVersion();
Expand All @@ -243,7 +237,7 @@ public function testWithVendorDir(): void {
$this->command->localMachineHelper = $localMachineHelper->reveal();

$process = $this->mockProcess();
$this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $selectedEnvironment->vcs->path);
$this->mockExecuteGitFetchAndCheckout($localMachineHelper, $process, $this->projectDir, $environments[self::$INPUT_DEFAULT_CHOICE]->vcs->path);
$this->mockExecuteGitStatus(FALSE, $localMachineHelper, $this->projectDir);
$process = $this->mockProcess();
$this->mockExecuteComposerExists($localMachineHelper);
Expand All @@ -255,11 +249,11 @@ public function testWithVendorDir(): void {
// Would you like Acquia CLI to search for a Cloud application that matches your local git config?
'n',
// Select a Cloud Platform application:
0,
self::$INPUT_DEFAULT_CHOICE,
// Would you like to link the project at ... ?
'n',
// Choose an Acquia environment:
0,
self::$INPUT_DEFAULT_CHOICE,
];

$this->executeCommand([], $inputs);
Expand Down Expand Up @@ -318,7 +312,7 @@ public function testMatchPhpVersion(string $phpVersion): void {
'environmentId' => $environmentResponse->id,
], [
// Choose an Acquia environment:
0,
self::$INPUT_DEFAULT_CHOICE,
// Would you like to change the PHP version on this IDE to match the PHP version on ... ?
'n',
]);
Expand Down

0 comments on commit 753710e

Please sign in to comment.