|
8 | 8 | use PhpMyAdmin\Tests\AbstractTestCase; |
9 | 9 | use Symfony\Component\Console\Command\Command; |
10 | 10 | use Twig\Error\SyntaxError; |
11 | | -use Twig\Source; |
12 | 11 |
|
13 | 12 | use function class_exists; |
14 | 13 | use function sort; |
@@ -98,53 +97,21 @@ public function testGetFilesInfo(): void |
98 | 97 | ], $filesInfos); |
99 | 98 | } |
100 | 99 |
|
101 | | - /** |
102 | | - * @requires PHPUnit < 10 |
103 | | - */ |
104 | 100 | public function testGetFilesInfoInvalidFile(): void |
105 | 101 | { |
106 | | - $command = $this->getMockBuilder(TwigLintCommand::class) |
107 | | - ->onlyMethods(['getTemplateContents', 'findFiles']) |
108 | | - ->getMock(); |
109 | | - |
110 | | - $command->expects($this->exactly(1)) |
111 | | - ->method('findFiles') |
112 | | - ->willReturn( |
113 | | - [ |
114 | | - 'foo.twig', |
115 | | - 'foo-invalid.twig', |
116 | | - ] |
117 | | - ); |
118 | | - |
119 | | - $command->expects($this->exactly(2)) |
120 | | - ->method('getTemplateContents') |
121 | | - ->withConsecutive( |
122 | | - ['foo.twig'], |
123 | | - ['foo-invalid.twig'] |
124 | | - ) |
125 | | - ->willReturnOnConsecutiveCalls('{{ file }}', '{{ file }'); |
126 | | - |
127 | | - $filesFound = $this->callFunction($command, TwigLintCommand::class, 'getFilesInfo', [ |
128 | | - TEST_PATH . 'test/classes/_data/file_listing', |
129 | | - ]); |
130 | | - |
131 | | - self::assertEquals([ |
132 | | - [ |
133 | | - 'template' => '{{ file }}', |
134 | | - 'file' => 'foo.twig', |
135 | | - 'valid' => true, |
136 | | - ], |
137 | | - [ |
138 | | - 'template' => '{{ file }', |
139 | | - 'file' => 'foo-invalid.twig', |
140 | | - 'valid' => false, |
141 | | - 'line' => 1, |
142 | | - 'exception' => new SyntaxError('Unexpected "}".', 1, new Source( |
143 | | - '{{ file }', |
144 | | - 'foo-invalid.twig' |
145 | | - )), |
146 | | - ], |
147 | | - ], $filesFound); |
| 102 | + $twigLintCommand = new TwigLintCommand(); |
| 103 | + $path = __DIR__ . '/../_data/templates/lint_command'; |
| 104 | + $filesFound = $twigLintCommand->getFilesInfo($path); |
| 105 | + |
| 106 | + self::assertCount(2, $filesFound); |
| 107 | + self::assertSame('{{ file }' . "\n", $filesFound[0]['template']); |
| 108 | + self::assertSame($path . '/foo-invalid.twig', $filesFound[0]['file']); |
| 109 | + self::assertArrayHasKey('exception', $filesFound[0]); |
| 110 | + $exception = $filesFound[0]['exception']; |
| 111 | + self::assertInstanceOf(SyntaxError::class, $exception); |
| 112 | + self::assertSame('Unexpected "}" in "' . $path . '/foo-invalid.twig" at line 1.', $exception->getMessage()); |
| 113 | + self::assertSame('{{ file }}' . "\n", $filesFound[1]['template']); |
| 114 | + self::assertSame($path . '/foo-valid.twig', $filesFound[1]['file']); |
148 | 115 | } |
149 | 116 |
|
150 | 117 | public function testGetContext(): void |
|
0 commit comments