From d18288591013b68da4c0d106cc52c8d6977d269d Mon Sep 17 00:00:00 2001 From: Ruben Van Assche Date: Fri, 17 Jan 2025 10:53:56 +0100 Subject: [PATCH] Cleanup --- ...ionTraceArgumentsJsonSerializationTest.php | 41 ------------------- tests/Fakes/NotExtendedDataClass.php | 11 ----- tests/SerializeableTest.php | 19 +++++++++ 3 files changed, 19 insertions(+), 52 deletions(-) delete mode 100644 tests/ExceptionTraceArgumentsJsonSerializationTest.php delete mode 100644 tests/Fakes/NotExtendedDataClass.php diff --git a/tests/ExceptionTraceArgumentsJsonSerializationTest.php b/tests/ExceptionTraceArgumentsJsonSerializationTest.php deleted file mode 100644 index 4e4093a0d..000000000 --- a/tests/ExceptionTraceArgumentsJsonSerializationTest.php +++ /dev/null @@ -1,41 +0,0 @@ -getTrace(); - $encodedJson = json_encode($trace, JSON_THROW_ON_ERROR); - - expect($encodedJson)->toBeJson(); - } -}); - -it('can json_encode exception trace with args when nested property not extends Data or Dto class', function () { - $dataClass = new class ('', new NotExtendedDataClass('')) extends Data { - public function __construct( - public string $string, - public NotExtendedDataClass $nested - ) { - } - }; - - try { - $dataClass::from(['string' => '', 'nested' => ['name' => '']]); - } catch (TypeError $e) { - $trace = $e->getTrace(); - $encodedJson = json_encode($trace, JSON_THROW_ON_ERROR); - - expect($encodedJson)->toBeJson(); - } -}); diff --git a/tests/Fakes/NotExtendedDataClass.php b/tests/Fakes/NotExtendedDataClass.php deleted file mode 100644 index 9c9dbecb9..000000000 --- a/tests/Fakes/NotExtendedDataClass.php +++ /dev/null @@ -1,11 +0,0 @@ -toBeInstanceOf(LazyData::class); expect($unserialized->toArray())->toMatchArray(['name' => 'Hello world']); }); + +it('can json_encode exception trace with args when not all required properties passed', function () { + // When zend.exception_ignore_args is set to Off, the trace will contain the arguments + // We want to make sure these all can be encoded into JSON + + try { + SimpleData::from([]); + } catch (CannotCreateData $e) { + $trace = $e->getTrace(); + $encodedJson = json_encode($trace, JSON_THROW_ON_ERROR); + + expect($encodedJson)->toBeJson(); + } +});