| 1 | <?php |
||
| 7 | trait UsesDatabase |
||
| 8 | { |
||
| 9 | /** @var string */ |
||
| 10 | protected $database = __DIR__.'/../database/testing.sqlite'; |
||
| 11 | |||
| 12 | /** @var bool */ |
||
| 13 | protected static $migrated = false; |
||
| 14 | |||
| 15 | public function prepareDatabase() |
||
| 16 | { |
||
| 17 | // The database needs to be deleted before the application gets boted |
||
| 18 | // to avoid having the database in a weird read-only state. |
||
| 19 | |||
| 20 | if (static::$migrated) { |
||
| 21 | return; |
||
| 22 | } |
||
| 23 | |||
| 24 | @unlink($this->database); |
||
|
|
|||
| 25 | touch($this->database); |
||
| 26 | } |
||
| 27 | |||
| 28 | public function setUpDatabase(callable $afterMigrations = null) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Handle database transactions on the specified connections. |
||
| 47 | * |
||
| 48 | * @return void |
||
| 49 | */ |
||
| 50 | public function beginDatabaseTransaction() |
||
| 64 | |||
| 65 | /** |
||
| 66 | * The database connections that should have transactions. |
||
| 67 | * |
||
| 68 | * @return array |
||
| 69 | */ |
||
| 70 | protected function connectionsToTransact() |
||
| 75 | } |
||
| 76 |
If you suppress an error, we recommend checking for the error condition explicitly: