From 5273b4066eb2ff48f39d144c8c8e5461a9a5f509 Mon Sep 17 00:00:00 2001 From: "amelie.haladjian" Date: Mon, 17 Nov 2025 11:03:02 +0100 Subject: [PATCH] feat(api tester): return exception message if previous exception is null --- src/Test/TestCase.php | 10 +++++----- tests/Test/TestCaseTest.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Test/TestCase.php b/src/Test/TestCase.php index 1179cd9..2afb8d9 100644 --- a/src/Test/TestCase.php +++ b/src/Test/TestCase.php @@ -298,19 +298,19 @@ public function validateOpenApiSchema(): void $validator = new ResponseValidator($this->specification->getDocument()); $validator->validate($operationAddress, $this->response); } catch (ValidationFailed $e) { - $exception = $e->getPrevious(); + $previous = $e->getPrevious(); - if ($exception instanceof SchemaMismatch) { + if ($previous instanceof SchemaMismatch) { $breadcrumb = implode( '.', - $exception->dataBreadCrumb() !== null ? $exception->dataBreadCrumb() + $previous->dataBreadCrumb() !== null ? $previous->dataBreadCrumb() ->buildChain() : [] ); - $message = sprintf('Invalid field: %s. %s', $breadcrumb, $exception->getMessage()); + $message = sprintf('Invalid field: %s. %s', $breadcrumb, $previous->getMessage()); } throw new InvalidResponseSchemaException( $message ?? - sprintf('Response schema validation failed: %s', $exception?->getMessage()), + sprintf('Response schema validation failed: %s', $e->getMessage()), 0, $e ); diff --git a/tests/Test/TestCaseTest.php b/tests/Test/TestCaseTest.php index 24dbce7..fa4be2f 100644 --- a/tests/Test/TestCaseTest.php +++ b/tests/Test/TestCaseTest.php @@ -90,7 +90,7 @@ public function testWrongEnum(): void $this->testCase->assert(); } - public function testNullRequiredPropertyWithSchemaValidationShouldFail(): void + public function testIntInsteadOfStringShouldThrowInvalidSchemaException(): void { $this->expectException(InvalidResponseSchemaException::class);