Reputation: 11
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
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
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