Skip to content

Commit

Permalink
Merge branch '3.4' into 4.1
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
xabbuh committed Jan 3, 2019
2 parents a54d00a + 86d8c71 commit 97997c1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
10 changes: 9 additions & 1 deletion Application.php
Expand Up @@ -75,7 +75,7 @@ class Application
private $dispatcher;
private $terminal;
private $defaultCommand;
private $singleCommand;
private $singleCommand = false;
private $initialized;

/**
Expand Down Expand Up @@ -1090,6 +1090,14 @@ public function setDefaultCommand($commandName, $isSingleCommand = false)
return $this;
}

/**
* @internal
*/
public function isSingleCommand()
{
return $this->singleCommand;
}

private function splitStringByWidth($string, $width)
{
// str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly.
Expand Down
3 changes: 2 additions & 1 deletion Command/Command.php
Expand Up @@ -525,14 +525,15 @@ public function getHelp()
public function getProcessedHelp()
{
$name = $this->name;
$isSingleCommand = $this->application && $this->application->isSingleCommand();

$placeholders = array(
'%command.name%',
'%command.full_name%',
);
$replacements = array(
$name,
$_SERVER['PHP_SELF'].' '.$name,
$isSingleCommand ? $_SERVER['PHP_SELF'] : $_SERVER['PHP_SELF'].' '.$name,
);

return str_replace($placeholders, $replacements, $this->getHelp() ?: $this->getDescription());
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2004-2018 Fabien Potencier
Copyright (c) 2004-2019 Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 8 additions & 0 deletions Tests/Command/CommandTest.php
Expand Up @@ -166,6 +166,14 @@ public function testGetProcessedHelp()
$command = new \TestCommand();
$command->setHelp('');
$this->assertContains('description', $command->getProcessedHelp(), '->getProcessedHelp() falls back to the description');

$command = new \TestCommand();
$command->setHelp('The %command.name% command does... Example: php %command.full_name%.');
$application = new Application();
$application->add($command);
$application->setDefaultCommand('namespace:name', true);
$this->assertContains('The namespace:name command does...', $command->getProcessedHelp(), '->getProcessedHelp() replaces %command.name% correctly in single command applications');
$this->assertNotContains('%command.full_name%', $command->getProcessedHelp(), '->getProcessedHelp() replaces %command.full_name% in single command applications');
}

public function testGetSetAliases()
Expand Down

0 comments on commit 97997c1

Please sign in to comment.