Skip to content

Commit 123020f

Browse files
committed
update units tests
1 parent 0efcd37 commit 123020f

File tree

5 files changed

+22
-76
lines changed

5 files changed

+22
-76
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,4 @@ jobs:
6464
run: "mkdir -p build/logs"
6565
- uses: "ramsey/composer-install@v3"
6666
- name: "Run unit tests"
67-
run: "./vendor/bin/phpunit --colors=always --coverage-clover build/logs/clover.xml --coverage-text"
68-
- name: "Publish coverage report to Codecov"
69-
uses: "codecov/codecov-action@v5"
67+
run: "./vendor/bin/phpunit --colors=always --coverage-text"

tests/GeocachingAdventureSdkTest.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/GeocachingSdkTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public function testAllApiMethodsExist(): void
3737
$methods = [
3838
// Adventures API
3939
'getAdventure',
40-
'getStartLocationAdventure',
4140
'searchAdventures',
4241
'searchAdventuresStages',
4342

tests/OptionsTest.php

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ public function testEnableHttpLoggingWithUnknownLevelUsesDefaultInfo(): void
4848
// Vérifie que le plugin ajouté utilise un logger avec Level::Info
4949
$reflection = new \ReflectionClass($clientBuilder);
5050
$pluginsProperty = $reflection->getProperty('plugins');
51-
$pluginsProperty->setAccessible(true);
5251
$plugins = $pluginsProperty->getValue($clientBuilder);
5352
$loggerPlugin = end($plugins);
5453
$reflectionPlugin = new \ReflectionClass($loggerPlugin);
5554
$loggerProperty = $reflectionPlugin->getProperty('logger');
56-
$loggerProperty->setAccessible(true);
5755
$logger = $loggerProperty->getValue($loggerPlugin);
5856
$handlers = $logger->getHandlers();
5957
$handler = $handlers[0];
@@ -67,7 +65,7 @@ public function testEnableHttpLoggingWithUnknownLevelUsesDefaultInfo(): void
6765
protected function setUp(): void
6866
{
6967
parent::setUp();
70-
$this->logger = $this->createMock(LoggerInterface::class);
68+
$this->logger = $this->createStub(LoggerInterface::class);
7169
$this->clientBuilder = new ClientBuilder(new Client());
7270
$this->options = new Options([
7371
'access_token' => 'test-token',
@@ -112,8 +110,8 @@ public function testEnableHttpLoggingWithDefaultParameters(): void
112110

113111
public function testMultipleLoggingPluginsCanBeAdded(): void
114112
{
115-
$logger1 = $this->createMock(LoggerInterface::class);
116-
$logger2 = $this->createMock(LoggerInterface::class);
113+
$logger1 = $this->createStub(LoggerInterface::class);
114+
$logger2 = $this->createStub(LoggerInterface::class);
117115
$initialCount = $this->getPluginCount();
118116
$this->options->enableHttpLoggingWithLogger($logger1);
119117
$this->options->enableHttpLoggingWithLogger($logger2);
@@ -150,32 +148,23 @@ private function getPlugins(): array
150148
{
151149
$reflection = new \ReflectionClass($this->clientBuilder);
152150
$pluginsProperty = $reflection->getProperty('plugins');
153-
$pluginsProperty->setAccessible(true);
154151
return $pluginsProperty->getValue($this->clientBuilder);
155152
}
156153

157154
public function testCreateConfiguredLoggerReturnsLoggerInstance(): void
158155
{
159-
$options = $this->getMockBuilder(Options::class)
160-
->disableOriginalConstructor()
161-
->onlyMethods([])
162-
->getMock();
156+
$options = $this->createStub(Options::class);
163157
$reflection = new \ReflectionClass($options);
164158
$method = $reflection->getMethod('createConfiguredLogger');
165-
$method->setAccessible(true);
166159
$logger = $method->invoke($options, 'php://memory', 'info');
167160
$this->assertInstanceOf(Logger::class, $logger);
168161
}
169162

170163
public function testCreateConfiguredLoggerSetsLevelAndFormat(): void
171164
{
172-
$options = $this->getMockBuilder(Options::class)
173-
->disableOriginalConstructor()
174-
->onlyMethods([])
175-
->getMock();
165+
$options = $this->createStub(Options::class);
176166
$reflection = new \ReflectionClass($options);
177167
$method = $reflection->getMethod('createConfiguredLogger');
178-
$method->setAccessible(true);
179168
$customFormat = '[%level_name%] %message%';
180169
$logger = $method->invoke($options, 'php://memory', 'error', $customFormat);
181170
$handlers = $logger->getHandlers();
@@ -187,27 +176,21 @@ public function testCreateConfiguredLoggerSetsLevelAndFormat(): void
187176
$this->assertInstanceOf(LineFormatter::class, $formatter);
188177
$reflectionFormatter = new \ReflectionClass($formatter);
189178
$formatProperty = $reflectionFormatter->getProperty('format');
190-
$formatProperty->setAccessible(true);
191179
$this->assertSame($customFormat, $formatProperty->getValue($formatter));
192180
}
193181

194182
public function testDefaultFormatAndLevelAreUsedWhenNotProvided(): void
195183
{
196-
$options = $this->getMockBuilder(Options::class)
197-
->disableOriginalConstructor()
198-
->onlyMethods([])
199-
->getMock();
184+
$options = $this->createStub(Options::class);
200185
$reflection = new \ReflectionClass($options);
201186
$method = $reflection->getMethod('createConfiguredLogger');
202-
$method->setAccessible(true);
203187
$logger = $method->invoke($options, 'php://memory', 'unknownlevel');
204188
$handlers = $logger->getHandlers();
205189
$handler = $handlers[0];
206190
$this->assertSame(Level::Info, $handler->getLevel());
207191
$formatter = $handler->getFormatter();
208192
$reflectionFormatter = new \ReflectionClass($formatter);
209193
$formatProperty = $reflectionFormatter->getProperty('format');
210-
$formatProperty->setAccessible(true);
211194
$this->assertSame("[%datetime%] %channel%.%level_name%: %message% %context%\n", $formatProperty->getValue($formatter));
212195
}
213196

@@ -223,13 +206,9 @@ public function testAllPsr3LevelsAreSupported(): void
223206
'alert' => Level::Alert,
224207
'emergency' => Level::Emergency,
225208
];
226-
$options = $this->getMockBuilder(Options::class)
227-
->disableOriginalConstructor()
228-
->onlyMethods([])
229-
->getMock();
209+
$options = $this->createStub(Options::class);
230210
$reflection = new \ReflectionClass($options);
231211
$method = $reflection->getMethod('createConfiguredLogger');
232-
$method->setAccessible(true);
233212
foreach ($levels as $levelStr => $expectedLevel) {
234213
$logger = $method->invoke($options, 'php://memory', $levelStr);
235214
$handlers = $logger->getHandlers();
@@ -240,19 +219,14 @@ public function testAllPsr3LevelsAreSupported(): void
240219

241220
public function testLogFormatNullUsesDefault(): void
242221
{
243-
$options = $this->getMockBuilder(Options::class)
244-
->disableOriginalConstructor()
245-
->onlyMethods([])
246-
->getMock();
222+
$options = $this->createStub(Options::class);
247223
$reflection = new \ReflectionClass($options);
248224
$method = $reflection->getMethod('createConfiguredLogger');
249-
$method->setAccessible(true);
250225
$logger = $method->invoke($options, 'php://memory', 'info', null);
251226
$handlers = $logger->getHandlers();
252227
$formatter = $handlers[0]->getFormatter();
253228
$reflectionFormatter = new \ReflectionClass($formatter);
254229
$formatProperty = $reflectionFormatter->getProperty('format');
255-
$formatProperty->setAccessible(true);
256230
$this->assertSame("[%datetime%] %channel%.%level_name%: %message% %context%\n", $formatProperty->getValue($formatter));
257231
}
258232
}

tests/Plugin/GeocachingHttpLoggerPluginTest.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testHandleRequestLogsException(): void
3636

3737
public function testMaskSensitiveDataNoMaskingWhenDisabled(): void
3838
{
39-
$logger = $this->createMock(LoggerInterface::class);
39+
$logger = $this->createStub(LoggerInterface::class);
4040
$plugin = new GeocachingHttpLoggerPlugin($logger, LogLevel::INFO, false, false);
4141
$ref = new \ReflectionClass($plugin);
4242
$method = $ref->getMethod('maskSensitiveData');
@@ -49,7 +49,7 @@ public function testMaskSensitiveDataNoMaskingWhenDisabled(): void
4949

5050
public function testMaskHeadersNoMaskingWhenDisabled(): void
5151
{
52-
$logger = $this->createMock(LoggerInterface::class);
52+
$logger = $this->createStub(LoggerInterface::class);
5353
$plugin = new GeocachingHttpLoggerPlugin($logger, LogLevel::INFO, false, false);
5454
$ref = new \ReflectionClass($plugin);
5555
$method = $ref->getMethod('maskHeaders');
@@ -64,7 +64,7 @@ public function testMaskHeadersNoMaskingWhenDisabled(): void
6464

6565
public function testFilterResponseHeadersReturnsEmptyIfNoInterestingHeaders(): void
6666
{
67-
$logger = $this->createMock(LoggerInterface::class);
67+
$logger = $this->createStub(LoggerInterface::class);
6868
$plugin = new GeocachingHttpLoggerPlugin($logger);
6969
$ref = new \ReflectionClass($plugin);
7070
$method = $ref->getMethod('filterResponseHeaders');
@@ -79,7 +79,7 @@ public function testFilterResponseHeadersReturnsEmptyIfNoInterestingHeaders(): v
7979

8080
public function testTruncateBodyNoTruncationIfShort(): void
8181
{
82-
$logger = $this->createMock(LoggerInterface::class);
82+
$logger = $this->createStub(LoggerInterface::class);
8383
$plugin = new GeocachingHttpLoggerPlugin($logger, LogLevel::INFO, true, true, 100);
8484
$ref = new \ReflectionClass($plugin);
8585
$method = $ref->getMethod('truncateBody');
@@ -91,7 +91,7 @@ public function testTruncateBodyNoTruncationIfShort(): void
9191

9292
public function testGetLogLevelForStatusAllBranches(): void
9393
{
94-
$logger = $this->createMock(LoggerInterface::class);
94+
$logger = $this->createStub(LoggerInterface::class);
9595
$plugin = new GeocachingHttpLoggerPlugin($logger, LogLevel::INFO);
9696
$ref = new \ReflectionClass($plugin);
9797
$method = $ref->getMethod('getLogLevelForStatus');
@@ -104,7 +104,7 @@ public function testGetLogLevelForStatusAllBranches(): void
104104

105105
public function testConstructSetsPropertiesLegacy(): void
106106
{
107-
$logger = $this->createMock(LoggerInterface::class);
107+
$logger = $this->createStub(LoggerInterface::class);
108108
$plugin = new GeocachingHttpLoggerPlugin($logger, LogLevel::DEBUG, true, false, 123);
109109
$ref = new \ReflectionClass($plugin);
110110
$this->assertSame($logger, $ref->getProperty('logger')->getValue($plugin));
@@ -116,7 +116,7 @@ public function testConstructSetsPropertiesLegacy(): void
116116

117117
public function testMaskSensitiveDataMasksTokensLegacy(): void
118118
{
119-
$logger = $this->createMock(LoggerInterface::class);
119+
$logger = $this->createStub(LoggerInterface::class);
120120
$plugin = new GeocachingHttpLoggerPlugin($logger);
121121
$ref = new \ReflectionClass($plugin);
122122
$method = $ref->getMethod('maskSensitiveData');
@@ -263,7 +263,7 @@ public function testLogsResponseBodyWhenEnabled(): void
263263
$plugin = new GeocachingHttpLoggerPlugin($logger, LogLevel::INFO, true);
264264
$bodyContent = '{"foo":"bar"}';
265265
$body = $this->createMockStream($bodyContent);
266-
$response = $this->createMock(ResponseInterface::class);
266+
$response = $this->createStub(ResponseInterface::class);
267267
$response->method('getStatusCode')->willReturn(200);
268268
$response->method('getReasonPhrase')->willReturn('OK');
269269
$response->method('getHeaders')->willReturn(['Content-Type' => ['application/json']]);
@@ -290,9 +290,9 @@ public function testLogsResponseBodyWhenEnabled(): void
290290

291291
private function createMockRequest(string $method, string $uri, array $headers = [], ?StreamInterface $body = null): RequestInterface
292292
{
293-
$request = $this->createMock(RequestInterface::class);
293+
$request = $this->createStub(RequestInterface::class);
294294
$request->method('getMethod')->willReturn($method);
295-
$uriMock = $this->createMock(UriInterface::class);
295+
$uriMock = $this->createStub(UriInterface::class);
296296
$uriMock->method('__toString')->willReturn($uri);
297297
$request->method('getUri')->willReturn($uriMock);
298298
$request->method('getHeaders')->willReturn($headers);
@@ -305,7 +305,7 @@ private function createMockRequest(string $method, string $uri, array $headers =
305305

306306
private function createMockResponse(int $statusCode, string $reasonPhrase, array $headers = []): ResponseInterface
307307
{
308-
$response = $this->createMock(ResponseInterface::class);
308+
$response = $this->createStub(ResponseInterface::class);
309309
$response->method('getStatusCode')->willReturn($statusCode);
310310
$response->method('getReasonPhrase')->willReturn($reasonPhrase);
311311
$response->method('getHeaders')->willReturn($headers);
@@ -315,10 +315,9 @@ private function createMockResponse(int $statusCode, string $reasonPhrase, array
315315

316316
private function createMockStream(string $content): StreamInterface
317317
{
318-
$stream = $this->createMock(StreamInterface::class);
318+
$stream = $this->createStub(StreamInterface::class);
319319
$stream->method('getContents')->willReturn($content);
320320
$stream->method('getSize')->willReturn(strlen($content));
321-
$stream->expects($this->any())->method('rewind');
322321
return $stream;
323322
}
324-
}
323+
}

0 commit comments

Comments
 (0)