Skip to content

Commit 1c8a801

Browse files
committed
refactor(client): Remove unused methods from DotCMSClient
Clean up the DotCMSClient class by removing the following methods: - getConfig() - getHttpClient() - getPageService() Update README and tests accordingly to reflect these changes.
1 parent c582760 commit 1c8a801

3 files changed

Lines changed: 24 additions & 65 deletions

File tree

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ The main client for interacting with the dotCMS API.
189189
- `getPage(PageRequest $request)`: Fetch a page synchronously
190190
- `getPageAsync(PageRequest $request)`: Fetch a page asynchronously
191191
- `createPageRequest(string $pagePath, string $format = 'json')`: Create a new page request
192-
- `getConfig()`: Get the client configuration
193-
- `getHttpClient()`: Get the HTTP client
194-
- `getPageService()`: Get the page service
195192

196193
### PageRequest
197194

src/DotCMSClient.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,6 @@ public function __construct(private readonly Config $config)
3131
$this->pageService = new PageService($this->httpClient);
3232
}
3333

34-
/**
35-
* Get the configuration
36-
*
37-
* @return Config The client configuration
38-
*/
39-
public function getConfig(): Config
40-
{
41-
return $this->config;
42-
}
43-
44-
/**
45-
* Get the HTTP client
46-
*
47-
* @return HttpClient The HTTP client
48-
*/
49-
public function getHttpClient(): HttpClient
50-
{
51-
return $this->httpClient;
52-
}
53-
54-
/**
55-
* Get the page service
56-
*
57-
* @return PageService The page service
58-
*/
59-
public function getPageService(): PageService
60-
{
61-
return $this->pageService;
62-
}
63-
6434
/**
6535
* Fetch a page from dotCMS
6636
*

tests/DotCMSClientTest.php

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Dotcms\PhpSdk\Config\Config;
88
use Dotcms\PhpSdk\DotCMSClient;
9-
use Dotcms\PhpSdk\Http\HttpClient;
109
use Dotcms\PhpSdk\Model\PageAsset;
1110
use Dotcms\PhpSdk\Request\PageRequest;
1211
use 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

Comments
 (0)