From d8a0127c0c5ee913418c7f7764e78668584959d6 Mon Sep 17 00:00:00 2001 From: Mauro Bonfietti Date: Wed, 12 Oct 2022 12:19:58 -0300 Subject: [PATCH] Added tests for Clear Cache Command. (#11066) * Added tests for Clear Cache Command. * Fix side-effects breaking other tests Co-authored-by: Jordi Boggiano --- .../Test/Command/ClearCacheCommandTest.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/Composer/Test/Command/ClearCacheCommandTest.php diff --git a/tests/Composer/Test/Command/ClearCacheCommandTest.php b/tests/Composer/Test/Command/ClearCacheCommandTest.php new file mode 100644 index 000000000..7a528ffae --- /dev/null +++ b/tests/Composer/Test/Command/ClearCacheCommandTest.php @@ -0,0 +1,61 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Test\Command; + +use Composer\Test\TestCase; +use Composer\Util\Platform; + +class ClearCacheCommandTest extends TestCase +{ + public function tearDown(): void + { + // --no-cache triggers the env to change so make sure the env is cleaned up after these tests run + Platform::clearEnv('COMPOSER_CACHE_DIR'); + } + + public function testClearCacheCommandSuccess(): void + { + $appTester = $this->getApplicationTester(); + $appTester->run(['command' => 'clear-cache']); + + $appTester->assertCommandIsSuccessful(); + + $output = $appTester->getDisplay(true); + + $this->assertStringContainsString('All caches cleared.', $output); + } + + public function testClearCacheCommandWithOptionGarbageCollection(): void + { + $appTester = $this->getApplicationTester(); + $appTester->run(['command' => 'clear-cache', '--gc' => true]); + + $appTester->assertCommandIsSuccessful(); + + $output = $appTester->getDisplay(true); + + $this->assertStringContainsString('All caches garbage-collected.', $output); + } + + public function testClearCacheCommandWithOptionNoCache(): void + { + $appTester = $this->getApplicationTester(); + $appTester->run(['command' => 'clear-cache', '--no-cache' => true]); + + $appTester->assertCommandIsSuccessful(); + + $output = $appTester->getDisplay(true); + + $this->assertStringContainsString('Cache is not enabled', $output); + } +}