|
10 | 10 | use PHPUnit\Framework\Attributes\CoversClass; |
11 | 11 | use Symfony\Component\Console\Command\Command; |
12 | 12 | use Twig\Error\SyntaxError; |
13 | | -use Twig\Source; |
14 | 13 |
|
15 | 14 | use function class_exists; |
16 | 15 | use function sort; |
@@ -86,36 +85,19 @@ public function testGetFilesInfo(): void |
86 | 85 |
|
87 | 86 | public function testGetFilesInfoInvalidFile(): void |
88 | 87 | { |
89 | | - $command = $this->getMockBuilder(TwigLintCommand::class) |
90 | | - ->onlyMethods(['getTemplateContents', 'findFiles']) |
91 | | - ->getMock(); |
92 | | - |
93 | | - $command->expects(self::exactly(1)) |
94 | | - ->method('findFiles') |
95 | | - ->willReturn( |
96 | | - ['foo.twig', 'foo-invalid.twig'], |
97 | | - ); |
98 | | - |
99 | | - $command->expects(self::exactly(2))->method('getTemplateContents')->willReturnMap([ |
100 | | - ['foo.twig', '{{ file }}'], |
101 | | - ['foo-invalid.twig', '{{ file }'], |
102 | | - ]); |
103 | | - |
104 | | - $filesFound = $this->callFunction($command, TwigLintCommand::class, 'getFilesInfo', [ |
105 | | - __DIR__ . '/../_data/file_listing', |
106 | | - ]); |
107 | | - |
108 | | - self::assertEquals([ |
109 | | - ['template' => '{{ file }}', 'file' => 'foo.twig'], |
110 | | - [ |
111 | | - 'template' => '{{ file }', |
112 | | - 'file' => 'foo-invalid.twig', |
113 | | - 'exception' => new SyntaxError('Unexpected "}".', 1, new Source( |
114 | | - '{{ file }', |
115 | | - 'foo-invalid.twig', |
116 | | - )), |
117 | | - ], |
118 | | - ], $filesFound); |
| 88 | + $twigLintCommand = new TwigLintCommand(); |
| 89 | + $path = __DIR__ . '/../_data/templates/lint_command'; |
| 90 | + $filesFound = $twigLintCommand->getFilesInfo($path); |
| 91 | + |
| 92 | + self::assertCount(2, $filesFound); |
| 93 | + self::assertSame('{{ file }' . "\n", $filesFound[0]['template']); |
| 94 | + self::assertSame($path . '/foo-invalid.twig', $filesFound[0]['file']); |
| 95 | + self::assertArrayHasKey('exception', $filesFound[0]); |
| 96 | + $exception = $filesFound[0]['exception']; |
| 97 | + self::assertInstanceOf(SyntaxError::class, $exception); |
| 98 | + self::assertSame('Unexpected "}" in "' . $path . '/foo-invalid.twig" at line 1.', $exception->getMessage()); |
| 99 | + self::assertSame('{{ file }}' . "\n", $filesFound[1]['template']); |
| 100 | + self::assertSame($path . '/foo-valid.twig', $filesFound[1]['file']); |
119 | 101 | } |
120 | 102 |
|
121 | 103 | public function testGetContext(): void |
|
0 commit comments