Skip to content

Commit 5fd4d26

Browse files
committed
minor #122 Using a Twig CS tool to verify our generated Twig code (weaverryan)
This PR was merged into the 1.0-dev branch. Discussion ---------- Using a Twig CS tool to verify our generated Twig code A simple way to help make sure we generate decent code - it will help #113, which has a few violations ;). Commits ------- 2214434 Using a Twig CS tool to verify our generated Twig code
2 parents 0ae2474 + 2214434 commit 5fd4d26

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"symfony/http-kernel": "^3.4|^4.0"
2222
},
2323
"require-dev": {
24+
"allocine/twigcs": "^3.0",
2425
"friendsofphp/php-cs-fixer": "^2.8",
2526
"symfony/phpunit-bridge": "^3.4|^4.0",
2627
"symfony/process": "^3.4|^4.0"

src/Test/MakerTestCase.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function executeMakerCommand(MakerTestDetails $testDetails)
9292
throw new \Exception(sprintf('Running maker command failed: "%s" "%s"', $makerProcess->getOutput(), $makerProcess->getErrorOutput()));
9393
}
9494

95-
$files = $this->getGeneratedPhpFilesFromOutputText($makerProcess->getOutput());
95+
$files = $this->getGeneratedFilesFromOutputText($makerProcess->getOutput(), '.php');
9696
foreach ($files as $file) {
9797
$process = $this->createProcess(
9898
sprintf(
@@ -106,6 +106,19 @@ protected function executeMakerCommand(MakerTestDetails $testDetails)
106106
$this->assertTrue($process->isSuccessful(), sprintf('File "%s" has a php-cs problem: %s', $file, $process->getOutput()));
107107
}
108108

109+
$files = $this->getGeneratedFilesFromOutputText($makerProcess->getOutput(), '.twig');
110+
foreach ($files as $file) {
111+
$process = $this->createProcess(
112+
sprintf(
113+
'php vendor/bin/twigcs lint %s',
114+
self::$currentRootDir.'/'.$file
115+
),
116+
__DIR__.'/../../'
117+
);
118+
$process->run();
119+
$this->assertTrue($process->isSuccessful(), sprintf('File "%s" has a php-cs problem: %s', $file, $process->getOutput()));
120+
}
121+
109122
foreach ($testDetails->getPostMakeCommands() as $postCommand) {
110123
$process = $this->createProcess($postCommand, self::$currentRootDir);
111124
$process->run();
@@ -165,7 +178,7 @@ private function buildFlexProject()
165178
$this->runProcess($process);
166179
}
167180

168-
private function getGeneratedPhpFilesFromOutputText($output)
181+
private function getGeneratedFilesFromOutputText($output, $fileExtension)
169182
{
170183
$files = [];
171184
foreach (explode("\n", $output) as $line) {
@@ -174,7 +187,10 @@ private function getGeneratedPhpFilesFromOutputText($output)
174187
}
175188

176189
list(, $filename) = explode(':', $line);
177-
$files[] = trim($filename);
190+
$filename = trim($filename);
191+
if ($fileExtension === substr($filename, (-1 * strlen($fileExtension)))) {
192+
$files[] = trim($filename);
193+
}
178194
}
179195

180196
return $files;

0 commit comments

Comments
 (0)