diff --git a/apps/web-twig-demo/docker/Dockerfile b/apps/web-twig-demo/docker/Dockerfile index f1a7a0991a..b28d81ec17 100644 --- a/apps/web-twig-demo/docker/Dockerfile +++ b/apps/web-twig-demo/docker/Dockerfile @@ -42,6 +42,7 @@ RUN set -eux; \ zip \ apcu \ opcache \ + tidy \ ; ###> recipes ### diff --git a/packages/web-twig/tests/ComponentSnapshotTest.php b/packages/web-twig/tests/ComponentSnapshotTest.php index 9ed80e84fc..64ab84b99a 100644 --- a/packages/web-twig/tests/ComponentSnapshotTest.php +++ b/packages/web-twig/tests/ComponentSnapshotTest.php @@ -29,6 +29,8 @@ public function test(string $template): void { $html = $this->twig->render($template); + $html = $this->formatHtml($html); + $this->assertMatchesHtmlSnapshot($html); } @@ -45,11 +47,29 @@ public function snapshotComponentsDataProvider(): array $dataToProvide = []; foreach ($scannedDirectory as $fileName) { - if (!is_dir(self::SNAPSHOT_SOURCES . '/' . $fileName)) { - $dataToProvide[(string) $fileName] = [(string) $fileName]; - } + if (! is_dir(self::SNAPSHOT_SOURCES . '/' . $fileName)) { + $dataToProvide[(string) $fileName] = [(string) $fileName]; + } } return $dataToProvide; } + + private function formatHtml(string $html): string + { + // Specify configuration + $config = [ + 'indent' => true, + 'output-xhtml' => true, + 'wrap' => 120, + ]; + + // Tidy + $tidy = new \tidy(); + $tidy->parseString($html, $config, 'utf8'); + $tidy->cleanRepair(); + + // Output + return $tidy->root()->value; + } }