Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ba7a4ca

Browse filesBrowse files
ycerutonicolas-grekas
authored andcommitted
[TwigBridge] Fix missing path and separators in loader paths list on debug:twig output
1 parent 52270d1 commit ba7a4ca
Copy full SHA for ba7a4ca

File tree

2 files changed

+92
-3
lines changed
Filter options

2 files changed

+92
-3
lines changed

‎src/Symfony/Bridge/Twig/Command/DebugCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Command/DebugCommand.php
+11-3Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,27 @@ protected function execute(InputInterface $input, OutputInterface $output)
151151
}
152152

153153
$rows = array();
154+
$firstNamespace = true;
155+
$prevHasSeparator = false;
154156
foreach ($this->getLoaderPaths() as $namespace => $paths) {
155-
if (count($paths) > 1) {
157+
if (!$firstNamespace && !$prevHasSeparator && count($paths) > 1) {
156158
$rows[] = array('', '');
157159
}
160+
$firstNamespace = false;
158161
foreach ($paths as $path) {
159-
$rows[] = array($namespace, '- '.$path);
162+
$rows[] = array($namespace, $path.DIRECTORY_SEPARATOR);
160163
$namespace = '';
161164
}
162165
if (count($paths) > 1) {
163166
$rows[] = array('', '');
167+
$prevHasSeparator = true;
168+
} else {
169+
$prevHasSeparator = false;
164170
}
165171
}
166-
array_pop($rows);
172+
if ($prevHasSeparator) {
173+
array_pop($rows);
174+
}
167175
$io->section('Loader Paths');
168176
$io->table(array('Namespace', 'Paths'), $rows);
169177

+81Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Twig\Tests\Command;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\Twig\Command\DebugCommand;
16+
use Symfony\Component\Console\Application;
17+
use Symfony\Component\Console\Tester\CommandTester;
18+
use Twig\Loader\FilesystemLoader;
19+
use Twig\Environment;
20+
21+
class DebugCommandTest extends TestCase
22+
{
23+
public function testDebugCommand()
24+
{
25+
$tester = $this->createCommandTester();
26+
$ret = $tester->execute(array(), array('decorated' => false));
27+
28+
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
29+
$this->assertContains('Functions', trim($tester->getDisplay()));
30+
}
31+
32+
public function testLineSeparatorInLoaderPaths()
33+
{
34+
// these paths aren't realistic,
35+
// they're configured to force the line separator
36+
$tester = $this->createCommandTester(array(
37+
'Acme' => array('extractor', 'extractor'),
38+
'!Acme' => array('extractor', 'extractor'),
39+
FilesystemLoader::MAIN_NAMESPACE => array('extractor', 'extractor'),
40+
));
41+
$ret = $tester->execute(array(), array('decorated' => false));
42+
$ds = DIRECTORY_SEPARATOR;
43+
$loaderPaths = <<<TXT
44+
Loader Paths
45+
------------
46+
47+
----------- ------------
48+
Namespace Paths
49+
----------- ------------
50+
@Acme extractor$ds
51+
extractor$ds
52+
53+
@!Acme extractor$ds
54+
extractor$ds
55+
56+
(None) extractor$ds
57+
extractor$ds
58+
----------- ------------
59+
TXT;
60+
61+
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
62+
$this->assertContains($loaderPaths, trim($tester->getDisplay(true)));
63+
}
64+
65+
private function createCommandTester(array $paths = array())
66+
{
67+
$filesystemLoader = new FilesystemLoader(array(), dirname(__DIR__).'/Fixtures');
68+
foreach ($paths as $namespace => $relDirs) {
69+
foreach ($relDirs as $relDir) {
70+
$filesystemLoader->addPath($relDir, $namespace);
71+
}
72+
}
73+
$command = new DebugCommand(new Environment($filesystemLoader));
74+
75+
$application = new Application();
76+
$application->add($command);
77+
$command = $application->find('debug:twig');
78+
79+
return new CommandTester($command);
80+
}
81+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.