diff --git a/tests/FlightTest.php b/tests/FlightTest.php index f9f2855..5d196d6 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -356,26 +356,42 @@ class FlightTest extends TestCase $this->expectOutputString('Thisisaroutewithhtml'); } - public function testDoesNotPreserveVarsWhenFlagIsDisabled(): void + /** @dataProvider \tests\ViewTest::renderDataProvider */ + public function testDoesNotPreserveVarsWhenFlagIsDisabled( + string $output, + array $renderParams, + string $regexp + ): void { Flight::view()->preserveVars = false; - $this->expectOutputString("
Hi
\n
\n"); - Flight::render('myComponent', ['prop' => 'Hi']); + $this->expectOutputString($output); + Flight::render(...$renderParams); - set_error_handler(function (int $code, string $message): void { - $this->assertMatchesRegularExpression('/^Undefined variable:? \$?prop$/', $message); + set_error_handler(function (int $code, string $message) use ($regexp): void { + $this->assertMatchesRegularExpression($regexp, $message); }); - Flight::render('myComponent'); + Flight::render($renderParams[0]); restore_error_handler(); } public function testKeepThePreviousStateOfOneViewComponentByDefault(): void { - $this->expectOutputString("
Hi
\n
Hi
\n"); + $this->expectOutputString(<<Hi +
Hi
+ + + + + + html); + Flight::render('myComponent', ['prop' => 'Hi']); Flight::render('myComponent'); + Flight::render('input', ['type' => 'number']); + Flight::render('input'); } } diff --git a/tests/ViewTest.php b/tests/ViewTest.php index 361bb3c..38cabe0 100644 --- a/tests/ViewTest.php +++ b/tests/ViewTest.php @@ -153,26 +153,67 @@ class ViewTest extends TestCase ); } - public function testDoesNotPreserveVarsWhenFlagIsDisabled(): void - { + /** @dataProvider renderDataProvider */ + public function testDoesNotPreserveVarsWhenFlagIsDisabled( + string $output, + array $renderParams, + string $regexp + ): void { $this->view->preserveVars = false; - $this->expectOutputString("
Hi
\n
\n"); - $this->view->render('myComponent', ['prop' => 'Hi']); + $this->expectOutputString($output); + $this->view->render(...$renderParams); - set_error_handler(function (int $code, string $message): void { - $this->assertMatchesRegularExpression('/^Undefined variable:? \$?prop$/', $message); + set_error_handler(function (int $code, string $message) use ($regexp): void { + $this->assertMatchesRegularExpression($regexp, $message); }); - $this->view->render('myComponent'); + $this->view->render($renderParams[0]); restore_error_handler(); } public function testKeepThePreviousStateOfOneViewComponentByDefault(): void { - $this->expectOutputString("
Hi
\n
Hi
\n"); + $this->expectOutputString(<<Hi +
Hi
+ + + + + + html); + $this->view->render('myComponent', ['prop' => 'Hi']); $this->view->render('myComponent'); + $this->view->render('input', ['type' => 'number']); + $this->view->render('input'); + } + + public static function renderDataProvider(): array + { + return [ + [ + <<Hi +
+ + html, + ['myComponent', ['prop' => 'Hi']], + '/^Undefined variable:? \$?prop$/' + ], + [ + << + + + + html, + ['input', ['type' => 'number']], + '/^.*$/' + ], + ]; } } diff --git a/tests/views/input.php b/tests/views/input.php new file mode 100644 index 0000000..19e7182 --- /dev/null +++ b/tests/views/input.php @@ -0,0 +1,7 @@ + + +