Skip to content

Commit 471125d

Browse files
committed
Merge branch '4.2'
* 4.2: update years in license files Fix: Adjust DocBlock \"ParserTest->getParserTestData()\" -> only some more tests access the container getting it from the kernel Replace slave and master by replica and primary Fix erasing cookies issue [Lock] Pedantic improvements for lock [EventDispatcher] Fixed phpdoc on interface update year in license files [VarExporter] fix exporting array indexes [SecurityBundle] Fix traceable voters [Console] Fix help text for single command applications Fix random test failure on lock improve error message when using test client without the BrowserKit component Fixed minor typos in an error message [Event Dispatcher] fixed 29703: TraceableEventDispatcher reset now sets callStack to null with test to dispatch after reset. Fixed minor typos Fix: Method can also return null [Stopwatch] Fixed phpdoc for category name
2 parents 20e4894 + bcc0658 commit 471125d

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

Application.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Application
7575
private $dispatcher;
7676
private $terminal;
7777
private $defaultCommand;
78-
private $singleCommand;
78+
private $singleCommand = false;
7979
private $initialized;
8080

8181
/**
@@ -1098,6 +1098,14 @@ public function setDefaultCommand($commandName, $isSingleCommand = false)
10981098
return $this;
10991099
}
11001100

1101+
/**
1102+
* @internal
1103+
*/
1104+
public function isSingleCommand()
1105+
{
1106+
return $this->singleCommand;
1107+
}
1108+
11011109
private function splitStringByWidth($string, $width)
11021110
{
11031111
// str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly.

Command/Command.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,15 @@ public function getHelp()
525525
public function getProcessedHelp()
526526
{
527527
$name = $this->name;
528+
$isSingleCommand = $this->application && $this->application->isSingleCommand();
528529

529530
$placeholders = array(
530531
'%command.name%',
531532
'%command.full_name%',
532533
);
533534
$replacements = array(
534535
$name,
535-
$_SERVER['PHP_SELF'].' '.$name,
536+
$isSingleCommand ? $_SERVER['PHP_SELF'] : $_SERVER['PHP_SELF'].' '.$name,
536537
);
537538

538539
return str_replace($placeholders, $replacements, $this->getHelp() ?: $this->getDescription());

Helper/ProcessHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function run(OutputInterface $output, $cmd, $error = null, callable $call
6161
$process = $cmd[0];
6262
unset($cmd[0]);
6363
} else {
64-
throw new \InvalidArgumentException(sprintf('Invalid command provided to "%s()": the command should an array whose first is element is either the path to the binary to run of a "Process" object.', __METHOD__));
64+
throw new \InvalidArgumentException(sprintf('Invalid command provided to "%s()": the command should be an array whose first element is either the path to the binary to run or a "Process" object.', __METHOD__));
6565
}
6666

6767
if ($verbosity <= $output->getVerbosity()) {

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2004-2018 Fabien Potencier
1+
Copyright (c) 2004-2019 Fabien Potencier
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

Tests/Command/CommandTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ public function testGetProcessedHelp()
166166
$command = new \TestCommand();
167167
$command->setHelp('');
168168
$this->assertContains('description', $command->getProcessedHelp(), '->getProcessedHelp() falls back to the description');
169+
170+
$command = new \TestCommand();
171+
$command->setHelp('The %command.name% command does... Example: php %command.full_name%.');
172+
$application = new Application();
173+
$application->add($command);
174+
$application->setDefaultCommand('namespace:name', true);
175+
$this->assertContains('The namespace:name command does...', $command->getProcessedHelp(), '->getProcessedHelp() replaces %command.name% correctly in single command applications');
176+
$this->assertNotContains('%command.full_name%', $command->getProcessedHelp(), '->getProcessedHelp() replaces %command.full_name% in single command applications');
169177
}
170178

171179
public function testGetSetAliases()

0 commit comments

Comments
 (0)