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

Skip to content

Commit cf75c41

Browse files
committed
Fix missing path and separators in loader paths list
1 parent 52270d1 commit cf75c41

File tree

2 files changed

+89
-2
lines changed

2 files changed

+89
-2
lines changed

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

Lines changed: 10 additions & 2 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) {
159162
$rows[] = array($namespace, '- '.$path);
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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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 testLoaderPaths()
33+
{
34+
$tester = $this->createCommandTester(array(
35+
'Acme' => array('extractor', 'extractor'),
36+
'!Acme' => array('extractor', 'extractor'),
37+
FilesystemLoader::MAIN_NAMESPACE => array('extractor', 'extractor'),
38+
));
39+
$ret = $tester->execute(array(), array('decorated' => false));
40+
41+
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
42+
$loaderPaths = <<<TXT
43+
Loader Paths
44+
------------
45+
46+
----------- -------------
47+
Namespace Paths
48+
----------- -------------
49+
@Acme - extractor
50+
- extractor
51+
52+
@!Acme - extractor
53+
- extractor
54+
55+
(None) - extractor
56+
- extractor
57+
----------- -------------
58+
TXT;
59+
60+
$this->assertContains($loaderPaths, $tester->getDisplay());
61+
}
62+
63+
private function createCommandTester(array $paths = array())
64+
{
65+
$filesystemLoader = new FilesystemLoader(array(), dirname(__DIR__).'/Fixtures');
66+
foreach ($paths as $namespace => $relDirs) {
67+
foreach ($relDirs as $relDir) {
68+
$filesystemLoader->addPath($relDir, $namespace);
69+
}
70+
}
71+
$command = new DebugCommand(new Environment($filesystemLoader));
72+
73+
$application = new Application();
74+
$application->add($command);
75+
$command = $application->find('debug:twig');
76+
77+
return new CommandTester($command);
78+
}
79+
}

0 commit comments

Comments
 (0)