-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathTestCase.php
127 lines (109 loc) · 3.28 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
namespace Rennokki\QueryCache\Test;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Orchestra\Testbench\TestCase as Orchestra;
abstract class TestCase extends Orchestra
{
/**
* {@inheritdoc}
*/
public function setUp(): void
{
parent::setUp();
if (method_exists($this, 'getProvidedData')
&& $this->getProvidedData()
&& method_exists(Model::class, 'preventAccessingMissingAttributes')
) {
[$strict] = $this->getProvidedData();
Model::preventAccessingMissingAttributes($strict);
}
$this->resetDatabase();
$this->clearCache();
$this->loadLaravelMigrations(['--database' => 'sqlite']);
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
$this->loadMigrationsFrom(__DIR__.'/database/migrations');
$this->withFactories(__DIR__.'/database/factories');
$this->artisan('migrate', ['--database' => 'sqlite']);
}
/**
* {@inheritdoc}
*/
protected function getPackageProviders($app)
{
return [
\Livewire\LivewireServiceProvider::class,
];
}
/**
* {@inheritdoc}
*/
public function getEnvironmentSetUp($app)
{
$app['config']->set('database.default', 'sqlite');
$app['config']->set('database.connections.sqlite', [
'driver' => 'sqlite',
'database' => __DIR__.'/database/database.sqlite',
'prefix' => '',
]);
$app['config']->set(
'cache.driver',
getenv('CACHE_DRIVER') ?: env('CACHE_DRIVER', 'array')
);
$app['config']->set('auth.providers.users.model', User::class);
$app['config']->set('auth.providers.posts.model', Post::class);
$app['config']->set('auth.providers.kids.model', Kid::class);
$app['config']->set('auth.providers.books.model', Book::class);
$app['config']->set('auth.providers.pages.model', Page::class);
$app['config']->set('app.key', 'wslxrEFGWY6GfGhvN9L3wH3KSRJQQpBD');
$app['config']->set('view.paths', [
__DIR__.'/views',
]);
$app['config']->set('livewire.view_path', __DIR__.'/views/livewire');
}
/**
* Reset the database.
*
* @return void
*/
protected function resetDatabase()
{
file_put_contents(__DIR__.'/database/database.sqlite', null);
}
/**
* Clear the cache.
*
* @return void
*/
protected function clearCache()
{
$this->artisan('cache:clear');
}
/**
* Get the cache with tags, if the driver supports it.
*
* @param string $key
* @param array|null $tags
* @return mixed
*/
protected function getCacheWithTags(string $key, ?array $tags = null)
{
return $this->driverSupportsTags()
? Cache::tags($tags)->get($key)
: Cache::get($key);
}
public static function strictModeContextProvider(): iterable
{
yield [true];
yield [false];
}
/**
* Check if the current driver supports tags.
*
* @return bool
*/
protected function driverSupportsTags(): bool
{
return ! in_array(config('cache.driver'), ['file', 'database']);
}
}