Skip to content

Commit 9c05b51

Browse files
committed
Merge branch '4.4' into 5.0
* 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
2 parents 515c7ee + db75aa0 commit 9c05b51

File tree

4 files changed

+77
-4
lines changed

4 files changed

+77
-4
lines changed

Application.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,15 @@ public function find(string $name)
647647
// filter out aliases for commands which are already on the list
648648
if (\count($commands) > 1) {
649649
$commandList = $this->commandLoader ? array_merge(array_flip($this->commandLoader->getNames()), $this->commands) : $this->commands;
650-
$commands = array_unique(array_filter($commands, function ($nameOrAlias) use (&$commandList, $commands, &$aliases) {
650+
651+
if (isset($commandList[$name])) {
652+
return $this->get($name);
653+
}
654+
655+
foreach ($commands as $k => $nameOrAlias) {
656+
if ($nameOrAlias === $name) {
657+
return $this->get($nameOrAlias);
658+
}
651659
if (!$commandList[$nameOrAlias] instanceof Command) {
652660
$commandList[$nameOrAlias] = $this->commandLoader->get($nameOrAlias);
653661
}
@@ -656,8 +664,14 @@ public function find(string $name)
656664

657665
$aliases[$nameOrAlias] = $commandName;
658666

659-
return $commandName === $nameOrAlias || !\in_array($commandName, $commands);
660-
}));
667+
if ($commandName === $nameOrAlias || !\in_array($commandName, $commands)) {
668+
continue;
669+
}
670+
671+
unset($commands[$k]);
672+
}
673+
674+
$commands = array_unique($commands);
661675
}
662676

663677
if (\count($commands) > 1) {

Helper/Table.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,9 @@ private function calculateRowCount(): int
589589
++$numberOfRows; // Add row for header separator
590590
}
591591

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

594596
return $numberOfRows;
595597
}

Tests/ApplicationTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,31 @@ public function testAllExcludesDisabledLazyCommand()
16921692
$this->assertArrayNotHasKey('disabled', $application->all());
16931693
}
16941694

1695+
public function testFindAlternativesDoesNotLoadSameNamespaceCommandsOnExactMatch()
1696+
{
1697+
$application = new Application();
1698+
$application->setAutoExit(false);
1699+
1700+
$loaded = [];
1701+
1702+
$application->setCommandLoader(new FactoryCommandLoader([
1703+
'foo:bar' => function () use (&$loaded) {
1704+
$loaded['foo:bar'] = true;
1705+
1706+
return (new Command('foo:bar'))->setCode(function () {});
1707+
},
1708+
'foo' => function () use (&$loaded) {
1709+
$loaded['foo'] = true;
1710+
1711+
return (new Command('foo'))->setCode(function () {});
1712+
},
1713+
]));
1714+
1715+
$application->run(new ArrayInput(['command' => 'foo']), new NullOutput());
1716+
1717+
$this->assertSame(['foo' => true], $loaded);
1718+
}
1719+
16951720
protected function getDispatcher($skipCommand = false)
16961721
{
16971722
$dispatcher = new EventDispatcher();

Tests/Helper/TableTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,38 @@ public function testAppendRowWithoutSectionOutput()
951951
$table->appendRow(['9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens', '139.25']);
952952
}
953953

954+
public function testSectionOutputHandlesZeroRowsAfterRender()
955+
{
956+
$sections = [];
957+
$stream = $this->getOutputStream(true);
958+
$output = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
959+
$output->writeln('My Table');
960+
$table = new Table($output);
961+
$table
962+
->setHeaders(['ISBN', 'Title', 'Author', 'Price'])
963+
->setRows([]);
964+
965+
$table->render();
966+
967+
$table->appendRow(['9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens', '139.25']);
968+
969+
$expected =
970+
<<<TABLE
971+
My Table
972+
+------+-------+--------+-------+
973+
|\033[32m ISBN \033[39m|\033[32m Title \033[39m|\033[32m Author \033[39m|\033[32m Price \033[39m|
974+
+------+-------+--------+-------+
975+
\x1b[3A\x1b[0J+---------------+----------------------+-----------------+--------+
976+
|\033[32m ISBN \033[39m|\033[32m Title \033[39m|\033[32m Author \033[39m|\033[32m Price \033[39m|
977+
+---------------+----------------------+-----------------+--------+
978+
| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens | 139.25 |
979+
+---------------+----------------------+-----------------+--------+
980+
981+
TABLE;
982+
983+
$this->assertEquals($expected, $this->getOutputContent($output));
984+
}
985+
954986
public function testIsNotDefinedStyleException()
955987
{
956988
$this->expectException('Symfony\Component\Console\Exception\InvalidArgumentException');

0 commit comments

Comments
 (0)