From fa34cdc8e8cfd5220f67ea1b8734fefa369dd24d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 2 Sep 2021 03:43:08 +0200 Subject: [PATCH 1/2] Exception\Transport\Curl: add perfunctory unit tests --- tests/Exception/Transport/CurlTest.php | 129 +++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 tests/Exception/Transport/CurlTest.php diff --git a/tests/Exception/Transport/CurlTest.php b/tests/Exception/Transport/CurlTest.php new file mode 100644 index 000000000..40596241e --- /dev/null +++ b/tests/Exception/Transport/CurlTest.php @@ -0,0 +1,129 @@ +expectException(Curl::class); + $this->expectExceptionMessage($expected_msg); + $this->expectExceptionCode($expected_code); + + $exception = new Curl($message, $type, $data, $code); + + $this->assertSame($expected_reason, $exception->getReason()); + + throw $exception; + } + + /** + * Data provider. + * + * @return array + */ + public function dataException() { + return array( + 'Everything set to null (or not passed)' => array( + 'expected_msg' => '-1 Unknown', + 'expected_code' => -1, + 'expected_reason' => 'Unknown', + 'message' => null, + 'type' => null, + 'data' => null, + 'code' => null, + ), + 'Message passed, everything else set to null (or not passed)' => array( + 'expected_msg' => '-1 testing-1-2-3', + 'expected_code' => -1, + 'expected_reason' => 'testing-1-2-3', + 'message' => 'testing-1-2-3', + 'type' => null, + 'data' => null, + 'code' => null, + ), + 'Type passed, everything else set to null (or not passed)' => array( + 'expected_msg' => '-1 Unknown', + 'expected_code' => -1, + 'expected_reason' => 'Unknown', + 'message' => null, + 'type' => Curl::EASY, + 'data' => null, + 'code' => null, + ), + 'Code passed, everything else set to null (or not passed)' => array( + 'expected_msg' => CURLE_COULDNT_RESOLVE_HOST . ' Unknown', + 'expected_code' => CURLE_COULDNT_RESOLVE_HOST, + 'expected_reason' => 'Unknown', + 'message' => null, + 'type' => null, + 'data' => null, + 'code' => CURLE_COULDNT_RESOLVE_HOST, + ), + 'Message and type passed, everything else set to null (or not passed)' => array( + 'expected_msg' => '-1 testing-1-2-3', + 'expected_code' => -1, + 'expected_reason' => 'testing-1-2-3', + 'message' => 'testing-1-2-3', + 'type' => Curl::EASY, + 'data' => null, + 'code' => null, + ), + 'Message and code passed, everything else set to null (or not passed)' => array( + 'expected_msg' => CURLE_COULDNT_RESOLVE_HOST . ' testing-1-2-3', + 'expected_code' => CURLE_COULDNT_RESOLVE_HOST, + 'expected_reason' => 'testing-1-2-3', + 'message' => 'testing-1-2-3', + 'type' => null, + 'data' => null, + 'code' => CURLE_COULDNT_RESOLVE_HOST, + ), + 'Type and code passed, everything else set to null (or not passed)' => array( + 'expected_msg' => CURLE_COULDNT_RESOLVE_HOST . ' Unknown', + 'expected_code' => CURLE_COULDNT_RESOLVE_HOST, + 'expected_reason' => 'Unknown', + 'message' => null, + 'type' => Curl::EASY, + 'data' => null, + 'code' => CURLE_COULDNT_RESOLVE_HOST, + ), + 'Everything set; code not integer' => array( + 'expected_msg' => '61 testing-1-2-3', + 'expected_code' => 61, + 'expected_reason' => 'testing-1-2-3', + 'message' => 'testing-1-2-3', + 'type' => Curl::EASY, + 'data' => array(), + 'code' => '61 text', + ), + ); + } +} From e94251fdb4159703c625d8a1134d95c949fe255d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 2 Sep 2021 03:44:03 +0200 Subject: [PATCH 2/2] Exception\Transport\Curl: minor fix The error code should always be an integer. --- src/Exception/Transport/Curl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Exception/Transport/Curl.php b/src/Exception/Transport/Curl.php index c74d39261..2127bf306 100644 --- a/src/Exception/Transport/Curl.php +++ b/src/Exception/Transport/Curl.php @@ -47,7 +47,7 @@ public function __construct($message, $type, $data = null, $code = 0) { } if ($code !== null) { - $this->code = $code; + $this->code = (int) $code; } if ($message !== null) {