Skip to content

Commit

Permalink
Corona: Fix unit test errors for PHP 8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
pprkut committed Jan 19, 2024
1 parent 9cc6ad3 commit 289de78
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/Lunr/Corona/Tests/JsonViewPrintExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
{
Expand All @@ -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')
Expand All @@ -74,6 +77,7 @@ public function testPrintExceptionForWebPrintsJson(): void
$this->class->print_exception($exception);

$this->unmock_function('header');
$this->unmock_function('http_response_code');
}

}
Expand Down
12 changes: 8 additions & 4 deletions src/Lunr/Corona/Tests/JsonViewPrintFatalErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
/**
* This class contains tests for the JsonView class.
*
* @covers Lunr\Corona\JsonView
* @covers Lunr\Corona\JsonView
*/
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
{
Expand All @@ -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
{
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -95,6 +98,7 @@ public function testPrintFatalErrorForWebPrintsJson(): void

$this->unmock_function('error_get_last');
$this->unmock_function('header');
$this->unmock_function('http_response_code');
}

}
Expand Down
12 changes: 11 additions & 1 deletion src/Lunr/Corona/Tests/JsonViewPrintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* This class contains tests for the JsonView class.
*
* @covers Lunr\Corona\JsonView
* @covers Lunr\Corona\JsonView
*/
class JsonViewPrintTest extends JsonViewTest
{
Expand Down Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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');
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Lunr/Corona/Tests/MsgpackViewPrintExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

}
Expand Down
2 changes: 2 additions & 0 deletions src/Lunr/Corona/Tests/MsgpackViewPrintFatalErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ 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');

$this->class->print_fatal_error();

$this->unmock_function('error_get_last');
$this->unmock_function('header');
$this->unmock_function('http_response_code');
}

}
Expand Down
8 changes: 8 additions & 0 deletions src/Lunr/Corona/Tests/MsgpackViewPrintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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');
}

/**
Expand Down

0 comments on commit 289de78

Please sign in to comment.