@@ -17,15 +17,15 @@ trait InteractsWithDatabase
17
17
/**
18
18
* Assert that a given where condition exists in the database.
19
19
*
20
- * @param string $table
20
+ * @param \Illuminate\Database\Eloquent\Model| string $table
21
21
* @param array $data
22
22
* @param string|null $connection
23
23
* @return $this
24
24
*/
25
25
protected function assertDatabaseHas ($ table , array $ data , $ connection = null )
26
26
{
27
27
$ this ->assertThat (
28
- $ table , new HasInDatabase ($ this ->getConnection ($ connection ), $ data )
28
+ $ this -> getTable ( $ table) , new HasInDatabase ($ this ->getConnection ($ connection ), $ data )
29
29
);
30
30
31
31
return $ this ;
@@ -34,7 +34,7 @@ protected function assertDatabaseHas($table, array $data, $connection = null)
34
34
/**
35
35
* Assert that a given where condition does not exist in the database.
36
36
*
37
- * @param string $table
37
+ * @param \Illuminate\Database\Eloquent\Model| string $table
38
38
* @param array $data
39
39
* @param string|null $connection
40
40
* @return $this
@@ -45,23 +45,23 @@ protected function assertDatabaseMissing($table, array $data, $connection = null
45
45
new HasInDatabase ($ this ->getConnection ($ connection ), $ data )
46
46
);
47
47
48
- $ this ->assertThat ($ table , $ constraint );
48
+ $ this ->assertThat ($ this -> getTable ( $ table) , $ constraint );
49
49
50
50
return $ this ;
51
51
}
52
52
53
53
/**
54
54
* Assert the count of table entries.
55
55
*
56
- * @param string $table
56
+ * @param \Illuminate\Database\Eloquent\Model| string $table
57
57
* @param int $count
58
58
* @param string|null $connection
59
59
* @return $this
60
60
*/
61
61
protected function assertDatabaseCount ($ table , int $ count , $ connection = null )
62
62
{
63
63
$ this ->assertThat (
64
- $ table , new CountInDatabase ($ this ->getConnection ($ connection ), $ count )
64
+ $ this -> getTable ( $ table) , new CountInDatabase ($ this ->getConnection ($ connection ), $ count )
65
65
);
66
66
67
67
return $ this ;
@@ -81,7 +81,7 @@ protected function assertDeleted($table, array $data = [], $connection = null)
81
81
return $ this ->assertDatabaseMissing ($ table ->getTable (), [$ table ->getKeyName () => $ table ->getKey ()], $ table ->getConnectionName ());
82
82
}
83
83
84
- $ this ->assertDatabaseMissing ($ table , $ data , $ connection );
84
+ $ this ->assertDatabaseMissing ($ this -> getTable ( $ table) , $ data , $ connection );
85
85
86
86
return $ this ;
87
87
}
@@ -102,7 +102,7 @@ protected function assertSoftDeleted($table, array $data = [], $connection = nul
102
102
}
103
103
104
104
$ this ->assertThat (
105
- $ table , new SoftDeletedInDatabase ($ this ->getConnection ($ connection ), $ data , $ deletedAtColumn )
105
+ $ this -> getTable ( $ table) , new SoftDeletedInDatabase ($ this ->getConnection ($ connection ), $ data , $ deletedAtColumn )
106
106
);
107
107
108
108
return $ this ;
@@ -152,6 +152,17 @@ protected function getConnection($connection = null)
152
152
return $ database ->connection ($ connection );
153
153
}
154
154
155
+ /**
156
+ * Get the table name from the given model or string.
157
+ *
158
+ * @param \Illuminate\Database\Eloquent\Model|string $table
159
+ * @return string
160
+ */
161
+ protected function getTable ($ table )
162
+ {
163
+ return is_subclass_of ($ table , Model::class) ? (new $ table )->getTable () : $ table ;
164
+ }
165
+
155
166
/**
156
167
* Seed a given database connection.
157
168
*
0 commit comments