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 \Observers \AuthorObserver ;
7- use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Profile ;
8- use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Publisher ;
9- use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Store ;
104use Orchestra \Database \ConsoleServiceProvider ;
115
126trait CreatesApplication
137{
8+ use EnvironmentSetup;
9+
1410 protected $ cache ;
1511
1612 protected function cache ()
@@ -26,43 +22,27 @@ protected function cache()
2622
2723 public function setUp () : void
2824 {
25+ $ databasePath = __DIR__ . "/database " ;
26+ $ baselinePath = "{$ databasePath }/baseline.sqlite " ;
27+ $ testingPath = "{$ databasePath }/testing.sqlite " ;
28+
29+ if (file_exists ($ testingPath )) {
30+ unlink ($ testingPath );
31+ }
32+
33+ shell_exec ("cp {$ baselinePath } {$ testingPath }" );
34+
2935 parent ::setUp ();
3036
3137 require (__DIR__ . '/routes/web.php ' );
3238
3339 $ this ->withFactories (__DIR__ . '/database/factories ' );
34- $ this ->loadMigrationsFrom (__DIR__ . '/database/migrations ' );
3540 view ()->addLocation (__DIR__ . '/resources/views ' , 'laravel-model-caching ' );
3641
3742 $ this ->cache = app ('cache ' )
3843 ->store (config ('laravel-model-caching.store ' ));
3944
4045 $ this ->cache ()->flush ();
41- $ publishers = factory (Publisher::class, 10 )->create ();
42- (new Author )->observe (AuthorObserver::class);
43- factory (Author::class, 10 )->create ()
44- ->each (function ($ author ) use ($ publishers ) {
45- $ profile = factory (Profile::class)
46- ->make ();
47- $ profile ->author_id = $ author ->id ;
48- $ profile ->save ();
49- factory (Book::class, random_int (5 , 25 ))->make ()
50- ->each (function ($ book ) use ($ author , $ publishers ) {
51- $ book ->author ()->associate ($ author );
52- $ book ->publisher ()->associate ($ publishers [rand (0 , 9 )]);
53- $ book ->save ();
54- });
55- factory (Profile::class)->make ([
56- 'author_id ' => $ author ->id ,
57- ]);
58- });
59-
60- $ bookIds = (new Book )->all ()->pluck ('id ' );
61- factory (Store::class, 10 )->create ()
62- ->each (function ($ store ) use ($ bookIds ) {
63- $ store ->books ()->sync (rand ($ bookIds ->min (), $ bookIds ->max ()));
64- });
65- $ this ->cache ()->flush ();
6646 }
6747
6848 /**
@@ -75,31 +55,4 @@ protected function getPackageProviders($app)
7555 ConsoleServiceProvider::class,
7656 ];
7757 }
78-
79- protected function getEnvironmentSetUp ($ app )
80- {
81- $ app ['config ' ]->set ('database.default ' , 'testing ' );
82- $ app ['config ' ]->set ('database.connections.testbench ' , [
83- 'driver ' => 'sqlite ' ,
84- 'database ' => ':memory: ' ,
85- 'prefix ' => '' ,
86- ]);
87- $ app ['config ' ]->set ('database.redis.cache ' , [
88- 'host ' => env ('REDIS_HOST ' , '192.168.10.10 ' ),
89- ]);
90- $ app ['config ' ]->set ('database.redis.default ' , [
91- 'host ' => env ('REDIS_HOST ' , '192.168.10.10 ' ),
92- ]);
93- $ app ['config ' ]->set ('database.redis.model-cache ' , [
94- 'host ' => env ('REDIS_HOST ' , '192.168.10.10 ' ),
95- 'password ' => env ('REDIS_PASSWORD ' , null ),
96- 'port ' => env ('REDIS_PORT ' , 6379 ),
97- 'database ' => 1 ,
98- ]);
99- $ app ['config ' ]->set ('cache.stores.model ' , [
100- 'driver ' => 'redis ' ,
101- 'connection ' => 'model-cache ' ,
102- ]);
103- $ app ['config ' ]->set ('laravel-model-caching.store ' , 'model ' );
104- }
10558}
0 commit comments