66
77use Dotcms \PhpSdk \Config \Config ;
88use Dotcms \PhpSdk \DotCMSClient ;
9- use Dotcms \PhpSdk \Http \HttpClient ;
109use Dotcms \PhpSdk \Model \PageAsset ;
1110use Dotcms \PhpSdk \Request \PageRequest ;
1211use Dotcms \PhpSdk \Service \PageService ;
@@ -29,21 +28,6 @@ protected function setUp(): void
2928 $ this ->client = new DotCMSClient ($ this ->config );
3029 }
3130
32- public function testGetConfig (): void
33- {
34- $ this ->assertSame ($ this ->config , $ this ->client ->getConfig ());
35- }
36-
37- public function testGetHttpClient (): void
38- {
39- $ this ->assertInstanceOf (HttpClient::class, $ this ->client ->getHttpClient ());
40- }
41-
42- public function testGetPageService (): void
43- {
44- $ this ->assertInstanceOf (PageService::class, $ this ->client ->getPageService ());
45- }
46-
4731 public function testCreatePageRequest (): void
4832 {
4933 $ pagePath = '/about-us/index ' ;
@@ -64,18 +48,22 @@ public function testGetPage(): void
6448 // Create a mock PageRequest
6549 $ pageRequestMock = $ this ->createMock (PageRequest::class);
6650
67- // Create a test double for DotCMSClient
68- $ clientMock = $ this ->getMockBuilder (DotCMSClient::class)
69- ->setConstructorArgs ([$ this ->config ])
70- ->onlyMethods (['getPage ' ])
71- ->getMock ();
72-
73- // Configure the mock to return our mock page asset
74- $ clientMock ->expects ($ this ->once ())
51+ // Create a mock PageService that will return our mock PageAsset
52+ $ pageServiceMock = $ this ->createMock (PageService::class);
53+ $ pageServiceMock ->expects ($ this ->once ())
7554 ->method ('getPage ' )
7655 ->with ($ pageRequestMock )
7756 ->willReturn ($ pageAssetMock );
7857
58+ // Create a partial mock of DotCMSClient with the pageService property replaced
59+ $ clientMock = $ this ->createPartialMock (DotCMSClient::class, []);
60+
61+ // Set the mocked pageService using reflection
62+ $ reflection = new \ReflectionClass ($ clientMock );
63+ $ property = $ reflection ->getProperty ('pageService ' );
64+ $ property ->setAccessible (true );
65+ $ property ->setValue ($ clientMock , $ pageServiceMock );
66+
7967 // Call the method
8068 $ result = $ clientMock ->getPage ($ pageRequestMock );
8169
@@ -94,18 +82,22 @@ public function testGetPageAsync(): void
9482 // Create a mock Promise
9583 $ promiseMock = new FulfilledPromise ($ pageAssetMock );
9684
97- // Create a test double for DotCMSClient
98- $ clientMock = $ this ->getMockBuilder (DotCMSClient::class)
99- ->setConstructorArgs ([$ this ->config ])
100- ->onlyMethods (['getPageAsync ' ])
101- ->getMock ();
102-
103- // Configure the mock to return our mock Promise
104- $ clientMock ->expects ($ this ->once ())
85+ // Create a mock PageService that will return our mock Promise
86+ $ pageServiceMock = $ this ->createMock (PageService::class);
87+ $ pageServiceMock ->expects ($ this ->once ())
10588 ->method ('getPageAsync ' )
10689 ->with ($ pageRequestMock )
10790 ->willReturn ($ promiseMock );
10891
92+ // Create a partial mock of DotCMSClient with the pageService property replaced
93+ $ clientMock = $ this ->createPartialMock (DotCMSClient::class, []);
94+
95+ // Set the mocked pageService using reflection
96+ $ reflection = new \ReflectionClass ($ clientMock );
97+ $ property = $ reflection ->getProperty ('pageService ' );
98+ $ property ->setAccessible (true );
99+ $ property ->setValue ($ clientMock , $ pageServiceMock );
100+
109101 // Call the method
110102 $ result = $ clientMock ->getPageAsync ($ pageRequestMock );
111103
0 commit comments