22
33namespace Kirschbaum \PowerJoins \Tests ;
44
5- use Kirschbaum \PowerJoins \PowerJoins ;
6- use Kirschbaum \PowerJoins \Tests \Models \Post ;
7- use Kirschbaum \PowerJoins \Tests \Models \User ;
8- use Kirschbaum \PowerJoins \Tests \Models \Image ;
9- use Kirschbaum \PowerJoins \Tests \Models \Comment ;
10- use Kirschbaum \PowerJoins \Tests \Models \Category ;
115use Illuminate \Database \Eloquent \Relations \HasMany ;
12- use Kirschbaum \PowerJoins \Tests \Models \UserProfile ;
6+ use Kirschbaum \PowerJoins \Tests \Models \PostWithClosureGlobalScope ;
137use Kirschbaum \PowerJoins \Tests \Models \PostWithGlobalScope ;
8+ use Kirschbaum \PowerJoins \Tests \Models \User ;
149
1510class JoinWithGlobalScopeTest extends TestCase
1611{
@@ -29,4 +24,19 @@ public function posts(): HasMany
2924 $ query = $ user ->query ()->joinRelationship ('posts ' , fn ($ join ) => $ join ->withGlobalScopes ())->toSql ();
3025 $ this ->assertStringContainsString ('"posts"."published" = ? ' , $ query );
3126 }
27+
28+ public function test_join_with_closure_global_scope_applied ()
29+ {
30+ $ user = new class extends User {
31+ public function posts (): HasMany
32+ {
33+ return $ this ->hasMany (PostWithClosureGlobalScope::class, 'user_id ' );
34+ }
35+ };
36+
37+ $ this ->assertCount (0 , $ user ->query ()->joinRelationship ('posts ' , fn ($ join ) => $ join ->withGlobalScopes ())->get ());
38+
39+ $ query = $ user ->query ()->joinRelationship ('posts ' , fn ($ join ) => $ join ->withGlobalScopes ())->toSql ();
40+ $ this ->assertStringContainsString ('"posts"."published" = ? ' , $ query );
41+ }
3242}
0 commit comments