-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14ac0e9
commit 998cdf8
Showing
2 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]); | ||
} | ||
|
||
} |