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

[TwigBridge] Fix missing path and separators in loader paths list on debug:twig output #27728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions 14 src/Symfony/Bridge/Twig/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,27 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$rows = array();
$firstNamespace = true;
$prevHasSeparator = false;
foreach ($this->getLoaderPaths() as $namespace => $paths) {
if (count($paths) > 1) {
if (!$firstNamespace && !$prevHasSeparator && count($paths) > 1) {
$rows[] = array('', '');
}
$firstNamespace = false;
foreach ($paths as $path) {
$rows[] = array($namespace, '- '.$path);
$rows[] = array($namespace, $path.DIRECTORY_SEPARATOR);
$namespace = '';
}
if (count($paths) > 1) {
$rows[] = array('', '');
$prevHasSeparator = true;
} else {
$prevHasSeparator = false;
}
}
array_pop($rows);
if ($prevHasSeparator) {
array_pop($rows);
}
$io->section('Loader Paths');
$io->table(array('Namespace', 'Paths'), $rows);

Expand Down
81 changes: 81 additions & 0 deletions 81 src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php
Original file line number Diff line number Diff line change
@@ -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);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.