Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 97997c1

Browse files
committed
Merge branch '3.4' into 4.1
* 3.4: Fix: Adjust DocBlock \"ParserTest->getParserTestData()\" -> only some more tests [Lock] Pedantic improvements for lock [EventDispatcher] Fixed phpdoc on interface update year in license files [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 [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 a54d00a + 86d8c71 commit 97997c1

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
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
/**
@@ -1090,6 +1090,14 @@ public function setDefaultCommand($commandName, $isSingleCommand = false)
10901090
return $this;
10911091
}
10921092

1093+
/**
1094+
* @internal
1095+
*/
1096+
public function isSingleCommand()
1097+
{
1098+
return $this->singleCommand;
1099+
}
1100+
10931101
private function splitStringByWidth($string, $width)
10941102
{
10951103
// 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());

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)