@@ -132,7 +132,9 @@ public function testBasicTableWrapping()
132
132
133
133
public function testWhenCallback ()
134
134
{
135
- $ callback = function ($ query ) {
135
+ $ callback = function ($ query , $ condition ) {
136
+ $ this ->assertTrue ($ condition );
137
+
136
138
return $ query ->where ('id ' , '= ' , 1 );
137
139
};
138
140
@@ -147,16 +149,20 @@ public function testWhenCallback()
147
149
148
150
public function testWhenCallbackWithDefault ()
149
151
{
150
- $ callback = function ($ query ) {
152
+ $ callback = function ($ query , $ condition ) {
153
+ $ this ->assertEquals ('truthy ' );
154
+
151
155
return $ query ->where ('id ' , '= ' , 1 );
152
156
};
153
157
154
- $ default = function ($ query ) {
158
+ $ default = function ($ query , $ condition ) {
159
+ $ this ->assertFalse ($ condition );
160
+
155
161
return $ query ->where ('id ' , '= ' , 2 );
156
162
};
157
163
158
164
$ builder = $ this ->getBuilder ();
159
- $ builder ->select ('* ' )->from ('users ' )->when (true , $ callback , $ default )->where ('email ' , 'foo ' );
165
+ $ builder ->select ('* ' )->from ('users ' )->when (' truthy ' , $ callback , $ default )->where ('email ' , 'foo ' );
160
166
$ this ->assertEquals ('select * from "users" where "id" = ? and "email" = ? ' , $ builder ->toSql ());
161
167
$ this ->assertEquals ([0 => 1 , 1 => 'foo ' ], $ builder ->getBindings ());
162
168
0 commit comments