[TwigBridge] Fix missing path and separators in loader paths list on debug:twig output
This commit is contained in:
parent
52270d1e5a
commit
ba7a4ca863
@ -151,19 +151,27 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
$rows = array();
|
$rows = array();
|
||||||
|
$firstNamespace = true;
|
||||||
|
$prevHasSeparator = false;
|
||||||
foreach ($this->getLoaderPaths() as $namespace => $paths) {
|
foreach ($this->getLoaderPaths() as $namespace => $paths) {
|
||||||
if (count($paths) > 1) {
|
if (!$firstNamespace && !$prevHasSeparator && count($paths) > 1) {
|
||||||
$rows[] = array('', '');
|
$rows[] = array('', '');
|
||||||
}
|
}
|
||||||
|
$firstNamespace = false;
|
||||||
foreach ($paths as $path) {
|
foreach ($paths as $path) {
|
||||||
$rows[] = array($namespace, '- '.$path);
|
$rows[] = array($namespace, $path.DIRECTORY_SEPARATOR);
|
||||||
$namespace = '';
|
$namespace = '';
|
||||||
}
|
}
|
||||||
if (count($paths) > 1) {
|
if (count($paths) > 1) {
|
||||||
$rows[] = array('', '');
|
$rows[] = array('', '');
|
||||||
|
$prevHasSeparator = true;
|
||||||
|
} else {
|
||||||
|
$prevHasSeparator = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
array_pop($rows);
|
if ($prevHasSeparator) {
|
||||||
|
array_pop($rows);
|
||||||
|
}
|
||||||
$io->section('Loader Paths');
|
$io->section('Loader Paths');
|
||||||
$io->table(array('Namespace', 'Paths'), $rows);
|
$io->table(array('Namespace', 'Paths'), $rows);
|
||||||
|
|
||||||
|
81
src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php
Normal file
81
src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Twig\Tests\Command;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Bridge\Twig\Command\DebugCommand;
|
||||||
|
use Symfony\Component\Console\Application;
|
||||||
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
|
use Twig\Loader\FilesystemLoader;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
|
class DebugCommandTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testDebugCommand()
|
||||||
|
{
|
||||||
|
$tester = $this->createCommandTester();
|
||||||
|
$ret = $tester->execute(array(), array('decorated' => false));
|
||||||
|
|
||||||
|
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
|
||||||
|
$this->assertContains('Functions', trim($tester->getDisplay()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLineSeparatorInLoaderPaths()
|
||||||
|
{
|
||||||
|
// these paths aren't realistic,
|
||||||
|
// they're configured to force the line separator
|
||||||
|
$tester = $this->createCommandTester(array(
|
||||||
|
'Acme' => array('extractor', 'extractor'),
|
||||||
|
'!Acme' => array('extractor', 'extractor'),
|
||||||
|
FilesystemLoader::MAIN_NAMESPACE => array('extractor', 'extractor'),
|
||||||
|
));
|
||||||
|
$ret = $tester->execute(array(), array('decorated' => false));
|
||||||
|
$ds = DIRECTORY_SEPARATOR;
|
||||||
|
$loaderPaths = <<<TXT
|
||||||
|
Loader Paths
|
||||||
|
------------
|
||||||
|
|
||||||
|
----------- ------------
|
||||||
|
Namespace Paths
|
||||||
|
----------- ------------
|
||||||
|
@Acme extractor$ds
|
||||||
|
extractor$ds
|
||||||
|
|
||||||
|
@!Acme extractor$ds
|
||||||
|
extractor$ds
|
||||||
|
|
||||||
|
(None) extractor$ds
|
||||||
|
extractor$ds
|
||||||
|
----------- ------------
|
||||||
|
TXT;
|
||||||
|
|
||||||
|
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
|
||||||
|
$this->assertContains($loaderPaths, trim($tester->getDisplay(true)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createCommandTester(array $paths = array())
|
||||||
|
{
|
||||||
|
$filesystemLoader = new FilesystemLoader(array(), dirname(__DIR__).'/Fixtures');
|
||||||
|
foreach ($paths as $namespace => $relDirs) {
|
||||||
|
foreach ($relDirs as $relDir) {
|
||||||
|
$filesystemLoader->addPath($relDir, $namespace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$command = new DebugCommand(new Environment($filesystemLoader));
|
||||||
|
|
||||||
|
$application = new Application();
|
||||||
|
$application->add($command);
|
||||||
|
$command = $application->find('debug:twig');
|
||||||
|
|
||||||
|
return new CommandTester($command);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user