88use App \WikiProfile ;
99use Illuminate \Database \Events \QueryExecuted ;
1010use Illuminate \Foundation \Testing \DatabaseTransactions ;
11+ use Illuminate \Http \Request ;
1112use Illuminate \Support \Facades \DB ;
1213use Tests \TestCase ;
1314
1415class PublicWikiControllerTest extends TestCase {
1516 use DatabaseTransactions;
1617
17- public function testShowEagerLoadsWikiLatestProfileForResource (): void {
18+ public function testShowLoadsWikiLatestProfileForResource (): void {
1819 $ wiki = Wiki::factory ()->create ([
1920 'domain ' => 'controller-test.wikibase.cloud ' ,
2021 'sitename ' => 'controller-test ' ,
@@ -31,14 +32,14 @@ public function testShowEagerLoadsWikiLatestProfileForResource(): void {
3132 $ resource = $ controller ->show ($ wiki ->id );
3233
3334 $ this ->assertInstanceOf (PublicWikiResource::class, $ resource );
34- $ this ->assertTrue ( $ resource ->resource -> relationLoaded ( ' wikiLatestProfile ' ) );
35+ $ this ->assertSame ( true , $ resource ->toArray ( new Request )[ ' reuse_prototype ' ] );
3536 }
3637
3738 public function testIndexEagerLoadsWikiLatestProfileOnceForCollection (): void {
38- for ($ i = 1 ; $ i <= rand ( 3 , 100 ) ; $ i ++) {
39+ for ($ i = 1 ; $ i <= 3 ; $ i ++) {
3940 $ wiki = Wiki::factory ()->create ([
40- 'domain ' => ' index-eager-load-test- ' . $ i . ' . wikibase.cloud' ,
41- 'sitename ' => ' Index Eager Load Test Site ' . $ i ,
41+ 'domain ' => " index-eager-load-test- { $ i } . wikibase.cloud" ,
42+ 'sitename ' => " Index Eager Load Test Site { $ i }" ,
4243 ]);
4344
4445 WikiProfile::create ([
@@ -57,9 +58,9 @@ public function testIndexEagerLoadsWikiLatestProfileOnceForCollection(): void {
5758 });
5859
5960 $ controller = new PublicWikiController ;
60- $ resourceCollection = $ controller ->index (request () );
61+ $ resourceCollection = $ controller ->index (new Request );
6162
6263 $ this ->assertSame (1 , $ profileQueryCount );
63- $ this ->assertTrue ($ resourceCollection ->collection [ 0 ]-> resource ->relationLoaded ('wikiLatestProfile ' ));
64+ $ this ->assertTrue ($ resourceCollection ->first () ->relationLoaded ('wikiLatestProfile ' ));
6465 }
6566}
0 commit comments