Haj Mohamed
Haj Mohamed

Reputation: 11

How to Disable Laravel Php Unit Test in Production

In Laravel below 5.6 there is option to remote code execution, remote code execution run by the phpunit test to avoid that, i want to know how to remove on production

Upvotes: 1

Views: 1891

Answers (2)

Stanley Peters
Stanley Peters

Reputation: 3

I pushed Paul's solution a little further to prevent test execution if env is not pointing to the local_db Docker container. Which should also prevent execution in production. Multi-schema version. Prevents accidental refresh.

    protected function setUp(): void
    {
        parent::setUp();
        collect(['DB_HOST', 'DB2_HOST', 'DB3_HOST'])->each(function ($db) {
            if (env($db) !== 'local_db') {
                throw new \Exception( "$db Must use Local DB for testing!");
            }
        });
    }

Upvotes: 0

Kamlesh Paul
Kamlesh Paul

Reputation: 12391

If all your tests inherit from the base TestCase then you could always over-ride the setUp method Something like :

    protected function setUp()
    {
        parent::setUp();
        if (env('APP_ENV') !== 'testing') {
           throw new \Exception('Argh!');
        }
    }

Upvotes: 1

Related Questions