-
Notifications
You must be signed in to change notification settings - Fork 42
/
TestCase.php
111 lines (91 loc) · 3.19 KB
/
TestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
namespace MagicLink\Test;
use Illuminate\Database\Schema\Blueprint;
use MagicLink\MagicLinkServiceProvider;
use MagicLink\Test\TestSupport\User;
use Orchestra\Testbench\TestCase as Orchestra;
abstract class TestCase extends Orchestra
{
public function setUp(): void
{
parent::setUp();
$this->setUpDatabase($this->app);
}
/**
* @param \Illuminate\Foundation\Application $app
* @return array
*/
protected function getPackageProviders($app)
{
return [
MagicLinkServiceProvider::class,
];
}
/**
* Set up the environment.
*
* @param \Illuminate\Foundation\Application $app
*/
protected function getEnvironmentSetUp($app)
{
$app['config']->set('app.key', 'base64:mJlbzP1TMXUPouK3KK6e9zS/VvxtWTfzfVlkn1JTqpM=');
$app['config']->set('auth.providers.users.model', 'MagicLink\Test\TestSupport\User');
$app['config']->set('view.paths', [__DIR__.'/stubs/resources/views']);
$app['config']->set('filesystems.disks.local.root', __DIR__.'/stubs/storage/app');
$app['config']->set('filesystems.disks.alternative', [
'driver' => 'local',
'root' => __DIR__.'/stubs/storage/app_alternative',
]);
$app['config']->set('database.connections.sqlite', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
]);
$app['config']->set('database.connections.pgsql', [
'driver' => 'pgsql',
'host' => '127.0.0.1',
'port' => '54320',
'username' => 'postgres',
'password' => 'mysecretpassword',
'database' => 'test',
]);
$app['config']->set('database.connections.mysql', [
'driver' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
'username' => 'root',
'password' => '',
'database' => 'test',
]);
$app['config']->set('database.default', 'sqlite');
if (getenv('DB_DRIVER') === 'pgsql') {
$app['config']->set('database.default', 'pgsql');
} elseif (getenv('DB_DRIVER') === 'mysql') {
$app['config']->set('database.default', 'mysql');
}
}
/**
* Set up the database.
*
* @param \Illuminate\Foundation\Application $app
*/
protected function setUpDatabase($app)
{
if ($app['config']->get('database.default') !== 'sqlite') {
$app['db']->connection()->getSchemaBuilder()->dropIfExists('users');
$app['db']->connection()->getSchemaBuilder()->dropIfExists('migrations');
$app['db']->connection()->getSchemaBuilder()->dropIfExists('magic_links');
}
$this->artisan('migrate');
$app['db']->connection()->getSchemaBuilder()->create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('email');
});
User::create(['email' => '[email protected]']);
}
protected function loadRoutes()
{
include __DIR__.'/stubs/routes.php';
}
}