From 2a7f6e581687c261d4fb228f65e8a59fe616ba22 Mon Sep 17 00:00:00 2001 From: Edmond <1571649+EdmondDantes@users.noreply.github.com> Date: Fri, 15 Nov 2024 11:13:21 +0200 Subject: [PATCH] + more tests --- src/ClassNotExist.php | 2 +- src/InterfaceNotImplemented.php | 2 +- src/RequiredValueEmpty.php | 2 +- src/SerializeException.php | 5 ++--- tests/InterfaceNotImplementedTest.php | 19 +++++++++++++++++++ tests/ObjectNotInitializedTest.php | 17 +++++++++++++++++ tests/RecursionLimitExceededTest.php | 17 +++++++++++++++++ tests/RequiredValueEmptyTest.php | 17 +++++++++++++++++ tests/SerializeExceptionTest.php | 17 +++++++++++++++++ 9 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 tests/InterfaceNotImplementedTest.php create mode 100644 tests/ObjectNotInitializedTest.php create mode 100644 tests/RecursionLimitExceededTest.php create mode 100644 tests/RequiredValueEmptyTest.php create mode 100644 tests/SerializeExceptionTest.php diff --git a/src/ClassNotExist.php b/src/ClassNotExist.php index c6e8ce8..7ae68e6 100644 --- a/src/ClassNotExist.php +++ b/src/ClassNotExist.php @@ -21,7 +21,7 @@ public function __construct(array|string $class) if (!\is_scalar($class)) { parent::__construct($class); } else { - parent::__construct(['class' => $class ]); + parent::__construct(['class' => $class]); } } } diff --git a/src/InterfaceNotImplemented.php b/src/InterfaceNotImplemented.php index c4de6e8..b865a49 100644 --- a/src/InterfaceNotImplemented.php +++ b/src/InterfaceNotImplemented.php @@ -23,7 +23,7 @@ public function __construct(object|array|string $class, string $interface) parent::__construct($class); } else { parent::__construct([ - 'class' => $this->typeInfo($class), + 'class' => is_string($class) ? $class : $this->typeInfo($class), 'interface' => $interface, ]); } diff --git a/src/RequiredValueEmpty.php b/src/RequiredValueEmpty.php index 4e485c4..5deb004 100644 --- a/src/RequiredValueEmpty.php +++ b/src/RequiredValueEmpty.php @@ -9,7 +9,7 @@ */ class RequiredValueEmpty extends LoggableException { - protected string $template = 'The Required value {name} is empty ({expected})'; + protected string $template = 'The Required value {name} is empty (expected: {expected})'; /** * If required value is empty. diff --git a/src/SerializeException.php b/src/SerializeException.php index 4043b43..687581e 100644 --- a/src/SerializeException.php +++ b/src/SerializeException.php @@ -9,7 +9,7 @@ */ class SerializeException extends LoggableException { - protected string $template = 'Serialize process was failed (type:{type}, object:{object}, src:{srcObject}). {reason}'; + protected string $template = 'Serialize process was failed (type:{type}, object:{object}, src:{srcObject})'; /** * Object can't be serialized! @@ -27,8 +27,7 @@ public function __construct(array|string $reason, $object = null, string $type = } parent::__construct([ - 'message' => 'Serialize Failed', - 'reason' => $reason, + 'message' => $reason, 'type' => $type, 'object' => $this->typeInfo($object), 'srcObject' => $this->typeInfo($srcObject), diff --git a/tests/InterfaceNotImplementedTest.php b/tests/InterfaceNotImplementedTest.php new file mode 100644 index 0000000..762d1be --- /dev/null +++ b/tests/InterfaceNotImplementedTest.php @@ -0,0 +1,19 @@ +assertEquals("Class 'myClassName' does not implement interface 'Interface'", $exception->getMessage()); + + $exception = new InterfaceNotImplemented(new \stdClass(), 'Interface'); + $this->assertEquals("Class 'stdClass' does not implement interface 'Interface'", $exception->getMessage()); + } +} diff --git a/tests/ObjectNotInitializedTest.php b/tests/ObjectNotInitializedTest.php new file mode 100644 index 0000000..b71f792 --- /dev/null +++ b/tests/ObjectNotInitializedTest.php @@ -0,0 +1,17 @@ +assertEquals("Object 'STRING' is not initialized. Additional message", $exception->getMessage()); + } +} diff --git a/tests/RecursionLimitExceededTest.php b/tests/RecursionLimitExceededTest.php new file mode 100644 index 0000000..f0bf5e3 --- /dev/null +++ b/tests/RecursionLimitExceededTest.php @@ -0,0 +1,17 @@ +assertEquals("Recursion limit exceeded: '12'", $exception->getMessage()); + } +} diff --git a/tests/RequiredValueEmptyTest.php b/tests/RequiredValueEmptyTest.php new file mode 100644 index 0000000..f50d20c --- /dev/null +++ b/tests/RequiredValueEmptyTest.php @@ -0,0 +1,17 @@ +assertEquals("The Required value 'name' is empty (expected: 'string3')", $exception->getMessage()); + } +} diff --git a/tests/SerializeExceptionTest.php b/tests/SerializeExceptionTest.php new file mode 100644 index 0000000..e2e6af3 --- /dev/null +++ b/tests/SerializeExceptionTest.php @@ -0,0 +1,17 @@ +assertEquals("Serialize process was failed (type:'phpserialize', object:'stdClass', src:'stdClass'). reason", $exception->getMessage()); + } +}