Skip to content

Commit

Permalink
test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Dec 12, 2023
1 parent 01103b8 commit b23f587
Show file tree
Hide file tree
Showing 74 changed files with 201 additions and 213 deletions.
36 changes: 35 additions & 1 deletion src/Command/Self/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,48 @@

use Acquia\Cli\Command\Acsf\AcsfListCommandBase;
use Acquia\Cli\Command\Api\ApiListCommandBase;
use Acquia\Cli\Command\CommandBase;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Descriptor\ApplicationDescription;
use Symfony\Component\Console\Helper\DescriptorHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: 'list', description: NULL, aliases: ['self:list'])]
final class ListCommand extends \Symfony\Component\Console\Command\ListCommand {
final class ListCommand extends CommandBase {

protected function configure(): void {
$this
->setName('list')
->setDefinition([
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name', NULL, fn () => array_keys((new ApplicationDescription($this->getApplication()))->getNamespaces())),
new InputOption('raw', NULL, InputOption::VALUE_NONE, 'To output raw command list'),
new InputOption('format', NULL, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt', fn () => (new DescriptorHelper())->getFormats()),
new InputOption('short', NULL, InputOption::VALUE_NONE, 'To skip describing commands\' arguments'),
])
->setDescription('List commands')
->setHelp(<<<'EOF'
The <info>%command.name%</info> command lists all commands:
<info>%command.full_name%</info>
You can also display the commands for a specific namespace:
<info>%command.full_name% test</info>
You can also output the information in other formats by using the <comment>--format</comment> option:
<info>%command.full_name% --format=xml</info>
It's also possible to get raw list of commands (useful for embedding command runner):
<info>%command.full_name% --raw</info>
EOF
);
}

protected function execute(InputInterface $input, OutputInterface $output): int {
foreach (['api', 'acsf'] as $prefix) {
Expand Down
4 changes: 3 additions & 1 deletion tests/phpunit/src/Application/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class KernelTest extends ApplicationTestBase {
* @group serial
*/
public function testRun(): void {
$this->setInput(['list']);
$this->setInput([
'command' => 'list',
]);
$buffer = $this->runApp();
// A bit dumb that we need to break these up, but the available commands vary based on whether a browser is available or the session is interactive.
// Could probably handle that more intelligently...
Expand Down
14 changes: 5 additions & 9 deletions tests/phpunit/src/CommandTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Message\StreamInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Terminal;
Expand All @@ -46,16 +45,11 @@ abstract class CommandTestBase extends TestBase {
// Select the application / SSH key / etc.
protected static int $INPUT_DEFAULT_CHOICE = 0;

protected Command $command;
protected CommandBase $command;

protected string $apiCommandPrefix = 'api';

/**
* Creates a command object to test.
*
* @return \Symfony\Component\Console\Command\Command A command object with mocked dependencies injected.
*/
abstract protected function createCommand(): Command;
abstract protected function createCommand(): CommandBase;

/**
* This method is called before each test.
Expand All @@ -68,7 +62,7 @@ protected function setUp(): void {
$this->printTestName();
}

protected function setCommand(Command $command): void {
protected function setCommand(CommandBase $command): void {
$this->command = $command;
}

Expand Down Expand Up @@ -218,6 +212,8 @@ public function mockGetEnvironment(): mixed {
protected function mockLocalMachineHelper(): LocalMachineHelper|ObjectProphecy {
$localMachineHelper = $this->prophet->prophesize(LocalMachineHelper::class);
$localMachineHelper->useTty()->willReturn(FALSE);
$this->command->localMachineHelper = $localMachineHelper->reveal();

return $localMachineHelper;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/src/Commands/Acsf/AcsfApiCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
use Acquia\Cli\CloudApi\ClientService;
use Acquia\Cli\Command\Acsf\AcsfApiBaseCommand;
use Acquia\Cli\Command\Acsf\AcsfCommandFactory;
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\CommandFactoryInterface;
use Prophecy\Argument;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand All @@ -29,7 +29,7 @@ public function setUp(): void {
putenv('ACQUIA_CLI_USE_CLOUD_API_SPEC_CACHE=1');
}

protected function createCommand(): Command {
protected function createCommand(): CommandBase {
$this->createMockCloudConfigFile($this->getAcsfCredentialsFileContents());
$this->cloudCredentials = new AcsfCredentials($this->datastoreCloud);
$this->setClientProphecies(AcsfClientService::class);
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/src/Commands/Acsf/AcsfAuthLoginCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

use Acquia\Cli\AcsfApi\AcsfCredentials;
use Acquia\Cli\Command\Auth\AuthAcsfLoginCommand;
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Config\CloudDataConfig;
use Acquia\Cli\DataStore\CloudDataStore;
use Symfony\Component\Console\Command\Command;

/**
* @property \Acquia\Cli\Command\Auth\AuthLoginCommand $command
*/
class AcsfAuthLoginCommandTest extends AcsfCommandTestBase {

protected function createCommand(): Command {
protected function createCommand(): CommandBase {
$this->cloudCredentials = new AcsfCredentials($this->datastoreCloud);
return $this->injectCommand(AuthAcsfLoginCommand::class);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/src/Commands/Acsf/AcsfAuthLogoutCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

use Acquia\Cli\AcsfApi\AcsfCredentials;
use Acquia\Cli\Command\Auth\AuthAcsfLogoutCommand;
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Config\CloudDataConfig;
use Acquia\Cli\DataStore\CloudDataStore;
use Symfony\Component\Console\Command\Command;

/**
* @property AcsfAuthLogoutCommandTest $command
*/
class AcsfAuthLogoutCommandTest extends AcsfCommandTestBase {

protected function createCommand(): Command {
protected function createCommand(): CommandBase {
$this->cloudCredentials = new AcsfCredentials($this->datastoreCloud);
return $this->injectCommand(AuthAcsfLogoutCommand::class);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/src/Commands/Acsf/AcsfListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use Acquia\Cli\Command\Acsf\AcsfListCommand;
use Acquia\Cli\Command\Acsf\AcsfListCommandBase;
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Command\Self\ListCommand;
use Acquia\Cli\Tests\CommandTestBase;
use Symfony\Component\Console\Command\Command;

/**
* @property AcsfListCommandBase $command
Expand All @@ -23,7 +23,7 @@ public function setUp(): void {
$this->application->addCommands($this->getApiCommands());
}

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

Expand All @@ -47,7 +47,7 @@ public function testApiNamespaceListCommand(): void {
}

public function testListCommand(): void {
$this->command = new ListCommand('list');
$this->command = $this->injectCommand(ListCommand::class);
$this->executeCommand();
$output = $this->getDisplay();
$this->assertStringContainsString('acsf:api', $output);
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/src/Commands/Api/ApiCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace Acquia\Cli\Tests\Commands\Api;

use Acquia\Cli\Command\Api\ApiBaseCommand;
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Command\Self\ClearCacheCommand;
use Acquia\Cli\Exception\AcquiaCliException;
use Acquia\Cli\Tests\CommandTestBase;
use AcquiaCloudApi\Exception\ApiErrorException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\MissingInputException;
use Symfony\Component\Filesystem\Path;
use Symfony\Component\Yaml\Yaml;
Expand All @@ -25,7 +25,7 @@ public function setUp(): void {
putenv('ACQUIA_CLI_USE_CLOUD_API_SPEC_CACHE=1');
}

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

Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/src/Commands/Api/ApiListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use Acquia\Cli\Command\Api\ApiListCommand;
use Acquia\Cli\Command\Api\ApiListCommandBase;
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Command\Self\ListCommand;
use Acquia\Cli\Tests\CommandTestBase;
use Symfony\Component\Console\Command\Command;

/**
* @property ApiListCommandBase $command
Expand All @@ -20,7 +20,7 @@ public function setUp(): void {
$this->application->addCommands($this->getApiCommands());
}

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

Expand All @@ -43,7 +43,7 @@ public function testApiNamespaceListCommand(): void {
}

public function testListCommand(): void {
$this->command = new ListCommand();
$this->command = $this->injectCommand(ListCommand::class);
$this->executeCommand();
$output = $this->getDisplay();
$this->assertStringContainsString(' api:accounts', $output);
Expand Down
12 changes: 5 additions & 7 deletions tests/phpunit/src/Commands/App/AppOpenCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
namespace Acquia\Cli\Tests\Commands\App;

use Acquia\Cli\Command\App\AppOpenCommand;
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Exception\AcquiaCliException;
use Acquia\Cli\Tests\CommandTestBase;
use Symfony\Component\Console\Command\Command;

/**
* @property AppOpenCommand $command
*/
class AppOpenCommandTest extends CommandTestBase {

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

Expand All @@ -23,18 +23,16 @@ public function testAppOpenCommand(): void {
$localMachineHelper = $this->mockLocalMachineHelper();
$localMachineHelper->startBrowser('https://cloud.acquia.com/a/applications/' . $applicationUuid)->shouldBeCalled();
$localMachineHelper->isBrowserAvailable()->willReturn(TRUE);
$this->command->localMachineHelper = $localMachineHelper->reveal();
$this->createMockAcliConfigFile($applicationUuid);
$this->mockApplicationRequest();
$this->executeCommand();
$this->mockRequest('getApplicationByUuid', $applicationUuid);
$this->executeCommand(['applicationUuid' => $applicationUuid]);
$this->prophet->checkPredictions();
}

public function testAppOpenNoBrowser(): void {
$applicationUuid = 'a47ac10b-58cc-4372-a567-0e02b2c3d470';
$localMachineHelper = $this->mockLocalMachineHelper();
$localMachineHelper->isBrowserAvailable()->willReturn(FALSE);
$this->command->localMachineHelper = $localMachineHelper->reveal();

$this->mockApplicationRequest();
$this->createMockAcliConfigFile($applicationUuid);
$this->expectException(AcquiaCliException::class);
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/src/Commands/App/AppVcsInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
namespace Acquia\Cli\Tests\Commands\App;

use Acquia\Cli\Command\App\AppVcsInfo;
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Exception\AcquiaCliException;
use Acquia\Cli\Tests\CommandTestBase;
use Symfony\Component\Console\Command\Command;

/**
* @property \Acquia\Cli\Command\App\AppVcsInfo $command
*/
class AppVcsInfoTest extends CommandTestBase {

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

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 @@ -5,16 +5,16 @@
namespace Acquia\Cli\Tests\Commands\App;

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

/**
* @property \Acquia\Cli\Command\App\LinkCommand $command
*/
class LinkCommandTest extends CommandTestBase {

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

Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/src/Commands/App/LogTailCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
namespace Acquia\Cli\Tests\Commands\App;

use Acquia\Cli\Command\App\LogTailCommand;
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Tests\CommandTestBase;
use Symfony\Component\Console\Command\Command;

/**
* @property \Acquia\Cli\Command\App\LogTailCommand $command
*/
class LogTailCommandTest extends CommandTestBase {

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

Expand Down
6 changes: 2 additions & 4 deletions tests/phpunit/src/Commands/App/NewCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Acquia\Cli\Tests\Commands\App;

use Acquia\Cli\Command\App\NewCommand;
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Tests\CommandTestBase;
use Prophecy\Prophecy\ObjectProphecy;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Filesystem\Path;
use Symfony\Component\Process\Process;

Expand All @@ -23,7 +23,7 @@ public function setUp(): void {
$this->setupFsFixture();
}

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

Expand Down Expand Up @@ -70,7 +70,6 @@ public function testNewDrupalCommand(array $package, string $directory = 'drupal
$this->mockExecuteGitAdd($localMachineHelper, $this->newProjectDir, $process);
$this->mockExecuteGitCommit($localMachineHelper, $this->newProjectDir, $process);

$this->command->localMachineHelper = $localMachineHelper->reveal();
$inputs = [
// Choose a starting project
$project,
Expand Down Expand Up @@ -111,7 +110,6 @@ public function testNewNextJSAppCommand(array $package, string $directory = 'nex
$this->mockExecuteGitAdd($localMachineHelper, $this->newProjectDir, $process);
$this->mockExecuteGitCommit($localMachineHelper, $this->newProjectDir, $process);

$this->command->localMachineHelper = $localMachineHelper->reveal();
$inputs = [
// Choose a starting project
$project,
Expand Down
Loading

0 comments on commit b23f587

Please sign in to comment.