From 289de78172e605e97246c56ccd904e680bbde094 Mon Sep 17 00:00:00 2001 From: Heinz Wiesinger Date: Sat, 9 Dec 2023 18:24:20 +0100 Subject: [PATCH] Corona: Fix unit test errors for PHP 8.3 Reviewed at https://reviews.lunr.nl/r/1092/ --- src/Lunr/Corona/Tests/JsonViewPrintExceptionTest.php | 6 +++++- .../Corona/Tests/JsonViewPrintFatalErrorTest.php | 12 ++++++++---- src/Lunr/Corona/Tests/JsonViewPrintTest.php | 12 +++++++++++- .../Corona/Tests/MsgpackViewPrintExceptionTest.php | 2 ++ .../Corona/Tests/MsgpackViewPrintFatalErrorTest.php | 2 ++ src/Lunr/Corona/Tests/MsgpackViewPrintTest.php | 8 ++++++++ 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/Lunr/Corona/Tests/JsonViewPrintExceptionTest.php b/src/Lunr/Corona/Tests/JsonViewPrintExceptionTest.php index d62566cd..dd6935d0 100644 --- a/src/Lunr/Corona/Tests/JsonViewPrintExceptionTest.php +++ b/src/Lunr/Corona/Tests/JsonViewPrintExceptionTest.php @@ -33,6 +33,7 @@ public function testPrintExceptionPrintsPrettyJson(): void $exception->setLine(100); $this->mock_function('header', function () {}); + $this->mock_function('http_response_code', function () {}); $this->request->expects($this->once()) ->method('__get') @@ -44,12 +45,13 @@ public function testPrintExceptionPrintsPrettyJson(): void $this->class->print_exception($exception); $this->unmock_function('header'); + $this->unmock_function('http_response_code'); } /** * Test that print_exception() prints a json object if there is an exception. * - * @covers Lunr\Corona\JsonView::print_exception + * @covers Lunr\Corona\JsonView::print_exception */ public function testPrintExceptionForWebPrintsJson(): void { @@ -59,6 +61,7 @@ public function testPrintExceptionForWebPrintsJson(): void $exception->setLine(100); $this->mock_function('header', function () {}); + $this->mock_function('http_response_code', function () {}); $this->request->expects($this->once()) ->method('__get') @@ -74,6 +77,7 @@ public function testPrintExceptionForWebPrintsJson(): void $this->class->print_exception($exception); $this->unmock_function('header'); + $this->unmock_function('http_response_code'); } } diff --git a/src/Lunr/Corona/Tests/JsonViewPrintFatalErrorTest.php b/src/Lunr/Corona/Tests/JsonViewPrintFatalErrorTest.php index cf2d2cce..a1c8be15 100644 --- a/src/Lunr/Corona/Tests/JsonViewPrintFatalErrorTest.php +++ b/src/Lunr/Corona/Tests/JsonViewPrintFatalErrorTest.php @@ -13,7 +13,7 @@ /** * This class contains tests for the JsonView class. * - * @covers Lunr\Corona\JsonView + * @covers Lunr\Corona\JsonView */ class JsonViewPrintFatalErrorTest extends JsonViewTest { @@ -21,7 +21,7 @@ class JsonViewPrintFatalErrorTest extends JsonViewTest /** * Test that print_fatal_error() does not print an error page if there is no error. * - * @covers Lunr\Corona\JsonView::print_fatal_error + * @covers Lunr\Corona\JsonView::print_fatal_error */ public function testPrintFatalErrorPrintsNothingIfNoError(): void { @@ -37,7 +37,7 @@ public function testPrintFatalErrorPrintsNothingIfNoError(): void /** * Test that print_fatal_error() does not print an error page if there is no fatal error. * - * @covers Lunr\Corona\JsonView::print_fatal_error + * @covers Lunr\Corona\JsonView::print_fatal_error */ public function testPrintFatalErrorPrintsNothingIfErrorNotFatal(): void { @@ -60,6 +60,7 @@ public function testPrintFatalErrorPrintsPrettyJson(): void { $this->mock_function('error_get_last', function () { return [ 'type' => 1, 'message' => 'Message', 'file' => 'index.php', 'line' => 2 ]; }); $this->mock_function('header', function () {}); + $this->mock_function('http_response_code', function () {}); $this->request->expects($this->once()) ->method('__get') @@ -72,17 +73,19 @@ public function testPrintFatalErrorPrintsPrettyJson(): void $this->unmock_function('error_get_last'); $this->unmock_function('header'); + $this->unmock_function('http_response_code'); } /** * Test that print_fatal_error() does prints a json object if there is a fatal error. * - * @covers Lunr\Corona\JsonView::print_fatal_error + * @covers Lunr\Corona\JsonView::print_fatal_error */ public function testPrintFatalErrorForWebPrintsJson(): void { $this->mock_function('error_get_last', function () { return [ 'type' => 1, 'message' => 'Message', 'file' => 'index.php', 'line' => 2 ]; }); $this->mock_function('header', function () {}); + $this->mock_function('http_response_code', function () {}); $this->request->expects($this->once()) ->method('__get') @@ -95,6 +98,7 @@ public function testPrintFatalErrorForWebPrintsJson(): void $this->unmock_function('error_get_last'); $this->unmock_function('header'); + $this->unmock_function('http_response_code'); } } diff --git a/src/Lunr/Corona/Tests/JsonViewPrintTest.php b/src/Lunr/Corona/Tests/JsonViewPrintTest.php index 11c9cb13..ead75c8a 100644 --- a/src/Lunr/Corona/Tests/JsonViewPrintTest.php +++ b/src/Lunr/Corona/Tests/JsonViewPrintTest.php @@ -13,7 +13,7 @@ /** * This class contains tests for the JsonView class. * - * @covers Lunr\Corona\JsonView + * @covers Lunr\Corona\JsonView */ class JsonViewPrintTest extends JsonViewTest { @@ -77,10 +77,12 @@ public function testPrintPagePrintsJsonWithCode($error_info): void $this->expectOutputMatchesFile(TEST_STATICS . '/Corona/json_code.json'); $this->mock_function('header', function () {}); + $this->mock_function('http_response_code', function () {}); $this->class->print_page(); $this->unmock_function('header'); + $this->unmock_function('http_response_code'); } /** @@ -123,10 +125,12 @@ public function testPrintPagePrintsJsonWithoutMessage(): void $this->expectOutputMatchesFile(TEST_STATICS . '/Corona/json_empty_message.json'); $this->mock_function('header', function () {}); + $this->mock_function('http_response_code', function () {}); $this->class->print_page(); $this->unmock_function('header'); + $this->unmock_function('http_response_code'); } /** @@ -169,10 +173,12 @@ public function testPrintPagePrintsJson(): void $this->expectOutputMatchesFile(TEST_STATICS . '/Corona/json_complete.json'); $this->mock_function('header', function () {}); + $this->mock_function('http_response_code', function () {}); $this->class->print_page(); $this->unmock_function('header'); + $this->unmock_function('http_response_code'); } /** @@ -214,10 +220,12 @@ public function testPrintPageForWebDoesNotPrettyPrint(): void $this->expectOutputString('{"data":{"a":100,"b":{"z":true},"c":[null],"d":{},"e":"みんな"},"status":{"code":4040,"message":"Message"}}'); $this->mock_function('header', function () {}); + $this->mock_function('http_response_code', function () {}); $this->class->print_page(); $this->unmock_function('header'); + $this->unmock_function('http_response_code'); } /** @@ -260,10 +268,12 @@ public function testPrintPageWithEmptyData(): void $this->expectOutputMatchesFile(TEST_STATICS . '/Corona/json_empty_data.json'); $this->mock_function('header', function () {}); + $this->mock_function('http_response_code', function () {}); $this->class->print_page(); $this->unmock_function('header'); + $this->unmock_function('http_response_code'); } /** diff --git a/src/Lunr/Corona/Tests/MsgpackViewPrintExceptionTest.php b/src/Lunr/Corona/Tests/MsgpackViewPrintExceptionTest.php index ede615b3..b4b666f1 100644 --- a/src/Lunr/Corona/Tests/MsgpackViewPrintExceptionTest.php +++ b/src/Lunr/Corona/Tests/MsgpackViewPrintExceptionTest.php @@ -33,12 +33,14 @@ public function testPrintExceptionPrintsMsgpack(): void $exception->setLine(100); $this->mock_function('header', function () {}); + $this->mock_function('http_response_code', function () {}); $this->expectOutputMatchesFile(TEST_STATICS . '/Corona/msgpack_exception.msgpack'); $this->class->print_exception($exception); $this->unmock_function('header'); + $this->unmock_function('http_response_code'); } } diff --git a/src/Lunr/Corona/Tests/MsgpackViewPrintFatalErrorTest.php b/src/Lunr/Corona/Tests/MsgpackViewPrintFatalErrorTest.php index b08028ea..4efc37d7 100644 --- a/src/Lunr/Corona/Tests/MsgpackViewPrintFatalErrorTest.php +++ b/src/Lunr/Corona/Tests/MsgpackViewPrintFatalErrorTest.php @@ -65,6 +65,7 @@ public function testPrintFatalErrorPrintsMsgpack(): void { $this->mock_function('error_get_last', fn() => [ 'type' => 1, 'message' => 'Message', 'file' => 'index.php', 'line' => 2 ]); $this->mock_function('header', function () {}); + $this->mock_function('http_response_code', function () {}); $this->expectOutputMatchesFile(TEST_STATICS . '/Corona/msgpack_error.msgpack'); @@ -72,6 +73,7 @@ public function testPrintFatalErrorPrintsMsgpack(): void $this->unmock_function('error_get_last'); $this->unmock_function('header'); + $this->unmock_function('http_response_code'); } } diff --git a/src/Lunr/Corona/Tests/MsgpackViewPrintTest.php b/src/Lunr/Corona/Tests/MsgpackViewPrintTest.php index 35be6af9..f26c9762 100644 --- a/src/Lunr/Corona/Tests/MsgpackViewPrintTest.php +++ b/src/Lunr/Corona/Tests/MsgpackViewPrintTest.php @@ -72,10 +72,12 @@ public function testPrintPagePrintsmsgpackWithCode($error_info): void $this->expectOutputMatchesFile(TEST_STATICS . '/Corona/msgpack_code.msgpack'); $this->mock_function('header', function () {}); + $this->mock_function('http_response_code', function () {}); $this->class->print_page(); $this->unmock_function('header'); + $this->unmock_function('http_response_code'); } /** @@ -113,10 +115,12 @@ public function testPrintPagePrintsmsgpackWithoutMessage(): void $this->expectOutputMatchesFile(TEST_STATICS . '/Corona/msgpack_empty_message.msgpack'); $this->mock_function('header', function () {}); + $this->mock_function('http_response_code', function () {}); $this->class->print_page(); $this->unmock_function('header'); + $this->unmock_function('http_response_code'); } /** @@ -154,10 +158,12 @@ public function testPrintPagePrintsmsgpack(): void $this->expectOutputMatchesFile(TEST_STATICS . '/Corona/msgpack_complete.msgpack'); $this->mock_function('header', function () {}); + $this->mock_function('http_response_code', function () {}); $this->class->print_page(); $this->unmock_function('header'); + $this->unmock_function('http_response_code'); } /** @@ -195,10 +201,12 @@ public function testPrintPageWithEmptyData(): void $this->expectOutputMatchesFile(TEST_STATICS . '/Corona/msgpack_empty_data.msgpack'); $this->mock_function('header', function () {}); + $this->mock_function('http_response_code', function () {}); $this->class->print_page(); $this->unmock_function('header'); + $this->unmock_function('http_response_code'); } /**