|
| 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 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