1
1
<?php namespace GeneaLabs \LaravelModelCaching \Tests ;
2
2
3
3
use GeneaLabs \LaravelModelCaching \Providers \Service as LaravelModelCachingService ;
4
+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Author ;
5
+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Book ;
6
+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Profile ;
7
+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Publisher ;
8
+ use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Store ;
4
9
use Orchestra \Database \ConsoleServiceProvider ;
5
10
6
11
trait CreatesApplication
7
12
{
13
+ protected $ cache ;
14
+
8
15
public function setUp ()
9
16
{
10
17
parent ::setUp ();
11
18
12
19
$ this ->withFactories (__DIR__ . '/database/factories ' );
13
20
$ this ->loadMigrationsFrom (__DIR__ . '/database/migrations ' );
21
+
22
+ $ this ->cache = cache ()
23
+ ->store (config ('laravel-model-caching.store ' ));
24
+
25
+ $ this ->cache ()->flush ();
26
+ $ publishers = factory (Publisher::class, 10 )->create ();
27
+ factory (Author::class, 10 )->create ()
28
+ ->each (function ($ author ) use ($ publishers ) {
29
+ factory (Book::class, random_int (2 , 10 ))->make ()
30
+ ->each (function ($ book ) use ($ author , $ publishers ) {
31
+ $ book ->author ()->associate ($ author );
32
+ $ book ->publisher ()->associate ($ publishers [rand (0 , 9 )]);
33
+ $ book ->save ();
34
+ });
35
+ factory (Profile::class)->make ([
36
+ 'author_id ' => $ author ->id ,
37
+ ]);
38
+ });
39
+
40
+ $ bookIds = (new Book )->all ()->pluck ('id ' );
41
+ factory (Store::class, 10 )->create ()
42
+ ->each (function ($ store ) use ($ bookIds ) {
43
+ $ store ->books ()->sync (rand ($ bookIds ->min (), $ bookIds ->max ()));
44
+ });
45
+ $ this ->cache ()->flush ();
14
46
}
15
47
16
48
/**
@@ -23,4 +55,22 @@ protected function getPackageProviders($app)
23
55
ConsoleServiceProvider::class,
24
56
];
25
57
}
58
+
59
+ protected function getEnvironmentSetUp ($ app )
60
+ {
61
+ $ app ['config ' ]->set ('database.redis.default ' , [
62
+ 'host ' => env ('REDIS_HOST ' , '192.168.10.10 ' ),
63
+ ]);
64
+ $ app ['config ' ]->set ('database.redis.model-cache ' , [
65
+ 'host ' => env ('REDIS_HOST ' , '192.168.10.10 ' ),
66
+ 'password ' => env ('REDIS_PASSWORD ' , null ),
67
+ 'port ' => env ('REDIS_PORT ' , 6379 ),
68
+ 'database ' => 1 ,
69
+ ]);
70
+ $ app ['config ' ]->set ('cache.stores.model ' , [
71
+ 'driver ' => 'redis ' ,
72
+ 'connection ' => 'model-cache ' ,
73
+ ]);
74
+ $ app ['config ' ]->set ('laravel-model-caching.store ' , 'model ' );
75
+ }
26
76
}
0 commit comments