@@ -91,7 +91,7 @@ public function foreign($table, $column = 'id', $onUpdate = 'cascade', $onDelete
91
91
}
92
92
93
93
$ name = $ this ->getIndexName ('foreign ' );
94
- $ this ->context -> assertTrue ($ this ->table ->hasForeignKey ($ name ), "The foreign key {$ name } does not exist. " );
94
+ $ this ->assertTrue ($ this ->table ->hasForeignKey ($ name ), "The foreign key {$ name } does not exist. " );
95
95
96
96
$ key = $ this ->table ->getForeignKey ($ name );
97
97
$ onUpdate && $ this ->context ->assertEquals (strtoupper ($ onUpdate ), $ key ->onUpdate ());
@@ -154,9 +154,9 @@ public function exists()
154
154
*/
155
155
public function increments ()
156
156
{
157
- return $ this ->integer ()
158
- -> assertTrue ( $ this -> get ( ' autoincrement ' ), " The column { $ this -> name } is not auto-incremented. " )
159
- ->primary ();
157
+ $ message = " The column { $ this ->name } is not auto-incremented. " ;
158
+
159
+ return $ this -> integer ()-> assertTrue ( $ this -> get ( ' autoincrement ' ), $ message ) ->primary ();
160
160
}
161
161
162
162
/**
@@ -168,11 +168,11 @@ public function index()
168
168
{
169
169
$ index = $ this ->getIndexName ();
170
170
171
- $ this ->context -> assertTrue (
171
+ $ this ->assertTrue (
172
172
$ this ->table ->hasIndex ($ index ), "The {$ this ->name } column is not indexed. "
173
173
);
174
174
175
- $ this ->context -> assertTrue (
175
+ $ this ->assertTrue (
176
176
$ this ->table ->getIndex ($ index )->isSimpleIndex (), "The {$ this ->name } column is not a simple index. "
177
177
);
178
178
}
@@ -199,15 +199,11 @@ public function ofType($type)
199
199
public function primary ()
200
200
{
201
201
$ key = $ this ->tableHasPrimary ()->getPrimaryKey ();
202
+ $ message = "The column {$ this ->name } is not a primary key. " ;
202
203
203
- $ this ->context ->assertTrue (
204
- in_array ($ this ->name , $ key ->getColumns ()), "The column {$ this ->name } is not a primary key. "
205
- );
206
-
207
- $ this ->context ->assertTrue ($ key ->isPrimary ());
208
- $ this ->context ->assertTrue ($ key ->isUnique ());
209
-
210
- return $ this ;
204
+ return $ this ->assertTrue (in_array ($ this ->name , $ key ->getColumns ()), $ message )
205
+ ->assertTrue ($ key ->isPrimary ())
206
+ ->assertTrue ($ key ->isUnique ());
211
207
}
212
208
213
209
/**
@@ -238,12 +234,10 @@ public function __call($method, $args)
238
234
protected function assertNullable ($ negate = false )
239
235
{
240
236
if ($ negate ) {
241
- $ this ->context ->assertTrue ($ this ->get ('notnull ' ), "The table column ` {$ this ->name }` is nullable " );
242
- } else {
243
- $ this ->context ->assertFalse ($ this ->get ('notnull ' ), "The table column ` {$ this ->name }` is not nullable " );
237
+ return $ this ->assertTrue ($ this ->get ('notnull ' ), "The table column ` {$ this ->name }` is nullable " );
244
238
}
245
239
246
- return $ this ;
240
+ return $ this -> assertFalse ( $ this -> get ( ' notnull ' ), " The table column ` { $ this -> name } ` is not nullable " ) ;
247
241
}
248
242
249
243
/**
@@ -270,6 +264,20 @@ protected function assertColumn($method, $args)
270
264
throw new \Exception ("The database table column assertion {$ method } does not exist. " );
271
265
}
272
266
267
+ /**
268
+ * Assert a condition is false alias.
269
+ *
270
+ * @param bool $condition
271
+ * @param string $message
272
+ * @return $this
273
+ */
274
+ protected function assertFalse ($ condition , $ message )
275
+ {
276
+ $ this ->context ->assertFalse ($ condition , $ message );
277
+
278
+ return $ this ;
279
+ }
280
+
273
281
/**
274
282
* Assert a condition is true alias.
275
283
*
@@ -294,7 +302,7 @@ protected function assertTrue($condition, $message)
294
302
protected function assertUniqueIndex ($ key , $ indexes )
295
303
{
296
304
$ this ->context ->assertArrayHasKey ($ key , $ indexes , "The {$ this ->name } column is not indexed. " );
297
- $ this ->context -> assertTrue ($ indexes [$ key ]->isUnique (), "The {$ this ->name } is not a unique index. " );
305
+ $ this ->assertTrue ($ indexes [$ key ]->isUnique (), "The {$ this ->name } is not a unique index. " );
298
306
}
299
307
300
308
/**
@@ -316,7 +324,7 @@ protected function getIndexName($suffix = 'index')
316
324
*/
317
325
protected function tableHasPrimary ()
318
326
{
319
- $ this ->context -> assertTrue (
327
+ $ this ->assertTrue (
320
328
$ this ->table ->hasPrimaryKey (), "The table {$ this ->table ->getName ()} does not have a primary key. "
321
329
);
322
330
0 commit comments