diff --git a/tests/View/Blade/BladeEchoHandlerTest.php b/tests/View/Blade/BladeEchoHandlerTest.php index 00c143a58afc..a8eceb43d19d 100644 --- a/tests/View/Blade/BladeEchoHandlerTest.php +++ b/tests/View/Blade/BladeEchoHandlerTest.php @@ -49,7 +49,10 @@ public function testWhitespaceIsPreservedCorrectly() ); } - public function testHandlerLogicWorksCorrectly() + /** + * @dataProvider handlerLogicDataProvider + */ + public function testHandlerLogicWorksCorrectly($blade) { $this->expectExceptionMessage('The fluent object has been successfully handled!'); @@ -63,23 +66,41 @@ public function testHandlerLogicWorksCorrectly() $exampleObject = new Fluent(); - eval(Str::of($this->compiler->compileString('{{$exampleObject}}'))->remove([''])); + eval(Str::of($this->compiler->compileString($blade))->remove([''])); } - public function testHandlerLogicWorksCorrectlyWithSemicolon() + public function handlerLogicDataProvider() { - $this->expectExceptionMessage('The fluent object has been successfully handled!'); - - $this->compiler->stringable(Fluent::class, function ($object) { - throw new Exception('The fluent object has been successfully handled!'); - }); + return [ + ['{{$exampleObject}}'], + ['{{$exampleObject;}}'], + ]; + } + /** + * @dataProvider nonStringableDataProvider + */ + public function testHandlerWorksWithNonStringables($blade, $expectedOutput) + { app()->singleton('blade.compiler', function () { return $this->compiler; }); - $exampleObject = new Fluent(); + // We output to the buffer to avoid outputting in the test console. + ob_start(); + eval(Str::of($this->compiler->compileString($blade))->remove([''])); + $output = ob_get_contents(); + ob_end_clean(); - eval(Str::of($this->compiler->compileString('{{$exampleObject;}}'))->remove([''])); + $this->assertSame($expectedOutput, $output); + } + + public function nonStringableDataProvider() + { + return [ + ['{{"foo" . "bar"}}', 'foobar'], + ['{{ 1 + 2 }}{{ "test"; }}', '3test'], + ['@php($test = "hi"){{ $test }}', 'hi'] + ]; } }