Last active
May 20, 2021 02:18
-
-
Save nissicreative/9d3c5451211b9e8552033368a98ee692 to your computer and use it in GitHub Desktop.
Laravel 5.7 Base Test Case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests; | |
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; | |
abstract class TestCase extends BaseTestCase | |
{ | |
use CreatesApplication; | |
public function __construct( ? string $name = null, array $data = [], string $dataName = '') | |
{ | |
parent::__construct($name, $data, $dataName); | |
$this->hotfixSqlite(); | |
} | |
public function signIn($user = null) | |
{ | |
$this->actingAs($user ?? factory(\App\User::class)->create()); | |
} | |
public function actingAsAdmin($level = 40) | |
{ | |
$this->actingAs(factory(\App\User::class)->create(['access_level' => $level])); | |
} | |
/** | |
* Allow "dropping" foreign keys in SQLite. | |
*/ | |
public function hotfixSqlite() | |
{ | |
\Illuminate\Database\Connection::resolverFor('sqlite', function ($connection, $database, $prefix, $config) { | |
return new class($connection, $database, $prefix, $config) extends \Illuminate\Database\SQLiteConnection | |
{ | |
public function getSchemaBuilder() | |
{ | |
if ($this->schemaGrammar === null) { | |
$this->useDefaultSchemaGrammar(); | |
} | |
return new class($this) extends \Illuminate\Database\Schema\SQLiteBuilder | |
{ | |
protected function createBlueprint($table, \Closure $callback = null) | |
{ | |
return new class($table, $callback) extends \Illuminate\Database\Schema\Blueprint | |
{ | |
public function dropForeign($index) | |
{ | |
return new \Illuminate\Support\Fluent(); | |
} | |
}; | |
} | |
}; | |
} | |
}; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment