1 | <?php |
||
16 | trait RefreshDatabase |
||
17 | { |
||
18 | /** |
||
19 | * Define hooks to migrate the database before and after each test. |
||
20 | * |
||
21 | * @return void |
||
22 | */ |
||
23 | public function refreshDatabase() |
||
29 | |||
30 | /** |
||
31 | * Determine if an in-memory database is being used. |
||
32 | * |
||
33 | * @return bool |
||
34 | */ |
||
35 | protected function usingInMemoryDatabase() |
||
41 | |||
42 | /** |
||
43 | * Refresh the in-memory database. |
||
44 | * |
||
45 | * @return void |
||
46 | */ |
||
47 | protected function refreshInMemoryDatabase() |
||
53 | |||
54 | /** |
||
55 | * Refresh a conventional test database. |
||
56 | * |
||
57 | * @return void |
||
58 | */ |
||
59 | protected function refreshTestDatabase() |
||
76 | |||
77 | /** |
||
78 | * Begin a database transaction on the testing database. |
||
79 | * |
||
80 | * @return void |
||
81 | */ |
||
82 | public function beginDatabaseTransaction() |
||
107 | |||
108 | /** |
||
109 | * The database connections that should have transactions. |
||
110 | * |
||
111 | * @return array |
||
112 | */ |
||
113 | protected function connectionsToTransact() |
||
118 | |||
119 | /** |
||
120 | * Determine if views should be dropped when refreshing the database. |
||
121 | * |
||
122 | * @return bool |
||
123 | */ |
||
124 | protected function shouldDropViews() |
||
129 | |||
130 | protected function swapTestingDatabase(): void |
||
146 | } |
||
147 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.