Skip to content

Commit

Permalink
Merge branch '4.4' into 5.0
Browse files Browse the repository at this point in the history
* 4.4:
  fix unix root dir issue
  sync validator translation files with master
  [HttpFoundation] fix not sending Content-Type header for 204 responses
  [ErrorHandler] silence warning when zend.assertions=-1
  fix anchor
  [Console] Handle zero row count in appendRow() for Table
  fix links to releases page (formerly known as "roadmap")
  [Console] Don't load same-namespace alternatives on exact match found
  • Loading branch information
fabpot committed Feb 14, 2020
2 parents 515c7ee + db75aa0 commit 9c05b51
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
20 changes: 17 additions & 3 deletions Application.php
Expand Up @@ -647,7 +647,15 @@ public function find(string $name)
// filter out aliases for commands which are already on the list
if (\count($commands) > 1) {
$commandList = $this->commandLoader ? array_merge(array_flip($this->commandLoader->getNames()), $this->commands) : $this->commands;
$commands = array_unique(array_filter($commands, function ($nameOrAlias) use (&$commandList, $commands, &$aliases) {

if (isset($commandList[$name])) {
return $this->get($name);
}

foreach ($commands as $k => $nameOrAlias) {
if ($nameOrAlias === $name) {
return $this->get($nameOrAlias);
}
if (!$commandList[$nameOrAlias] instanceof Command) {
$commandList[$nameOrAlias] = $this->commandLoader->get($nameOrAlias);
}
Expand All @@ -656,8 +664,14 @@ public function find(string $name)

$aliases[$nameOrAlias] = $commandName;

return $commandName === $nameOrAlias || !\in_array($commandName, $commands);
}));
if ($commandName === $nameOrAlias || !\in_array($commandName, $commands)) {
continue;
}

unset($commands[$k]);
}

$commands = array_unique($commands);
}

if (\count($commands) > 1) {
Expand Down
4 changes: 3 additions & 1 deletion Helper/Table.php
Expand Up @@ -589,7 +589,9 @@ private function calculateRowCount(): int
++$numberOfRows; // Add row for header separator
}

++$numberOfRows; // Add row for footer separator
if (\count($this->rows) > 0) {
++$numberOfRows; // Add row for footer separator
}

return $numberOfRows;
}
Expand Down
25 changes: 25 additions & 0 deletions Tests/ApplicationTest.php
Expand Up @@ -1692,6 +1692,31 @@ public function testAllExcludesDisabledLazyCommand()
$this->assertArrayNotHasKey('disabled', $application->all());
}

public function testFindAlternativesDoesNotLoadSameNamespaceCommandsOnExactMatch()
{
$application = new Application();
$application->setAutoExit(false);

$loaded = [];

$application->setCommandLoader(new FactoryCommandLoader([
'foo:bar' => function () use (&$loaded) {
$loaded['foo:bar'] = true;

return (new Command('foo:bar'))->setCode(function () {});
},
'foo' => function () use (&$loaded) {
$loaded['foo'] = true;

return (new Command('foo'))->setCode(function () {});
},
]));

$application->run(new ArrayInput(['command' => 'foo']), new NullOutput());

$this->assertSame(['foo' => true], $loaded);
}

protected function getDispatcher($skipCommand = false)
{
$dispatcher = new EventDispatcher();
Expand Down
32 changes: 32 additions & 0 deletions Tests/Helper/TableTest.php
Expand Up @@ -951,6 +951,38 @@ public function testAppendRowWithoutSectionOutput()
$table->appendRow(['9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens', '139.25']);
}

public function testSectionOutputHandlesZeroRowsAfterRender()
{
$sections = [];
$stream = $this->getOutputStream(true);
$output = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
$output->writeln('My Table');
$table = new Table($output);
$table
->setHeaders(['ISBN', 'Title', 'Author', 'Price'])
->setRows([]);

$table->render();

$table->appendRow(['9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens', '139.25']);

$expected =
<<<TABLE
My Table
+------+-------+--------+-------+
|\033[32m ISBN \033[39m|\033[32m Title \033[39m|\033[32m Author \033[39m|\033[32m Price \033[39m|
+------+-------+--------+-------+
\x1b[3A\x1b[0J+---------------+----------------------+-----------------+--------+
|\033[32m ISBN \033[39m|\033[32m Title \033[39m|\033[32m Author \033[39m|\033[32m Price \033[39m|
+---------------+----------------------+-----------------+--------+
| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens | 139.25 |
+---------------+----------------------+-----------------+--------+
TABLE;

$this->assertEquals($expected, $this->getOutputContent($output));
}

public function testIsNotDefinedStyleException()
{
$this->expectException('Symfony\Component\Console\Exception\InvalidArgumentException');
Expand Down

0 comments on commit 9c05b51

Please sign in to comment.