@@ -71,13 +71,6 @@ protected function defineDatabaseMigrations(): void
71
71
});
72
72
}
73
73
74
- public function test_passes_through_method_calls (): void
75
- {
76
- $ query = $ this ->app ->make ('db ' )->table ('users ' )->cache ()->where ('id ' , 1 );
77
-
78
- static ::assertSame ([], $ query ->getConnection ()->getQueryLog ());
79
- }
80
-
81
74
public function test_caches_base_query_into_default_store (): void
82
75
{
83
76
$ get = $ this ->app ->make ('db ' )->table ('users ' )->cache ()->where ('id ' , 1 )->get ();
@@ -874,6 +867,10 @@ public function test_pass_through_methods_to_wrapped_connection(): void
874
867
$ connection ->setDatabaseName ('foo ' );
875
868
876
869
static ::assertSame ('foo ' , $ connection ->getDatabaseName ());
870
+
871
+ $ query = $ this ->app ->make ('db ' )->table ('users ' )->cache ()->where ('id ' , 1 );
872
+
873
+ static ::assertSame ([], $ query ->getConnection ()->getQueryLog ());
877
874
}
878
875
879
876
public function test_pass_through_properties_set_and_get (): void
@@ -916,6 +913,24 @@ public function test_sets_custom_query_hasher(): void
916
913
917
914
static ::assertTrue ($ this ->app ->make ('cache ' )->has ('cache-query|test_hash ' ));
918
915
}
916
+
917
+ public function test_base_query_uses_cache_callback (): void
918
+ {
919
+ $ hash = 'cache-query|fj8Xyz4K1Zh0tdAamPbG1A ' ;
920
+
921
+ $ repository = $ this ->mock (Repository::class);
922
+ $ repository ->expects ('flexible ' )->never ();
923
+ $ repository ->expects ('put ' )->with ($ hash , Mockery::type ('array ' ), [5 , 300 ])->once ();
924
+ $ repository ->expects ('getMultiple ' )->with ([$ hash , '' ])->times (1 )->andReturn (['' => null , $ hash => null ]);
925
+
926
+ $ this ->mock ('cache ' )->expects ('store ' )->with (null )->andReturn ($ repository );
927
+
928
+ $ this ->app ->make ('db ' )->table ('users ' )->where ('id ' , 1 )->cache (function ($ cache ) {
929
+ static ::assertInstanceOf (Cache::class, $ cache );
930
+
931
+ $ cache ->ttl ([5 , 300 ]);
932
+ })->first ();
933
+ }
919
934
}
920
935
921
936
class User extends Authenticatable
0 commit comments