diff --git a/src/Command/ListCommand.php b/src/Command/ListCommand.php index 3b1eae0..3836b67 100644 --- a/src/Command/ListCommand.php +++ b/src/Command/ListCommand.php @@ -3,12 +3,13 @@ namespace PrivatePackagist\VendorDataExporter\Command; use PrivatePackagist\ApiClient\Client as PackagistApiClient; +use PrivatePackagist\VendorDataExporter\Exceptions\MissingApiCredentialsException; use PrivatePackagist\VendorDataExporter\Formatter\Manager; use PrivatePackagist\VendorDataExporter\Formatter\ManagerInterface; use PrivatePackagist\VendorDataExporter\Model; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; /** @@ -16,7 +17,7 @@ * @phpstan-import-type PackageShape from Model\Package * @phpstan-import-type VersionShape from Model\Version */ -class ListCommand extends Command +final class ListCommand extends Command { public const DEFAULT_COMMAND_NAME = 'list'; @@ -73,10 +74,10 @@ private function getPackagistApiClient(InputInterface $input): PackagistApiClien } if (!is_string($token = $input->getOption('token'))) { - $token = $_ENV['PACKAGIST_API_TOKEN'] ?? throw new \InvalidArgumentException('Missing API credentials: provide API token via command flag or environment variable.'); + $token = $_ENV['PACKAGIST_API_TOKEN'] ?? throw MissingApiCredentialsException::missingApiToken(); } if (!is_string($secret = $input->getOption('secret'))) { - $secret = $_ENV['PACKAGIST_API_SECRET'] ?? throw new \InvalidArgumentException('Missing API credentials: provide API secret via command flag or environment variable.'); + $secret = $_ENV['PACKAGIST_API_SECRET'] ?? throw MissingApiCredentialsException::missingApiSecret(); } $this->packagistApiClient = new PackagistApiClient(null, $_ENV['PACKAGIST_API_URL'] ?? null); diff --git a/src/Exceptions/MissingApiCredentialsException.php b/src/Exceptions/MissingApiCredentialsException.php new file mode 100644 index 0000000..cf3648a --- /dev/null +++ b/src/Exceptions/MissingApiCredentialsException.php @@ -0,0 +1,20 @@ +command->run($input, $output); static::assertCount(49, $this->httpClient->getRequests()); - static::assertSame(file_get_contents(__DIR__ . '/../res/output/output.txt'), $output->fetch()); + static::assertStringEqualsFile(__DIR__ . '/../res/output/output.txt', $output->fetch()); } public function testJsonOutput(): void @@ -51,7 +51,7 @@ public function testJsonOutput(): void $this->command->run($input, $output); static::assertCount(49, $this->httpClient->getRequests()); - static::assertSame(file_get_contents(__DIR__ . '/../res/output/output.json'), $output->fetch()); + static::assertStringEqualsFile(__DIR__ . '/../res/output/output.json', $output->fetch()); } public function testCsvOutput(): void @@ -62,6 +62,6 @@ public function testCsvOutput(): void $this->command->run($input, $output); static::assertCount(49, $this->httpClient->getRequests()); - static::assertSame(file_get_contents(__DIR__ . '/../res/output/output.csv'), $output->fetch()); + static::assertStringEqualsFile(__DIR__ . '/../res/output/output.csv', $output->fetch()); } }