Skip to content

Commit

Permalink
Soothe SA: Improve test robustness with stricter type assertions
Browse files Browse the repository at this point in the history
Added stricter type checks and assertions in unit tests to improve robustness and ensure better error handling. These changes enforce expected data structures and validate outputs more thoroughly.
  • Loading branch information
koriym committed Jan 10, 2025
1 parent d126abf commit a38cc5e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
24 changes: 17 additions & 7 deletions tests/Provide/Error/DevVndErrorPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,24 @@ public function testToString(): void
"exceptions": "LogicException(bear)"
}';

$actualArray = json_decode($actual, true);
$expectedArray = json_decode($expected, true);
$actualJson = json_decode($actual, true);
$expectedJson = json_decode($expected, true);

$this->assertSame($expectedArray['message'], $actualArray['message']);
$this->assertSame($expectedArray['logref'], $actualArray['logref']);
$this->assertSame($expectedArray['request'], $actualArray['request']);
$this->assertSame($expectedArray['exceptions'], $actualArray['exceptions']);
$this->assertIsArray($actualJson);
$this->assertIsArray($expectedJson);

$this->assertArrayHasKey('file', $actualArray);
/** @var array{message: string, logref: string, request: string, exceptions: string, file: string} $actualJson */
/** @var array{message: string, logref: string, request: string, exceptions: string} $expectedJson */

$this->assertArrayHasKey('message', $actualJson);
$this->assertArrayHasKey('logref', $actualJson);
$this->assertArrayHasKey('request', $actualJson);
$this->assertArrayHasKey('exceptions', $actualJson);
$this->assertArrayHasKey('file', $actualJson);

$this->assertSame($expectedJson['message'], $actualJson['message']);
$this->assertSame($expectedJson['logref'], $actualJson['logref']);
$this->assertSame($expectedJson['request'], $actualJson['request']);
$this->assertSame($expectedJson['exceptions'], $actualJson['exceptions']);
}
}
8 changes: 6 additions & 2 deletions tests/Provide/Transfer/CliResponderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ public function testTransfer(): void
$ro->headers['X-BEAR-VERSION'] = 'Sunday';
ob_start();
$ro->transfer($this->responder, []);
$actual = ob_get_clean();

$output = ob_get_clean();
$this->assertNotFalse($output);
/** @var non-empty-string $output */

$expect = <<< 'EOT'
200 OK
Content-Type: application/json
X-BEAR-VERSION: Sunday
{"greeting":"Hello BEAR.Sunday"}
EOT;
$this->assertNormalizedStringEquals($expect, $actual);
$this->assertNormalizedStringEquals($expect, $output);
}
}

0 comments on commit a38cc5e

Please sign in to comment.