diff --git a/src/AuditCommand.php b/src/AuditCommand.php index 2262f67..a4ae641 100644 --- a/src/AuditCommand.php +++ b/src/AuditCommand.php @@ -127,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln(sprintf( 'Checking %s (%s) for advisories...', $name, - $name !== 'cs278/composer-audit' ? $version : 'N/A' + !self::isUnderTest() ? $version : 'N/A' ), OutputInterface::VERBOSITY_DEBUG); foreach ($advisoriesManager->findByPackageNameAndVersion($name, $version) as $advisory) { @@ -139,7 +139,7 @@ protected function execute(InputInterface $input, OutputInterface $output) 'Found %u advisories for %s (%s)', \count($advisories[$name]), $name, - $name !== 'cs278/composer-audit' ? $version : 'N/A' + !self::isUnderTest() ? $version : 'N/A' ), OutputInterface::VERBOSITY_VERY_VERBOSE); } } @@ -300,4 +300,17 @@ private static function clearLine(OutputInterface $output): void $output->writeln(''); } } + + /** + * Check if the command is being run by the test suite. + * + * This is used to hide version information which will go stale as new packages + * are published. + */ + private static function isUnderTest(): bool + { + $value = filter_var(getenv('COMPOSER_AUDIT_TEST'), \FILTER_VALIDATE_BOOLEAN); + + return $value !== null ? $value : false; + } } diff --git a/tests/integration/IntegrationTest.php b/tests/integration/IntegrationTest.php index 999b6a5..39dd895 100644 --- a/tests/integration/IntegrationTest.php +++ b/tests/integration/IntegrationTest.php @@ -108,6 +108,7 @@ public function testRun(int $expectedExit, string $expectedOutput, string $condi return new Process($args, $workingDir, [ 'COMPOSER_HOME' => $workingDir.'/.composer', 'COMPOSER_CACHE_DIR' => self::$cacheDir, + 'COMPOSER_AUDIT_TEST' => 1, ]); }; diff --git a/tests/integration/ignore--broken-show-warnings.test b/tests/integration/ignore--broken-show-warnings.test index 7a760ed..000d0ec 100644 --- a/tests/integration/ignore--broken-show-warnings.test +++ b/tests/integration/ignore--broken-show-warnings.test @@ -25,7 +25,7 @@ true Ignoring invalid ignore rule: `{"type":"package","value":"foo\/bar"}` Ignoring invalid ignore rule: `{"type":"cve","value":""}` Ignoring invalid ignore rule: `{"type":"","value":"test"}` -Found 9 advisories for symfony/http-foundation (2.0.4) +Found 9 advisories for symfony/http-foundation (N/A) Found 9 advisories affecting 1 package(s). composer://symfony/http-foundation (2.0.4) diff --git a/tests/integration/verbose_debug_no_errors.test b/tests/integration/verbose_debug_no_errors.test index c57949c..cae9c90 100644 --- a/tests/integration/verbose_debug_no_errors.test +++ b/tests/integration/verbose_debug_no_errors.test @@ -10,8 +10,8 @@ true 0 --EXPECT-OUTPUT-- Checking cs278/composer-audit (N/A) for advisories... -Checking symfony/deprecation-contracts (v2.4.0) for advisories... -Checking symfony/polyfill-ctype (v1.23.0) for advisories... -Checking symfony/polyfill-php80 (v1.23.0) for advisories... -Checking symfony/yaml (v5.3.4) for advisories... +Checking symfony/deprecation-contracts (N/A) for advisories... +Checking symfony/polyfill-ctype (N/A) for advisories... +Checking symfony/polyfill-php80 (N/A) for advisories... +Checking symfony/yaml (N/A) for advisories... No advisories found for any packages.