1
|
|
|
<?php namespace GeneaLabs\LaravelModelCaching\Tests; |
2
|
|
|
|
3
|
|
|
use GeneaLabs\LaravelModelCaching\Providers\Service as LaravelModelCachingService; |
4
|
|
|
use Illuminate\Auth\Middleware\Authenticate; |
5
|
|
|
use Illuminate\Support\Facades\Artisan; |
6
|
|
|
use Laravel\Nova\Http\Middleware\Authorize; |
7
|
|
|
use Laravel\Nova\Http\Middleware\BootTools; |
8
|
|
|
use Laravel\Nova\Http\Middleware\DispatchServingNovaEvent; |
9
|
|
|
|
10
|
|
|
trait CreatesApplication |
11
|
|
|
{ |
12
|
|
|
private static $baseLineDatabaseMigrated = false; |
13
|
|
|
|
14
|
|
|
protected $cache; |
15
|
|
|
protected $testingSqlitePath; |
16
|
|
|
|
17
|
|
|
protected function cache() |
18
|
|
|
{ |
19
|
|
|
$cache = app('cache'); |
20
|
|
|
|
21
|
|
|
if (config('laravel-model-caching.store')) { |
22
|
|
|
$cache = $cache->store(config('laravel-model-caching.store')); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
return $cache; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function setUp() : void |
29
|
|
|
{ |
30
|
|
|
parent::setUp(); |
31
|
|
|
|
32
|
|
|
$this->setUpBaseLineSqlLiteDatabase(); |
33
|
|
|
|
34
|
|
|
$databasePath = __DIR__ . "/database"; |
35
|
|
|
$this->testingSqlitePath = "{$databasePath}/"; |
36
|
|
|
$baselinePath = "{$databasePath}/baseline.sqlite"; |
37
|
|
|
$testingPath = "{$databasePath}/testing.sqlite"; |
38
|
|
|
|
39
|
|
|
! file_exists($testingPath) |
40
|
|
|
?: unlink($testingPath); |
41
|
|
|
copy($baselinePath, $testingPath); |
42
|
|
|
|
43
|
|
|
require(__DIR__ . '/routes/web.php'); |
44
|
|
|
|
45
|
|
|
$this->withFactories(__DIR__ . '/database/factories'); |
|
|
|
|
46
|
|
|
|
47
|
|
|
view()->addLocation(__DIR__ . '/resources/views', 'laravel-model-caching'); |
48
|
|
|
|
49
|
|
|
$this->cache = app('cache') |
50
|
|
|
->store(config('laravel-model-caching.store')); |
51
|
|
|
$this->cache()->flush(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
56
|
|
|
*/ |
57
|
|
|
protected function getPackageProviders($app) |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
|
|
LaravelModelCachingService::class, |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function setUpBaseLineSqlLiteDatabase() |
65
|
|
|
{ |
66
|
|
|
if (self::$baseLineDatabaseMigrated) { |
67
|
|
|
return; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
self::$baseLineDatabaseMigrated = true; |
71
|
|
|
|
72
|
|
|
$file = __DIR__ . '/database/baseline.sqlite'; |
73
|
|
|
$this->app['config']->set('database.default', 'baseline'); |
|
|
|
|
74
|
|
|
$this->app['config']->set('database.connections.baseline', [ |
75
|
|
|
'driver' => 'sqlite', |
76
|
|
|
"url" => null, |
77
|
|
|
'database' => $file, |
78
|
|
|
'prefix' => '', |
79
|
|
|
"foreign_key_constraints" => false, |
80
|
|
|
]); |
81
|
|
|
|
82
|
|
|
! file_exists($file) |
83
|
|
|
?: unlink($file); |
84
|
|
|
touch($file); |
85
|
|
|
|
86
|
|
|
$this->withFactories(__DIR__ . '/database/factories'); |
|
|
|
|
87
|
|
|
$this->loadMigrationsFrom(__DIR__ . '/database/migrations'); |
|
|
|
|
88
|
|
|
|
89
|
|
|
Artisan::call('db:seed', [ |
90
|
|
|
'--class' => 'DatabaseSeeder', |
91
|
|
|
'--database' => 'baseline', |
92
|
|
|
]); |
93
|
|
|
|
94
|
|
|
$this->app['config']->set('database.default', 'testing'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
protected function getEnvironmentSetUp($app) |
98
|
|
|
{ |
99
|
|
|
$app['config']->set('database.default', 'testing'); |
100
|
|
|
$app['config']->set('database.connections.testing', [ |
101
|
|
|
'driver' => 'sqlite', |
102
|
|
|
'database' => __DIR__ . '/database/testing.sqlite', |
103
|
|
|
'prefix' => '', |
104
|
|
|
"foreign_key_constraints" => false, |
105
|
|
|
]); |
106
|
|
|
$app['config']->set('database.redis.client', "phpredis"); |
107
|
|
|
$app['config']->set('database.redis.cache', [ |
108
|
|
|
'host' => env('REDIS_HOST', '127.0.0.1'), |
109
|
|
|
'port' => env('REDIS_PORT', 6379), |
110
|
|
|
]); |
111
|
|
|
$app['config']->set('database.redis.default', [ |
112
|
|
|
'host' => env('REDIS_HOST', '127.0.0.1'), |
113
|
|
|
'port' => env('REDIS_PORT', 6379), |
114
|
|
|
]); |
115
|
|
|
$app['config']->set('database.redis.model-cache', [ |
116
|
|
|
'host' => env('REDIS_HOST', '127.0.0.1'), |
117
|
|
|
'password' => env('REDIS_PASSWORD', null), |
118
|
|
|
'port' => env('REDIS_PORT', 6379), |
119
|
|
|
'database' => 1, |
120
|
|
|
]); |
121
|
|
|
$app['config']->set('cache.stores.model', [ |
122
|
|
|
'driver' => 'redis', |
123
|
|
|
'connection' => 'model-cache', |
124
|
|
|
]); |
125
|
|
|
$app['config']->set('laravel-model-caching.store', 'model'); |
126
|
|
|
$app['config']->set("nova", [ |
127
|
|
|
'name' => 'Nova Site', |
128
|
|
|
'url' => env('APP_URL', '/'), |
129
|
|
|
'path' => '/nova', |
130
|
|
|
'guard' => env('NOVA_GUARD', null), |
131
|
|
|
'middleware' => [ |
132
|
|
|
'web', |
133
|
|
|
Authenticate::class, |
134
|
|
|
DispatchServingNovaEvent::class, |
135
|
|
|
BootTools::class, |
136
|
|
|
Authorize::class, |
137
|
|
|
], |
138
|
|
|
'pagination' => 'simple', |
139
|
|
|
]); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.