Merge pull request #13292 from marcusmoore/guard-against-wiping-local-db

Avoid accidentally wiping local database when running tests
This commit is contained in:
snipe 2023-07-12 15:23:11 +01:00 committed by GitHub
commit 1b8b117f4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View file

@ -21,7 +21,9 @@ pipeline:
- name: Setup
cmd: |
cp -v .env.example .env
# This is simply to allow passing the guard in TestCase@setUp()
# https://chipperci.com/docs/builds/env
touch .env.testing
composer install --no-interaction --prefer-dist --optimize-autoloader
- name: Generate Key

View file

@ -7,6 +7,7 @@ use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\TestCase as BaseTestCase;
use RuntimeException;
abstract class DuskTestCase extends BaseTestCase
{
@ -21,6 +22,12 @@ abstract class DuskTestCase extends BaseTestCase
*/
public static function prepare()
{
if (!file_exists(realpath(__DIR__ . '/../') . '/.env.dusk.local')) {
throw new RuntimeException(
'.env.dusk.local file does not exist. Aborting to avoid wiping your local database'
);
}
if (! static::runningInSail()) {
static::startChromeDriver();
}

View file

@ -5,6 +5,7 @@ namespace Tests;
use App\Http\Middleware\SecurityHeaders;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use RuntimeException;
use Tests\Support\CustomTestMacros;
use Tests\Support\InteractsWithAuthentication;
use Tests\Support\InteractsWithSettings;
@ -22,6 +23,12 @@ abstract class TestCase extends BaseTestCase
protected function setUp(): void
{
if (!file_exists(realpath(__DIR__ . '/../') . '/.env.testing')) {
throw new RuntimeException(
'.env.testing file does not exist. Aborting to avoid wiping your local database'
);
}
parent::setUp();
$this->withoutMiddleware($this->globallyDisabledMiddleware);