11<?php namespace GeneaLabs \LaravelModelCaching \Tests ;
22
33use 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 ;
49use Orchestra \Database \ConsoleServiceProvider ;
510
611trait CreatesApplication
712{
13+ protected $ cache ;
14+
815 public function setUp ()
916 {
1017 parent ::setUp ();
1118
1219 $ this ->withFactories (__DIR__ . '/database/factories ' );
1320 $ 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 ();
1446 }
1547
1648 /**
@@ -23,4 +55,22 @@ protected function getPackageProviders($app)
2355 ConsoleServiceProvider::class,
2456 ];
2557 }
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+ }
2676}
0 commit comments