From 13e673df76cca54ab75dd94923948d7b8a57e0cc Mon Sep 17 00:00:00 2001 From: Leo Viezens Date: Thu, 13 Oct 2022 11:21:19 +0200 Subject: [PATCH] #10796 Add test for ExecCommand (#11094) --- .../Composer/Test/Command/ExecCommandTest.php | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/Composer/Test/Command/ExecCommandTest.php diff --git a/tests/Composer/Test/Command/ExecCommandTest.php b/tests/Composer/Test/Command/ExecCommandTest.php new file mode 100644 index 000000000..ee195c4b5 --- /dev/null +++ b/tests/Composer/Test/Command/ExecCommandTest.php @@ -0,0 +1,60 @@ + + * 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; + +class ExecCommandTest extends TestCase +{ + public function testListThrowsIfNoBinariesExist(): void + { + $composerDir = $this->initTempComposer(); + + $composerBinDir = "$composerDir/vendor/bin"; + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage( + "No binaries found in composer.json or in bin-dir ($composerBinDir)" + ); + + $appTester = $this->getApplicationTester(); + $appTester->run(['command' => 'exec', '--list' => true]); + } + + public function testList(): void + { + $composerDir = $this->initTempComposer([ + 'bin' => [ + 'a' + ] + ]); + + $composerBinDir = "$composerDir/vendor/bin"; + mkdir($composerBinDir, 0777, true); + touch($composerBinDir . '/b'); + touch($composerBinDir . '/b.bat'); + touch($composerBinDir . '/c'); + + $appTester = $this->getApplicationTester(); + $appTester->run(['command' => 'exec', '--list' => true]); + + $output = $appTester->getDisplay(true); + + $this->assertSame( + 'Available binaries: +- b +- c +- a (local)', + trim($output) + ); + } +}