@@ -49,7 +49,10 @@ public function testWhitespaceIsPreservedCorrectly()
49
49
);
50
50
}
51
51
52
- public function testHandlerLogicWorksCorrectly ()
52
+ /**
53
+ * @dataProvider handlerLogicDataProvider
54
+ */
55
+ public function testHandlerLogicWorksCorrectly ($ blade )
53
56
{
54
57
$ this ->expectExceptionMessage ('The fluent object has been successfully handled! ' );
55
58
@@ -63,23 +66,41 @@ public function testHandlerLogicWorksCorrectly()
63
66
64
67
$ exampleObject = new Fluent ();
65
68
66
- eval (Str::of ($ this ->compiler ->compileString (' {{$exampleObject}} ' ))->remove (['<?php ' , '?> ' ]));
69
+ eval (Str::of ($ this ->compiler ->compileString ($ blade ))->remove (['<?php ' , '?> ' ]));
67
70
}
68
71
69
- public function testHandlerLogicWorksCorrectlyWithSemicolon ()
72
+ public function handlerLogicDataProvider ()
70
73
{
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
+ }
76
79
80
+ /**
81
+ * @dataProvider nonStringableDataProvider
82
+ */
83
+ public function testHandlerWorksWithNonStringables ($ blade , $ expectedOutput )
84
+ {
77
85
app ()->singleton ('blade.compiler ' , function () {
78
86
return $ this ->compiler ;
79
87
});
80
88
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 ();
82
94
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
+ ];
84
105
}
85
106
}
0 commit comments