Skip to content

Instantly share code, notes, and snippets.

@deleugpn
Last active October 13, 2017 21:33
Show Gist options
  • Select an option

  • Save deleugpn/ed996e19b38ae606d9a09f6613cca19d to your computer and use it in GitHub Desktop.

Select an option

Save deleugpn/ed996e19b38ae606d9a09f6613cca19d to your computer and use it in GitHub Desktop.
<?php
namespace Tests;
use Illuminate\Contracts\Console\Kernel;
use RuntimeException;
trait CreatesApplication
{
protected $allowedHosts = ['', '127.0.0.1', 'localhost'];
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
$this->protectDatabase();
return $app;
}
private function protectDatabase()
{
$host = config('database.connections.main.host');
if (! in_array($host, $this->allowedHosts)) {
throw new RuntimeException("$host not allowed. Please change your phpunit.xml setup.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment