From 29ae7b632a3dea9f6972fa54f180d0c4ca27bb84 Mon Sep 17 00:00:00 2001 From: Dan Barrett Date: Sat, 29 Oct 2022 18:14:48 +1100 Subject: [PATCH] Add "missing lockfile" test for the Audit command --- tests/Composer/Test/Command/AuditCommandTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Composer/Test/Command/AuditCommandTest.php b/tests/Composer/Test/Command/AuditCommandTest.php index 1b820b479..53041f33d 100644 --- a/tests/Composer/Test/Command/AuditCommandTest.php +++ b/tests/Composer/Test/Command/AuditCommandTest.php @@ -13,6 +13,7 @@ namespace Composer\Test\Command; use Composer\Test\TestCase; +use UnexpectedValueException; class AuditCommandTest extends TestCase { @@ -24,5 +25,20 @@ class AuditCommandTest extends TestCase $appTester->run(['command' => 'audit']); $appTester->assertCommandIsSuccessful(); + self::assertEquals('No packages - skipping audit.', trim($appTester->getDisplay(true))); + } + + public function testErrorAuditingLockFileWhenItIsMissing(): void + { + $this->initTempComposer(); + $this->createInstalledJson([self::getPackage()]); + + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage( + "Valid composer.json and composer.lock files are required to run this command with --locked" + ); + + $appTester = $this->getApplicationTester(); + $appTester->run(['command' => 'audit', '--locked' => true]); } }