@@ -11,6 +11,131 @@ public function testPhpStatementsWithExpressionAreCompiled()
11
11
$ this ->assertEquals ($ expected , $ this ->compiler ->compileString ($ string ));
12
12
}
13
13
14
+ public function testMixedPhpStatementsAreCompiled ()
15
+ {
16
+ $ string = <<<'BLADE'
17
+ @php($set = true)
18
+ @php($set = true) @php ($set = false;) @endphp
19
+ @php ($set = true) @php($set = false;)@endphp
20
+ <div>{{ $set }}</div>
21
+ @php
22
+ $set = false;
23
+ @endphp
24
+ @php (
25
+ $set = false;
26
+ )@endphp
27
+ @php(
28
+ $set = false;
29
+ )@endphp
30
+ @php (
31
+ $set = false
32
+ )
33
+ @php(
34
+ $set = false
35
+ )
36
+ @php
37
+ $set = '@@php';
38
+ @endphp
39
+ BLADE;
40
+ $ expected = <<<'PHP'
41
+ <?php ($set = true); ?>
42
+ <?php ($set = true); ?> <?php ($set = false;) ?>
43
+ <?php ($set = true); ?> <?php($set = false;)?>
44
+ <div><?php echo e($set); ?></div>
45
+ <?php
46
+ $set = false;
47
+ ?>
48
+ <?php (
49
+ $set = false;
50
+ )?>
51
+ <?php(
52
+ $set = false;
53
+ )?>
54
+ <?php (
55
+ $set = false
56
+ ); ?>
57
+ <?php (
58
+ $set = false
59
+ ); ?>
60
+ <?php
61
+ $set = '@@php';
62
+ ?>
63
+ PHP;
64
+ $ this ->assertEquals ($ expected , $ this ->compiler ->compileString ($ string ));
65
+ }
66
+
67
+ public function testCompilationOfMixedPhpStatements ()
68
+ {
69
+ $ string = '@php($set = true) @php ($hello = \'hi \') @php echo "Hello world" @endphp ' ;
70
+ $ expected = '<?php ($set = true); ?> <?php ($hello = \'hi \'); ?> <?php echo "Hello world" ?> ' ;
71
+
72
+ $ this ->assertEquals ($ expected , $ this ->compiler ->compileString ($ string ));
73
+ }
74
+
75
+ public function testCompilationOfMixedUsageStatements ()
76
+ {
77
+ $ string = '@php (
78
+ $classes = [
79
+ \'admin-font-mono \', // Font weight
80
+ ])
81
+ @endphp ' ;
82
+ $ expected = '<?php (
83
+ $classes = [
84
+ \'admin-font-mono \', // Font weight
85
+ ])
86
+ ?> ' ;
87
+
88
+ $ this ->assertEquals ($ expected , $ this ->compiler ->compileString ($ string ));
89
+ }
90
+
91
+ public function testMultilinePhpStatementsWithParenthesesCanBeCompiled ()
92
+ {
93
+ $ string = <<<'BLADE'
94
+ @php (
95
+ $classes = [
96
+ 'admin-font-mono'
97
+ ])
98
+ @endphp
99
+
100
+ <span class="{{ implode(' ', $classes) }}">Laravel</span>
101
+ BLADE;
102
+
103
+ $ expected = <<<'PHP'
104
+ <?php (
105
+ $classes = [
106
+ 'admin-font-mono'
107
+ ])
108
+ ?>
109
+
110
+ <span class="<?php echo e(implode(' ', $classes)); ?>">Laravel</span>
111
+ PHP;
112
+
113
+ $ this ->assertEquals ($ expected , $ this ->compiler ->compileString ($ string ));
114
+ }
115
+
116
+ public function testMixedOfPhpStatementsCanBeCompiled ()
117
+ {
118
+ $ string = <<<'BLADE'
119
+ @php($total = 0)
120
+ {{-- ... --}}
121
+ <div>{{ $total }}</div>
122
+ @php
123
+ // ...
124
+ @endphp
125
+ BLADE;
126
+
127
+ $ expected = <<<'PHP'
128
+ <?php ($total = 0); ?>
129
+
130
+ <div><?php echo e($total); ?></div>
131
+ <?php
132
+ // ...
133
+ ?>
134
+ PHP;
135
+
136
+ $ this ->assertEquals ($ expected , $ this ->compiler ->compileString ($ string ));
137
+ }
138
+
14
139
public function testStringWithParenthesisWithEndPHP ()
15
140
{
16
141
$ string = "@php( \$data = ['related_to' => 'issue#45388'];) {{ \$data }} @endphp " ;
0 commit comments