Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Nov 14, 2024
1 parent 3ad4ef5 commit efd491f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Command/Auth/AuthAcsfLoginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
if ($input->getOption('factory-url')) {
$factoryUrl = $input->getOption('factory-url');
self::validateUrl($factoryUrl);
} elseif ($input->isInteractive() && $this->datastoreCloud->get('acsf_factories')) {
$factories = $this->datastoreCloud->get('acsf_factories');
$factoryChoices = $factories;
Expand Down
34 changes: 34 additions & 0 deletions tests/phpunit/src/Commands/Acsf/AcsfAuthLoginCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Config\CloudDataConfig;
use Acquia\Cli\DataStore\CloudDataStore;
use Symfony\Component\Validator\Exception\ValidatorException;

/**
* @property \Acquia\Cli\Command\Auth\AuthLoginCommand $command
Expand Down Expand Up @@ -117,6 +118,39 @@ public function testAcsfAuthLoginCommand(bool $machineIsAuthenticated, array $in
$this->assertEquals(self::$acsfCurrentFactoryUrl, $this->cloudCredentials->getBaseUri());
}

/**
* @return string[][]
*/
public static function providerTestAcsfAuthLoginInvalid(): array
{
return [
[
['--factory-url' => 'example.com', '--key' => 'asdfasdfasdf','--username' => 'asdf'],
'This value is not a valid URL.',
],
[
['--factory-url' => 'https://example.com', '--key' => 'asdf','--username' => 'asdf'],
'This value is too short. It should have 10 characters or more.',
],
];
}

/**
* @dataProvider providerTestAcsfAuthLoginInvalid
* @throws \Exception
*/
public function testAcsfAuthLoginInvalid(array $args, string $message): void
{
$this->clientServiceProphecy->isMachineAuthenticated()
->willReturn(false);
$this->removeMockCloudConfigFile();
$this->createDataStores();
$this->command = $this->createCommand();
$this->expectException(ValidatorException::class);
$this->expectExceptionMessage($message);
$this->executeCommand($args);
}

protected function assertKeySavedCorrectly(): void
{
$credsFile = $this->cloudConfigFilepath;
Expand Down

0 comments on commit efd491f

Please sign in to comment.