Restore the ability to list the scripts in the 'run-script' command without providing a script (#10710)
parent
eb36025d37
commit
58e135181d
|
@ -5893,6 +5893,11 @@ parameters:
|
||||||
count: 1
|
count: 1
|
||||||
path: ../tests/Composer/Test/CacheTest.php
|
path: ../tests/Composer/Test/CacheTest.php
|
||||||
|
|
||||||
|
-
|
||||||
|
message: "#^Dynamic call to static method Composer\\\\Test\\\\TestCase\\:\\:getUniqueTmpDirectory\\(\\)\\.$#"
|
||||||
|
count: 1
|
||||||
|
path: ../tests/Composer/Test/Command/RunScriptCommandTest.php
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Dynamic call to static method Composer\\\\Test\\\\TestCase\\:\\:getUniqueTmpDirectory\\(\\)\\.$#"
|
message: "#^Dynamic call to static method Composer\\\\Test\\\\TestCase\\:\\:getUniqueTmpDirectory\\(\\)\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
|
|
@ -54,7 +54,7 @@ class RunScriptCommand extends BaseCommand
|
||||||
->setAliases(array('run'))
|
->setAliases(array('run'))
|
||||||
->setDescription('Runs the scripts defined in composer.json.')
|
->setDescription('Runs the scripts defined in composer.json.')
|
||||||
->setDefinition(array(
|
->setDefinition(array(
|
||||||
new InputArgument('script', InputArgument::REQUIRED, 'Script name to run.'),
|
new InputArgument('script', InputArgument::OPTIONAL, 'Script name to run.'),
|
||||||
new InputArgument('args', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, ''),
|
new InputArgument('args', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, ''),
|
||||||
new InputOption('timeout', null, InputOption::VALUE_REQUIRED, 'Sets script timeout in seconds, or 0 for never.'),
|
new InputOption('timeout', null, InputOption::VALUE_REQUIRED, 'Sets script timeout in seconds, or 0 for never.'),
|
||||||
new InputOption('dev', null, InputOption::VALUE_NONE, 'Sets the dev mode.'),
|
new InputOption('dev', null, InputOption::VALUE_NONE, 'Sets the dev mode.'),
|
||||||
|
@ -80,6 +80,10 @@ EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
$script = $input->getArgument('script');
|
$script = $input->getArgument('script');
|
||||||
|
if ($script === null) {
|
||||||
|
throw new \RuntimeException('Missing required argument "script"');
|
||||||
|
}
|
||||||
|
|
||||||
if (!in_array($script, $this->scriptEvents)) {
|
if (!in_array($script, $this->scriptEvents)) {
|
||||||
if (defined('Composer\Script\ScriptEvents::'.str_replace('-', '_', strtoupper($script)))) {
|
if (defined('Composer\Script\ScriptEvents::'.str_replace('-', '_', strtoupper($script)))) {
|
||||||
throw new \InvalidArgumentException(sprintf('Script "%s" cannot be run with this command', $script));
|
throw new \InvalidArgumentException(sprintf('Script "%s" cannot be run with this command', $script));
|
||||||
|
|
|
@ -12,13 +12,35 @@
|
||||||
|
|
||||||
namespace Composer\Test\Command;
|
namespace Composer\Test\Command;
|
||||||
|
|
||||||
|
use Composer\Command\RunScriptCommand;
|
||||||
use Composer\Composer;
|
use Composer\Composer;
|
||||||
use Composer\Config;
|
use Composer\Config;
|
||||||
|
use Composer\Console\Application;
|
||||||
use Composer\Script\Event as ScriptEvent;
|
use Composer\Script\Event as ScriptEvent;
|
||||||
use Composer\Test\TestCase;
|
use Composer\Test\TestCase;
|
||||||
|
use Composer\Util\Filesystem;
|
||||||
|
use Symfony\Component\Console\Tester\ApplicationTester;
|
||||||
|
|
||||||
class RunScriptCommandTest extends TestCase
|
class RunScriptCommandTest extends TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $home;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
$this->home = $this->getUniqueTmpDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
$fs = new Filesystem();
|
||||||
|
$fs->removeDirectory($this->home);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getDevOptions
|
* @dataProvider getDevOptions
|
||||||
* @param bool $dev
|
* @param bool $dev
|
||||||
|
@ -88,6 +110,35 @@ class RunScriptCommandTest extends TestCase
|
||||||
$command->run($input, $output);
|
$command->run($input, $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCanListScripts(): void
|
||||||
|
{
|
||||||
|
$manifest = [
|
||||||
|
'scripts' => [
|
||||||
|
'test' => '@php test',
|
||||||
|
'fix-cs' => 'php-cs-fixer fix',
|
||||||
|
],
|
||||||
|
'scripts-descriptions' => [
|
||||||
|
'fix-cs' => 'Run the codestyle fixer',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
file_put_contents($this->home.'/composer.json', json_encode($manifest));
|
||||||
|
|
||||||
|
$application = new Application();
|
||||||
|
$application->setAutoExit(false);
|
||||||
|
$application->add(new RunScriptCommand());
|
||||||
|
|
||||||
|
$tester = new ApplicationTester($application);
|
||||||
|
$tester->run(['command' => 'run-script', '--list' => true, '-d' => $this->home]);
|
||||||
|
|
||||||
|
$tester->assertCommandIsSuccessful();
|
||||||
|
|
||||||
|
$output = $tester->getDisplay();
|
||||||
|
|
||||||
|
$this->assertStringContainsString('Runs the test script as defined in composer.json.', $output, 'The default description for the test script should be printed');
|
||||||
|
$this->assertStringContainsString('Run the codestyle fixer', $output, 'The custom description for the fix-cs script should be printed');
|
||||||
|
}
|
||||||
|
|
||||||
/** @return bool[][] **/
|
/** @return bool[][] **/
|
||||||
public function getDevOptions(): array
|
public function getDevOptions(): array
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue