-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathTestCase.php
97 lines (78 loc) · 2.06 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
<?php
namespace Studio\Totem\Tests;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Support\Facades\Auth;
use Orchestra\Testbench\Exceptions\Handler;
use Studio\Totem\Providers\TotemServiceProvider;
use Studio\Totem\Totem;
use Studio\Totem\User;
use Throwable;
class TestCase extends \Orchestra\Testbench\TestCase
{
public function setUp(): void
{
parent::setUp();
$this->artisan('migrate', ['--database' => 'testing']);
$this->artisan('totem:assets');
$this->loadLaravelMigrations(['--database' => 'testing']);
$auth = function () {
switch (app()->environment()) {
case 'local':
return true;
break;
case 'testing':
return Auth::check();
break;
default:
return false;
}
};
Totem::auth($auth);
}
protected function getEnvironmentSetUp($app)
{
$app['config']->set('database.default', 'testing');
$app['config']->set('database.connections.testing', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
}
protected function getPackageProviders($app)
{
return [
TotemServiceProvider::class,
];
}
/**
* Disable Exception Handling.
*/
protected function disableExceptionHandling()
{
$this->app->instance(ExceptionHandler::class, new class() extends Handler
{
public function __construct()
{
}
public function report(Throwable $e)
{
}
public function render($request, Throwable $e)
{
throw $e;
}
});
return $this;
}
/**
* Creates and signs in a user.
*
* @return $this
*/
public function signIn()
{
$user = User::factory()->create();
$this->actingAs($user);
return $this;
}
}