Skip to content

A free open source IT asset/license management system

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

Marcus Moore48e4ec8cf5d4
diff --git a/.chipperci.yml b/.chipperci.yml
index 999737ce98..68d6f00c58 100644
--- a/.chipperci.yml
+++ b/.chipperci.yml
@@ -23,7 +23,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
diff --git a/tests/DuskTestCase.php b/tests/DuskTestCase.php
index e591a7c771..af46d0e3dc 100644
--- a/tests/DuskTestCase.php
+++ b/tests/DuskTestCase.php
@@ -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();
}
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 30237f3171..03f273ad6f 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -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);