Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed May 16, 2024
1 parent 14ac0e9 commit 998cdf8
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/phpunit/src/Commands/ClearCacheCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types = 1);

namespace Acquia\Cli\Tests\Commands;

use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Command\Ide\IdeListCommand;
use Acquia\Cli\Command\Self\ClearCacheCommand;
use Acquia\Cli\Tests\CommandTestBase;

/**
* @property \Acquia\Cli\Command\App\UnlinkCommand $command
*/
class ClearCacheCommandTest extends CommandTestBase {

protected function createCommand(): CommandBase {
return $this->injectCommand(ClearCacheCommand::class);
}

/**
* @group serial
*/
public function testAliasesAreCached(): void {
ClearCacheCommand::clearCaches();
$this->command = $this->injectCommand(IdeListCommand::class);

// Request for applications.
$applicationsResponse = $this->getMockResponseFromSpec('/applications',
'get', '200');
$applicationsResponse = $this->filterApplicationsResponse($applicationsResponse, 1, TRUE);
$this->clientProphecy->request('get', '/applications')
->willReturn($applicationsResponse->{'_embedded'}->items)
// Ensure this is only called once, even though we execute the command twice.
->shouldBeCalledTimes(1);

$this->clientProphecy->addQuery('filter', 'hosting=@*:devcloud2')->shouldBeCalled();
$this->mockApplicationRequest();
$this->mockRequest('getApplicationIdes', 'a47ac10b-58cc-4372-a567-0e02b2c3d470');
$this->mockRequest('getAccount');

$alias = 'devcloud2';
$args = ['applicationUuid' => $alias];
$inputs = [
// Would you like to link the Cloud application Sample application to this repository?
'n',
];

$this->executeCommand($args, $inputs);
// Run it twice, make sure API calls are made only once.
$this->executeCommand($args, $inputs);

// Assert.
$output = $this->getDisplay();
$this->assertEquals(0, $this->getStatusCode());
}

public function testClearCaches(): void {
$this->executeCommand();
$output = $this->getDisplay();
$this->assertStringContainsString('Acquia CLI caches were cleared', $output);

$cache = CommandBase::getAliasCache();
$this->assertCount(0, iterator_to_array($cache->getItems(), FALSE));
}

}
92 changes: 92 additions & 0 deletions tests/phpunit/src/Commands/InferApplicationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

declare(strict_types = 1);

namespace Acquia\Cli\Tests\Commands;

use Acquia\Cli\Command\App\LinkCommand;
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Exception\AcquiaCliException;
use Acquia\Cli\Tests\CommandTestBase;

/**
* @property LinkCommand $command
*/
class InferApplicationTest extends CommandTestBase {

/**
* @return \Acquia\Cli\Command\App\LinkCommand
*/
protected function createCommand(): CommandBase {
return $this->injectCommand(LinkCommand::class);
}

public function testInfer(): void {
$this->createMockGitConfigFile();
$applicationsResponse = $this->mockApplicationsRequest();
$this->mockApplicationRequest();
$environmentResponse = $this->getMockEnvironmentResponse();
// The searchApplicationEnvironmentsForGitUrl() method will only look
// for a match of the vcs url on the prod env. So, we mock a prod env.
$environmentResponse2 = $environmentResponse;
$environmentResponse2->flags->production = TRUE;
$this->clientProphecy->request('get',
"/applications/{$applicationsResponse->{'_embedded'}->items[0]->uuid}/environments")
->willReturn([$environmentResponse, $environmentResponse2])
->shouldBeCalled();

$this->executeCommand([], [
// Would you like Acquia CLI to search for a Cloud application that matches your local git config?
'y',
// Would you like to link the project at ...
'y',
]);

$output = $this->getDisplay();

$this->assertStringContainsString('There is no Cloud Platform application linked to', $output);
$this->assertStringContainsString('Searching for a matching Cloud application...', $output);
$this->assertStringContainsString('Found a matching application!', $output);
$this->assertStringContainsString('The Cloud application Sample application 1 has been linked', $output);
}

public function testInferFailure(): void {
$this->createMockGitConfigFile();
$applicationsResponse = $this->mockApplicationsRequest();
$this->mockApplicationRequest();

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

$this->executeCommand([], [
// Would you like Acquia CLI to search for a Cloud application that matches your local git config?
'y',
// Select a Cloud Platform application:
0,
// Would you like to link the project at ...
'y',
]);

$output = $this->getDisplay();

$this->assertStringContainsString('There is no Cloud Platform application linked to', $output);
$this->assertStringContainsString('Searching for a matching Cloud application...', $output);
$this->assertStringContainsString('Could not find a matching Cloud application.', $output);
$this->assertStringContainsString('The Cloud application Sample application 1 has been linked', $output);
}

public function testInferInvalidGitConfig(): void {
$this->expectException(AcquiaCliException::class);
$this->executeCommand([], [
'y',
]);
}

}

0 comments on commit 998cdf8

Please sign in to comment.