Skip to content

Commit 0e542b4

Browse files
lukeraymonddowningtaylorotwell
authored andcommitted
Adds more test cases.
1 parent b8c1532 commit 0e542b4

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

tests/View/Blade/BladeEchoHandlerTest.php

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public function testWhitespaceIsPreservedCorrectly()
4949
);
5050
}
5151

52-
public function testHandlerLogicWorksCorrectly()
52+
/**
53+
* @dataProvider handlerLogicDataProvider
54+
*/
55+
public function testHandlerLogicWorksCorrectly($blade)
5356
{
5457
$this->expectExceptionMessage('The fluent object has been successfully handled!');
5558

@@ -63,23 +66,41 @@ public function testHandlerLogicWorksCorrectly()
6366

6467
$exampleObject = new Fluent();
6568

66-
eval(Str::of($this->compiler->compileString('{{$exampleObject}}'))->remove(['<?php', '?>']));
69+
eval(Str::of($this->compiler->compileString($blade))->remove(['<?php', '?>']));
6770
}
6871

69-
public function testHandlerLogicWorksCorrectlyWithSemicolon()
72+
public function handlerLogicDataProvider()
7073
{
71-
$this->expectExceptionMessage('The fluent object has been successfully handled!');
72-
73-
$this->compiler->stringable(Fluent::class, function ($object) {
74-
throw new Exception('The fluent object has been successfully handled!');
75-
});
74+
return [
75+
['{{$exampleObject}}'],
76+
['{{$exampleObject;}}'],
77+
];
78+
}
7679

80+
/**
81+
* @dataProvider nonStringableDataProvider
82+
*/
83+
public function testHandlerWorksWithNonStringables($blade, $expectedOutput)
84+
{
7785
app()->singleton('blade.compiler', function () {
7886
return $this->compiler;
7987
});
8088

81-
$exampleObject = new Fluent();
89+
// We output to the buffer to avoid outputting in the test console.
90+
ob_start();
91+
eval(Str::of($this->compiler->compileString($blade))->remove(['<?php', '?>']));
92+
$output = ob_get_contents();
93+
ob_end_clean();
8294

83-
eval(Str::of($this->compiler->compileString('{{$exampleObject;}}'))->remove(['<?php', '?>']));
95+
$this->assertSame($expectedOutput, $output);
96+
}
97+
98+
public function nonStringableDataProvider()
99+
{
100+
return [
101+
['{{"foo" . "bar"}}', 'foobar'],
102+
['{{ 1 + 2 }}{{ "test"; }}', '3test'],
103+
['@php($test = "hi"){{ $test }}', 'hi']
104+
];
84105
}
85106
}

0 commit comments

Comments
 (0)