Skip to content

Commit 3086d40

Browse files
committed
Increased coverage.
1 parent f3740d1 commit 3086d40

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

.vortex/tooling/tests/Self/MockRequestSelfTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,4 +496,36 @@ public function testMockRequestGetScriptFailureAssertUnexpectedUrl(): void {
496496
$this->runScript('test-request-get-passing', 'tests/Fixtures');
497497
}
498498

499+
public function testMockRequestFailureMissingUrlKey(): void {
500+
$this->expectException(\InvalidArgumentException::class);
501+
$this->expectExceptionMessage('Mocked request response must include "url" key to specify expected URL.');
502+
503+
// Call mockRequestMultiple directly with malformed
504+
// response (missing 'url' key).
505+
// @phpstan-ignore-next-line argument.type
506+
$this->mockRequestMultiple([
507+
[
508+
'method' => 'GET',
509+
'response' => ['status' => 200, 'body' => 'test'],
510+
],
511+
]);
512+
513+
// Trigger curl_exec which validates the response structure.
514+
\DrevOps\VortexTooling\request_get('https://example.com/api');
515+
}
516+
517+
public function testMockRequestFailureMethodMismatch(): void {
518+
$this->mockRequest(
519+
'https://example.com/api',
520+
['method' => 'POST'],
521+
['status' => 200, 'body' => 'test']
522+
);
523+
524+
$this->expectException(\RuntimeException::class);
525+
$this->expectExceptionMessage('request made with unexpected method. Expected "POST", got "GET".');
526+
527+
// Make GET request when POST was expected.
528+
\DrevOps\VortexTooling\request_get('https://example.com/api');
529+
}
530+
499531
}

.vortex/tooling/tests/Traits/MockTrait.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,14 @@ protected function mockRequestMultiple(array $responses, string $namespace = 'Dr
283283
->willReturnCallback(function () use (&$current_url, &$current_method): string|false {
284284
$total_responses = count($this->mockRequestResponses);
285285

286+
// Note: This check is unreachable in normal flow since curl_init()
287+
// already validates the index. Kept as defensive programming for safety
288+
// in case the mock structure changes or curl_init is bypassed.
289+
// @codeCoverageIgnoreStart
286290
if ($this->mockRequestIndex >= $total_responses) {
287291
throw new \RuntimeException(sprintf('curl_exec() called more times than mocked responses. Expected %d request(s), but attempting request #%d.', $total_responses, $this->mockRequestIndex + 1));
288292
}
289-
293+
// @codeCoverageIgnoreEnd
290294
$mock = $this->mockRequestResponses[$this->mockRequestIndex];
291295

292296
// Capture current values before incrementing/resetting.

0 commit comments

Comments
 (0)