Skip to content

Instantly share code, notes, and snippets.

@Uplink03
Created November 21, 2023 15:48
Show Gist options
  • Save Uplink03/6f52ece5c18dc12331a65c60bf95ae36 to your computer and use it in GitHub Desktop.
Save Uplink03/6f52ece5c18dc12331a65c60bf95ae36 to your computer and use it in GitHub Desktop.
Refresh the damned database
<?php
// File path in Laravel project: `tests/RefreshTheDamnedDatabase.php`
declare(strict_types=1);
namespace Tests;
/**
* Quick and dirty database refresh for tests
*
* Reason:
* - RefreshDatabase uses transactions. That's no bueno when I'm also using transactions.
* - DatabaseTruncation exploded spectacularly with this beautiful error:
* ```
* Class "Doctrine\DBAL\Driver\AbstractMySQLDriver" not found
* ```
*/
trait RefreshTheDamnedDatabase
{
public function refreshTheDamnedDatabase(): void
{
$this->artisan('db:wipe');
$this->artisan('migrate --step --seed');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment