5. views can repass props

580-view-class-steroids
fadrian06 1 day ago
parent 538c9d32ae
commit 38d4458e96

@ -235,11 +235,14 @@ class ViewTest extends TestCase
} }
/** @dataProvider pagesDataProvider */ /** @dataProvider pagesDataProvider */
public function testItRendersComponent(string $page, string $expected): void public function testItRendersComponent(
{ string $page,
string $expected,
array $props = []
): void {
$view = new View(__DIR__ . '/views'); $view = new View(__DIR__ . '/views');
$view->preserveVars = false; $view->preserveVars = false;
$actual = $view->fetch("pages/$page"); $actual = $view->fetch("pages/$page", $props);
self::assertSame( self::assertSame(
self::removeIndentation(self::removeLineEndings($expected)), self::removeIndentation(self::removeLineEndings($expected)),
@ -329,7 +332,20 @@ class ViewTest extends TestCase
</body> </body>
</html> </html>
html, html,
['name' => 'James'],
],
[
'page-with-component-with-one-prop',
<<<'html'
<html>
<body>
<h1>Hello, Victoria</h1>
</body>
</html>
html,
['name' => 'Victoria'],
], ],
]; ];
} }

@ -1,5 +1,5 @@
<html> <html>
<body> <body>
<f-greeting name="James" /> <f-greeting name="<?= $name ?>" />
</body> </body>
</html> </html>
Loading…
Cancel
Save