Guard against wiping database when running tests and test specific envs are not created

This commit is contained in:
Marcus Moore 2023-07-11 12:14:42 -07:00
parent 4845a88c68
commit 48e4ec8cf5
No known key found for this signature in database
3 changed files with 17 additions and 1 deletions

View file

@ -23,7 +23,9 @@ pipeline:
- name: Setup - name: Setup
cmd: | cmd: |
cp -v .env.example .env 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 composer install --no-interaction --prefer-dist --optimize-autoloader
- name: Generate Key - name: Generate Key

View file

@ -7,6 +7,7 @@ use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver; use Facebook\WebDriver\Remote\RemoteWebDriver;
use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\TestCase as BaseTestCase; use Laravel\Dusk\TestCase as BaseTestCase;
use RuntimeException;
abstract class DuskTestCase extends BaseTestCase abstract class DuskTestCase extends BaseTestCase
{ {
@ -21,6 +22,12 @@ abstract class DuskTestCase extends BaseTestCase
*/ */
public static function prepare() 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()) { if (! static::runningInSail()) {
static::startChromeDriver(); static::startChromeDriver();
} }

View file

@ -5,6 +5,7 @@ namespace Tests;
use App\Http\Middleware\SecurityHeaders; use App\Http\Middleware\SecurityHeaders;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use RuntimeException;
use Tests\Support\CustomTestMacros; use Tests\Support\CustomTestMacros;
use Tests\Support\InteractsWithAuthentication; use Tests\Support\InteractsWithAuthentication;
use Tests\Support\InteractsWithSettings; use Tests\Support\InteractsWithSettings;
@ -22,6 +23,12 @@ abstract class TestCase extends BaseTestCase
protected function setUp(): void 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(); parent::setUp();
$this->withoutMiddleware($this->globallyDisabledMiddleware); $this->withoutMiddleware($this->globallyDisabledMiddleware);