refactor: update PHPUnit to 10 - #8069

Merged
kenjis merged 17 commits into
codeigniter4:4.5from
kenjis:update-phpunit-10
Apr 7, 2024
Merged

refactor: update PHPUnit to 10#8069
kenjis merged 17 commits into
codeigniter4:4.5from
kenjis:update-phpunit-10

Conversation

@kenjis

@kenjiskenjis commented Oct 20, 2023

Copy link
Copy Markdown
Member

Important

This PR will be merged just prior to the release of v4.5.0.

Description
PHPUnit requires PHP 8.1 or later.
https://packagist.org/packages/phpunit/phpunit#10.4.1

https://phpunit.de/announcements/phpunit-10.html

TODO

  • update nexusphp/tachycardia
  • fix errors on PHP 8.3

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjiskenjis added the 4.5 label Oct 20, 2023
@kenjis
kenjis marked this pull request as draft October 20, 2023 23:57
@kenjis

Copy link
Copy Markdown
MemberAuthor

@paulbalandan Any plan to release nexusphp/tachycardia that are compatible with PHPUnit10?

@paulbalandan

Copy link
Copy Markdown
Member

Is it ready but lacking integration tests. I'll try to finish this weekend. Thanks for reminding me.

@kenjis

Copy link
Copy Markdown
MemberAuthor
There was 1 PHPUnit test runner warning:
1) Class CodeIgniter\Cache\Handlers\AbstractHandlerTest declared in /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Cache/Handlers/AbstractHandlerTest.php is abstract
--
There was 1 PHPUnit test runner deprecation:
1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
--
6 tests triggered 6 PHPUnit deprecations:
1) CodeIgniter\AutoReview\FrameworkCodeTest::testEachTestClassHasCorrectGroupAnnotation
Data Provider method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAnnotation() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/AutoReview/FrameworkCodeTest.php:46
2) CodeIgniter\HTTP\SiteURITest::testConstructor
Data Provider method CodeIgniter\HTTP\SiteURITest::provideConstructor() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/HTTP/SiteURITest.php:32
3) CodeIgniter\Validation\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/CreditCardRulesTest.php:54
4) CodeIgniter\Validation\StrictRules\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\StrictRules\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/StrictRules/CreditCardRulesTest.php:55
5) CodeIgniter\Validation\StrictRules\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\StrictRules\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
6) CodeIgniter\Validation\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
WARNINGS!
Tests: 300, Assertions: 905, Warnings: 1, Deprecations: 7.

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6593809502/job/17916840733?pr=8069

@kenjis

Copy link
Copy Markdown
MemberAuthor
There was 1 PHPUnit test runner warning:
1) Class CodeIgniter\Cache\Handlers\AbstractHandlerTest declared in /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Cache/Handlers/AbstractHandlerTest.php is abstract
--
There was 1 PHPUnit test runner deprecation:
1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
--
There were 41 errors:
1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpers
Test was run in child process and ended unexpectedly
2) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRoute
Test was run in child process and ended unexpectedly
3) CodeIgniter\CodeIgniterTest::testOutputBufferingControl
Test was run in child process and ended unexpectedly
4) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRouteReturnResponse
Test was run in child process and ended unexpectedly
5) CodeIgniter\CodeIgniterTest::testRunClosureRoute
Test was run in child process and ended unexpectedly
6) CodeIgniter\CodeIgniterTest::testRun404Override
Test was run in child process and ended unexpectedly
7) CodeIgniter\CodeIgniterTest::testRun404OverrideControllerReturnsResponse
Test was run in child process and ended unexpectedly
8) CodeIgniter\CodeIgniterTest::testRun404OverrideReturnResponse
Test was run in child process and ended unexpectedly
9) CodeIgniter\CodeIgniterTest::testRun404OverrideByClosure
Test was run in child process and ended unexpectedly
1) CodeIgniter\Validation\StrictRules\ValidationTest::testPlaceholderReplacementTestFails
Failed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.
2) CodeIgniter\Validation\ValidationTest::testPlaceholderReplacementTestFails
Failed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.
--
6 tests triggered 6 PHPUnit deprecations:
1) CodeIgniter\AutoReview\FrameworkCodeTest::testEachTestClassHasCorrectGroupAnnotation
Data Provider method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAnnotation() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/AutoReview/FrameworkCodeTest.php:46
2) CodeIgniter\HTTP\SiteURITest::testConstructor
Data Provider method CodeIgniter\HTTP\SiteURITest::provideConstructor() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/HTTP/SiteURITest.php:32
3) CodeIgniter\Validation\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/CreditCardRulesTest.php:54
4) CodeIgniter\Validation\StrictRules\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\StrictRules\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/StrictRules/CreditCardRulesTest.php:55
5) CodeIgniter\Validation\StrictRules\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\StrictRules\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
6) CodeIgniter\Validation\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
ERRORS!
Tests: 5017, Assertions: 8400, Errors: 41, Failures: 2, Warnings: 1, Deprecations: 7, Skipped: 1.

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6593809497/job/17916881103?pr=8069

@paulbalandan

Copy link
Copy Markdown
Member

The first warning is easy. Just change the name to AbstractHandlerTestCase. Abstract tests need to be suffixed with TestCase.

For the static issues, just run the rule php_unit_data_provider_static for php-cs-fixer

@kenjis

Copy link
Copy Markdown
MemberAuthor

Unfortunately php-cs-fixer was not able to refactor the dataProviders because of $this.

@paulbalandan

Copy link
Copy Markdown
Member

Ah yes. The rule is risky because of uses of $this. Those cases should be modified to use static properties/methods.

@kenjis

Copy link
Copy Markdown
MemberAuthor

Why does this test fail?

$ vendor/bin/phpunit tests/system/Validation/StrictRules/ValidationTest.php PHPUnit 10.4.1 by Sebastian Bergmann and contributors.Runtime: PHP 8.1.24Configuration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml.................................................................................................... 100 / 121 ( 82%)...........F......... 121 / 121 (100%)Time: 00:00.930, Memory: 16.00 MB...--There was 1 failure:1) CodeIgniter\Validation\StrictRules\ValidationTest::testPlaceholderReplacementTestFailsFailed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.FAILURES!Tests: 121, Assertions: 173, Failures: 1, Warnings: 1.

@kenjis

Copy link
Copy Markdown
MemberAuthor

I got the reason. The error message of PHPUnit has been changed.

@MGatnerMGatner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will want to update DevKit as well - not sure when the appropriate time to do that is though, maybe when we actually drop 8.0? I know @paulbalandan is working on Tachycardia comparability - that would be great to include.

Edit: oops! I missed the existing conversation. All good.

@paulbalandan

Copy link
Copy Markdown
Member

nexusphp/tachycardia v2.0 is out

@kenjis
kenjisforce-pushed the update-phpunit-10 branch 2 times, most recently from 2052f1a to a524abcCompareOctober 27, 2023 04:39
@kenjis

Copy link
Copy Markdown
MemberAuthor

I don't know why, but only in PHP 8.3, the NoTestCaseObjectOnCallStackException occurs.

$ vendor/bin/phpunit tests/system/Autoloader/AutoloaderTest.php PHPUnit 10.4.2 by Sebastian Bergmann and contributors.Runtime: PHP 8.3.0-devConfiguration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml..........................E 27 / 27 (100%)Time: 00:00.486, Memory: 16.00 MBThere was 1 error:1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpersPHPUnit\Framework\Exception: PHP Fatal error: Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44Stack trace:#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter->format(Array)#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler->format(Array)#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\Debug\ExceptionHandler->handle(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException))#6 {main} thrown in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php on line 44ERRORS!Tests: 27, Assertions: 45, Errors: 1.

@kenjiskenjis added the help wanted More help is needed for the proper resolution of an issue or pull request label Oct 27, 2023
@kenjis

Copy link
Copy Markdown
MemberAuthor
--- a/system/Format/JSONFormatter.php+++ b/system/Format/JSONFormatter.php@@ -37,6 +37,7 @@ class JSONFormatter implements FormatterInterface
$options = ENVIRONMENT === 'production' ? $options : $options | JSON_PRETTY_PRINT;
+ log_message('debug', var_export($data, true));
$result = json_encode($data, $options, 512);
if (! in_array(json_last_error(), [JSON_ERROR_NONE, JSON_ERROR_RECURSION], true)) {
CRITICAL - 2023-10-27 07:08:34 --> Cannot find TestCase object on call stack
in VENDORPATH/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php on line 63.
1 VENDORPATH/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
2 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke(2, 'rewind(): Stream does not support seeking', 'Standard input code', 71)
3 Standard input code(71): rewind(resource (stream))
4 Standard input code(118): __phpunit_run_isolated_test()
DEBUG - 2023-10-27 07:08:34 --> array (
'title' => 'PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException',
'type' => 'PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException',
'code' => 500,
'message' => 'Cannot find TestCase object on call stack',
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php',
'line' => 63,
'trace' => array (
0 => array (
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php',
'line' => 83,
'function' => 'fromCallStack',
'class' => 'PHPUnit\\Event\\Code\\TestMethodBuilder',
'type' => '::',
'args' => array (
),
),
1 => array (
'function' => '__invoke',
'class' => 'PHPUnit\\Runner\\ErrorHandler',
'type' => '->',
'args' => array (
0 => 2,
1 => 'rewind(): Stream does not support seeking',
2 => 'Standard input code',
3 => 71,
),
),
2 => array (
'file' => 'Standard input code',
'line' => 71,
'function' => 'rewind',
'args' => array (
0 => NULL,
),
),
3 => array (
'file' => 'Standard input code',
'line' => 118,
'function' => '__phpunit_run_isolated_test',
'args' => array (
),
),
),
)
CRITICAL - 2023-10-27 07:08:34 --> Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter->format(Array)
#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler->format(Array)
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\Debug\ExceptionHandler->handle(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)
#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException))
#6 {main}
thrown
【Previous Exception】
PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException
Cannot find TestCase object on call stack
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke(2, 'rewind(): Strea...', 'Standard input ...', 71)
#2 Standard input code(71): rewind(Resource id #2)
#3 Standard input code(118): __phpunit_run_isolated_test()
#4 {main}
in SYSTEMPATH/Format/JSONFormatter.php on line 44.
1 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
DEBUG - 2023-10-27 07:08:34 --> array (
'title' => 'ErrorException',
'type' => 'ErrorException',
'code' => 500,
'message' => 'Uncaught CodeIgniter\\Format\\Exceptions\\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\\Format\\Exceptions\\FormatException::forInvalidJSON(\'Type is not sup...\')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\\Format\\JSONFormatter->format(Array)
#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\\Debug\\ExceptionHandler->format(Array)
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\\Debug\\ExceptionHandler->respond(Array, 500)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\\Debug\\ExceptionHandler->handle(Object(PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\\HTTP\\IncomingRequest), Object(CodeIgniter\\HTTP\\Response), 500, 1)
#5 [internal function]: CodeIgniter\\Debug\\Exceptions->exceptionHandler(Object(PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException))
#6 {main}
thrown
【Previous Exception】
PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException
Cannot find TestCase object on call stack
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\\Event\\Code\\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\\Runner\\ErrorHandler->__invoke(2, \'rewind(): Strea...\', \'Standard input ...\', 71)
#2 Standard input code(71): rewind(Resource id #2)
#3 Standard input code(118): __phpunit_run_isolated_test()
#4 {main}',
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php',
'line' => 44,
'trace' => array (
0 => array (
'function' => 'shutdownHandler',
'class' => 'CodeIgniter\\Debug\\Exceptions',
'type' => '->',
'args' => array (
),
),
),
)

@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Oct 28, 2023
@github-actions

This comment was marked as outdated.

@kenjiskenjis removed the stale Pull requests with conflicts label Oct 30, 2023
@github-actions

This comment was marked as outdated.

@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Nov 30, 2023
@kenjiskenjis removed the stale Pull requests with conflicts label Nov 30, 2023
@kenjis

Copy link
Copy Markdown
MemberAuthor

No good. Tests on PHP 8.3 fails.

There were 42 errors:
1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpers
Test was run in child process and ended unexpectedly
2) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRoute
Test was run in child process and ended unexpectedly
3) CodeIgniter\CodeIgniterTest::testOutputBufferingControl
Test was run in child process and ended unexpectedly

https://github.com/codeigniter4/CodeIgniter4/actions/runs/7043858533/job/19170759175?pr=8069

@kenjis
kenjisforce-pushed the update-phpunit-10 branch 2 times, most recently from 5b2f18f to 47bf62eCompareApril 2, 2024 23:26
@kenjis
kenjis marked this pull request as ready for review April 2, 2024 23:45
@kenjiskenjis changed the title chore: update PHPUnit to 10refactor: update PHPUnit to 10Apr 2, 2024
@kenjis
kenjisforce-pushed the update-phpunit-10 branch from 47bf62e to fe41852CompareApril 6, 2024 00:26
kenjis added 17 commits April 7, 2024 12:38
vendor/bin/phpunit --migrate-configuration -c phpunit.xml.dist
Message: file_put_contents(/home/runner/work/CodeIgniter4/CodeIgniter4/build/coverage/text/coverage.txt): Failed to open stream: No such file or directory
Location: /home/runner/work/CodeIgniter4/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/CodeCoverage.php:317
Script done.
Error: Process completed with exit code 255.
1) CodeIgniter\Database\DatabaseTestCase\DatabaseTestCaseMigrationOnce1Test::testMigrationDone
TypeError: json_encode(): Argument #2 ($flags) must be of type int, bool given
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/Constraints/SeeInDatabase.php:118
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:282
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce1Test.php:86
There was 1 error:
1) CodeIgniter\Security\SecurityCSRFSessionRandomizeTokenTest::testCSRFVerifyPostInvalidToken
PHPUnit\Framework\Exception: PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Security/Security.php on line 378
PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Security/Security.php on line 378
There was 1 error:
1) CodeIgniter\CommonFunctionsTest::testTraceWithCSP
Test was run in child process and ended unexpectedly
@kenjis
kenjisforce-pushed the update-phpunit-10 branch from fe41852 to 9e009e9CompareApril 7, 2024 03:38
@kenjis

Copy link
Copy Markdown
MemberAuthor

Rebased to resolve the conflict.

@kenjis
kenjis merged commit 5c45ef1 into codeigniter4:4.5Apr 7, 2024
@kenjis
kenjis deleted the update-phpunit-10 branch April 7, 2024 03:57
@MGatner

Copy link
Copy Markdown
Member

Happy to see this one launched!

@kenjis

Copy link
Copy Markdown
MemberAuthor

But we still need restore_error_handler() to separate process testing.
I don't know the true cause of the errors.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wantedMore help is needed for the proper resolution of an issue or pull requestrefactorPull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@kenjis@paulbalandan@datamweb@MGatner@michalsn@samsonasik
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

refactor: update PHPUnit to 10 - #8069

Merged
kenjis merged 17 commits into
codeigniter4:4.5from
kenjis:update-phpunit-10
Apr 7, 2024
Merged

refactor: update PHPUnit to 10#8069
kenjis merged 17 commits into
codeigniter4:4.5from
kenjis:update-phpunit-10

Conversation

@kenjis

@kenjiskenjis commented Oct 20, 2023

Copy link
Copy Markdown
Member

Important

This PR will be merged just prior to the release of v4.5.0.

Description
PHPUnit requires PHP 8.1 or later.
https://packagist.org/packages/phpunit/phpunit#10.4.1

https://phpunit.de/announcements/phpunit-10.html

TODO

  • update nexusphp/tachycardia
  • fix errors on PHP 8.3

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjiskenjis added the 4.5 label Oct 20, 2023
@kenjis
kenjis marked this pull request as draft October 20, 2023 23:57
@kenjis

Copy link
Copy Markdown
MemberAuthor

@paulbalandan Any plan to release nexusphp/tachycardia that are compatible with PHPUnit10?

@paulbalandan

Copy link
Copy Markdown
Member

Is it ready but lacking integration tests. I'll try to finish this weekend. Thanks for reminding me.

@kenjis

Copy link
Copy Markdown
MemberAuthor
There was 1 PHPUnit test runner warning:
1) Class CodeIgniter\Cache\Handlers\AbstractHandlerTest declared in /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Cache/Handlers/AbstractHandlerTest.php is abstract
--
There was 1 PHPUnit test runner deprecation:
1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
--
6 tests triggered 6 PHPUnit deprecations:
1) CodeIgniter\AutoReview\FrameworkCodeTest::testEachTestClassHasCorrectGroupAnnotation
Data Provider method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAnnotation() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/AutoReview/FrameworkCodeTest.php:46
2) CodeIgniter\HTTP\SiteURITest::testConstructor
Data Provider method CodeIgniter\HTTP\SiteURITest::provideConstructor() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/HTTP/SiteURITest.php:32
3) CodeIgniter\Validation\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/CreditCardRulesTest.php:54
4) CodeIgniter\Validation\StrictRules\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\StrictRules\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/StrictRules/CreditCardRulesTest.php:55
5) CodeIgniter\Validation\StrictRules\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\StrictRules\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
6) CodeIgniter\Validation\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
WARNINGS!
Tests: 300, Assertions: 905, Warnings: 1, Deprecations: 7.

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6593809502/job/17916840733?pr=8069

@kenjis

Copy link
Copy Markdown
MemberAuthor
There was 1 PHPUnit test runner warning:
1) Class CodeIgniter\Cache\Handlers\AbstractHandlerTest declared in /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Cache/Handlers/AbstractHandlerTest.php is abstract
--
There was 1 PHPUnit test runner deprecation:
1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
--
There were 41 errors:
1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpers
Test was run in child process and ended unexpectedly
2) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRoute
Test was run in child process and ended unexpectedly
3) CodeIgniter\CodeIgniterTest::testOutputBufferingControl
Test was run in child process and ended unexpectedly
4) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRouteReturnResponse
Test was run in child process and ended unexpectedly
5) CodeIgniter\CodeIgniterTest::testRunClosureRoute
Test was run in child process and ended unexpectedly
6) CodeIgniter\CodeIgniterTest::testRun404Override
Test was run in child process and ended unexpectedly
7) CodeIgniter\CodeIgniterTest::testRun404OverrideControllerReturnsResponse
Test was run in child process and ended unexpectedly
8) CodeIgniter\CodeIgniterTest::testRun404OverrideReturnResponse
Test was run in child process and ended unexpectedly
9) CodeIgniter\CodeIgniterTest::testRun404OverrideByClosure
Test was run in child process and ended unexpectedly
1) CodeIgniter\Validation\StrictRules\ValidationTest::testPlaceholderReplacementTestFails
Failed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.
2) CodeIgniter\Validation\ValidationTest::testPlaceholderReplacementTestFails
Failed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.
--
6 tests triggered 6 PHPUnit deprecations:
1) CodeIgniter\AutoReview\FrameworkCodeTest::testEachTestClassHasCorrectGroupAnnotation
Data Provider method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAnnotation() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/AutoReview/FrameworkCodeTest.php:46
2) CodeIgniter\HTTP\SiteURITest::testConstructor
Data Provider method CodeIgniter\HTTP\SiteURITest::provideConstructor() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/HTTP/SiteURITest.php:32
3) CodeIgniter\Validation\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/CreditCardRulesTest.php:54
4) CodeIgniter\Validation\StrictRules\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\StrictRules\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/StrictRules/CreditCardRulesTest.php:55
5) CodeIgniter\Validation\StrictRules\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\StrictRules\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
6) CodeIgniter\Validation\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
ERRORS!
Tests: 5017, Assertions: 8400, Errors: 41, Failures: 2, Warnings: 1, Deprecations: 7, Skipped: 1.

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6593809497/job/17916881103?pr=8069

@paulbalandan

Copy link
Copy Markdown
Member

The first warning is easy. Just change the name to AbstractHandlerTestCase. Abstract tests need to be suffixed with TestCase.

For the static issues, just run the rule php_unit_data_provider_static for php-cs-fixer

@kenjis

Copy link
Copy Markdown
MemberAuthor

Unfortunately php-cs-fixer was not able to refactor the dataProviders because of $this.

@paulbalandan

Copy link
Copy Markdown
Member

Ah yes. The rule is risky because of uses of $this. Those cases should be modified to use static properties/methods.

@kenjis

Copy link
Copy Markdown
MemberAuthor

Why does this test fail?

$ vendor/bin/phpunit tests/system/Validation/StrictRules/ValidationTest.php PHPUnit 10.4.1 by Sebastian Bergmann and contributors.Runtime: PHP 8.1.24Configuration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml.................................................................................................... 100 / 121 ( 82%)...........F......... 121 / 121 (100%)Time: 00:00.930, Memory: 16.00 MB...--There was 1 failure:1) CodeIgniter\Validation\StrictRules\ValidationTest::testPlaceholderReplacementTestFailsFailed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.FAILURES!Tests: 121, Assertions: 173, Failures: 1, Warnings: 1.

@kenjis

Copy link
Copy Markdown
MemberAuthor

I got the reason. The error message of PHPUnit has been changed.

@MGatnerMGatner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will want to update DevKit as well - not sure when the appropriate time to do that is though, maybe when we actually drop 8.0? I know @paulbalandan is working on Tachycardia comparability - that would be great to include.

Edit: oops! I missed the existing conversation. All good.

@paulbalandan

Copy link
Copy Markdown
Member

nexusphp/tachycardia v2.0 is out

@kenjis
kenjisforce-pushed the update-phpunit-10 branch 2 times, most recently from 2052f1a to a524abcCompareOctober 27, 2023 04:39
@kenjis

Copy link
Copy Markdown
MemberAuthor

I don't know why, but only in PHP 8.3, the NoTestCaseObjectOnCallStackException occurs.

$ vendor/bin/phpunit tests/system/Autoloader/AutoloaderTest.php PHPUnit 10.4.2 by Sebastian Bergmann and contributors.Runtime: PHP 8.3.0-devConfiguration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml..........................E 27 / 27 (100%)Time: 00:00.486, Memory: 16.00 MBThere was 1 error:1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpersPHPUnit\Framework\Exception: PHP Fatal error: Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44Stack trace:#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter->format(Array)#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler->format(Array)#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\Debug\ExceptionHandler->handle(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException))#6 {main} thrown in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php on line 44ERRORS!Tests: 27, Assertions: 45, Errors: 1.

@kenjiskenjis added the help wanted More help is needed for the proper resolution of an issue or pull request label Oct 27, 2023
@kenjis

Copy link
Copy Markdown
MemberAuthor
--- a/system/Format/JSONFormatter.php+++ b/system/Format/JSONFormatter.php@@ -37,6 +37,7 @@ class JSONFormatter implements FormatterInterface
$options = ENVIRONMENT === 'production' ? $options : $options | JSON_PRETTY_PRINT;
+ log_message('debug', var_export($data, true));
$result = json_encode($data, $options, 512);
if (! in_array(json_last_error(), [JSON_ERROR_NONE, JSON_ERROR_RECURSION], true)) {
CRITICAL - 2023-10-27 07:08:34 --> Cannot find TestCase object on call stack
in VENDORPATH/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php on line 63.
1 VENDORPATH/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
2 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke(2, 'rewind(): Stream does not support seeking', 'Standard input code', 71)
3 Standard input code(71): rewind(resource (stream))
4 Standard input code(118): __phpunit_run_isolated_test()
DEBUG - 2023-10-27 07:08:34 --> array (
'title' => 'PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException',
'type' => 'PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException',
'code' => 500,
'message' => 'Cannot find TestCase object on call stack',
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php',
'line' => 63,
'trace' => array (
0 => array (
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php',
'line' => 83,
'function' => 'fromCallStack',
'class' => 'PHPUnit\\Event\\Code\\TestMethodBuilder',
'type' => '::',
'args' => array (
),
),
1 => array (
'function' => '__invoke',
'class' => 'PHPUnit\\Runner\\ErrorHandler',
'type' => '->',
'args' => array (
0 => 2,
1 => 'rewind(): Stream does not support seeking',
2 => 'Standard input code',
3 => 71,
),
),
2 => array (
'file' => 'Standard input code',
'line' => 71,
'function' => 'rewind',
'args' => array (
0 => NULL,
),
),
3 => array (
'file' => 'Standard input code',
'line' => 118,
'function' => '__phpunit_run_isolated_test',
'args' => array (
),
),
),
)
CRITICAL - 2023-10-27 07:08:34 --> Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter->format(Array)
#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler->format(Array)
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\Debug\ExceptionHandler->handle(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)
#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException))
#6 {main}
thrown
【Previous Exception】
PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException
Cannot find TestCase object on call stack
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke(2, 'rewind(): Strea...', 'Standard input ...', 71)
#2 Standard input code(71): rewind(Resource id #2)
#3 Standard input code(118): __phpunit_run_isolated_test()
#4 {main}
in SYSTEMPATH/Format/JSONFormatter.php on line 44.
1 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
DEBUG - 2023-10-27 07:08:34 --> array (
'title' => 'ErrorException',
'type' => 'ErrorException',
'code' => 500,
'message' => 'Uncaught CodeIgniter\\Format\\Exceptions\\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\\Format\\Exceptions\\FormatException::forInvalidJSON(\'Type is not sup...\')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\\Format\\JSONFormatter->format(Array)
#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\\Debug\\ExceptionHandler->format(Array)
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\\Debug\\ExceptionHandler->respond(Array, 500)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\\Debug\\ExceptionHandler->handle(Object(PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\\HTTP\\IncomingRequest), Object(CodeIgniter\\HTTP\\Response), 500, 1)
#5 [internal function]: CodeIgniter\\Debug\\Exceptions->exceptionHandler(Object(PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException))
#6 {main}
thrown
【Previous Exception】
PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException
Cannot find TestCase object on call stack
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\\Event\\Code\\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\\Runner\\ErrorHandler->__invoke(2, \'rewind(): Strea...\', \'Standard input ...\', 71)
#2 Standard input code(71): rewind(Resource id #2)
#3 Standard input code(118): __phpunit_run_isolated_test()
#4 {main}',
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php',
'line' => 44,
'trace' => array (
0 => array (
'function' => 'shutdownHandler',
'class' => 'CodeIgniter\\Debug\\Exceptions',
'type' => '->',
'args' => array (
),
),
),
)

@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Oct 28, 2023
@github-actions

This comment was marked as outdated.

@kenjiskenjis removed the stale Pull requests with conflicts label Oct 30, 2023
@github-actions

This comment was marked as outdated.

@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Nov 30, 2023
@kenjiskenjis removed the stale Pull requests with conflicts label Nov 30, 2023
@kenjis

Copy link
Copy Markdown
MemberAuthor

No good. Tests on PHP 8.3 fails.

There were 42 errors:
1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpers
Test was run in child process and ended unexpectedly
2) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRoute
Test was run in child process and ended unexpectedly
3) CodeIgniter\CodeIgniterTest::testOutputBufferingControl
Test was run in child process and ended unexpectedly

https://github.com/codeigniter4/CodeIgniter4/actions/runs/7043858533/job/19170759175?pr=8069

@kenjis
kenjisforce-pushed the update-phpunit-10 branch 2 times, most recently from 5b2f18f to 47bf62eCompareApril 2, 2024 23:26
@kenjis
kenjis marked this pull request as ready for review April 2, 2024 23:45
@kenjiskenjis changed the title chore: update PHPUnit to 10refactor: update PHPUnit to 10Apr 2, 2024
@kenjis
kenjisforce-pushed the update-phpunit-10 branch from 47bf62e to fe41852CompareApril 6, 2024 00:26
kenjis added 17 commits April 7, 2024 12:38
vendor/bin/phpunit --migrate-configuration -c phpunit.xml.dist
Message: file_put_contents(/home/runner/work/CodeIgniter4/CodeIgniter4/build/coverage/text/coverage.txt): Failed to open stream: No such file or directory
Location: /home/runner/work/CodeIgniter4/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/CodeCoverage.php:317
Script done.
Error: Process completed with exit code 255.
1) CodeIgniter\Database\DatabaseTestCase\DatabaseTestCaseMigrationOnce1Test::testMigrationDone
TypeError: json_encode(): Argument #2 ($flags) must be of type int, bool given
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/Constraints/SeeInDatabase.php:118
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:282
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce1Test.php:86
There was 1 error:
1) CodeIgniter\Security\SecurityCSRFSessionRandomizeTokenTest::testCSRFVerifyPostInvalidToken
PHPUnit\Framework\Exception: PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Security/Security.php on line 378
PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Security/Security.php on line 378
There was 1 error:
1) CodeIgniter\CommonFunctionsTest::testTraceWithCSP
Test was run in child process and ended unexpectedly
@kenjis
kenjisforce-pushed the update-phpunit-10 branch from fe41852 to 9e009e9CompareApril 7, 2024 03:38
@kenjis

Copy link
Copy Markdown
MemberAuthor

Rebased to resolve the conflict.

@kenjis
kenjis merged commit 5c45ef1 into codeigniter4:4.5Apr 7, 2024
@kenjis
kenjis deleted the update-phpunit-10 branch April 7, 2024 03:57
@MGatner

Copy link
Copy Markdown
Member

Happy to see this one launched!

@kenjis

Copy link
Copy Markdown
MemberAuthor

But we still need restore_error_handler() to separate process testing.
I don't know the true cause of the errors.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wantedMore help is needed for the proper resolution of an issue or pull requestrefactorPull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@kenjis@paulbalandan@datamweb@MGatner@michalsn@samsonasik
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

refactor: update PHPUnit to 10 - #8069

Merged
kenjis merged 17 commits into
codeigniter4:4.5from
kenjis:update-phpunit-10
Apr 7, 2024
Merged

refactor: update PHPUnit to 10#8069
kenjis merged 17 commits into
codeigniter4:4.5from
kenjis:update-phpunit-10

Conversation

@kenjis

@kenjiskenjis commented Oct 20, 2023

Copy link
Copy Markdown
Member

Important

This PR will be merged just prior to the release of v4.5.0.

Description
PHPUnit requires PHP 8.1 or later.
https://packagist.org/packages/phpunit/phpunit#10.4.1

https://phpunit.de/announcements/phpunit-10.html

TODO

  • update nexusphp/tachycardia
  • fix errors on PHP 8.3

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjiskenjis added the 4.5 label Oct 20, 2023
@kenjis
kenjis marked this pull request as draft October 20, 2023 23:57
@kenjis

Copy link
Copy Markdown
MemberAuthor

@paulbalandan Any plan to release nexusphp/tachycardia that are compatible with PHPUnit10?

@paulbalandan

Copy link
Copy Markdown
Member

Is it ready but lacking integration tests. I'll try to finish this weekend. Thanks for reminding me.

@kenjis

Copy link
Copy Markdown
MemberAuthor
There was 1 PHPUnit test runner warning:
1) Class CodeIgniter\Cache\Handlers\AbstractHandlerTest declared in /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Cache/Handlers/AbstractHandlerTest.php is abstract
--
There was 1 PHPUnit test runner deprecation:
1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
--
6 tests triggered 6 PHPUnit deprecations:
1) CodeIgniter\AutoReview\FrameworkCodeTest::testEachTestClassHasCorrectGroupAnnotation
Data Provider method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAnnotation() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/AutoReview/FrameworkCodeTest.php:46
2) CodeIgniter\HTTP\SiteURITest::testConstructor
Data Provider method CodeIgniter\HTTP\SiteURITest::provideConstructor() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/HTTP/SiteURITest.php:32
3) CodeIgniter\Validation\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/CreditCardRulesTest.php:54
4) CodeIgniter\Validation\StrictRules\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\StrictRules\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/StrictRules/CreditCardRulesTest.php:55
5) CodeIgniter\Validation\StrictRules\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\StrictRules\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
6) CodeIgniter\Validation\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
WARNINGS!
Tests: 300, Assertions: 905, Warnings: 1, Deprecations: 7.

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6593809502/job/17916840733?pr=8069

@kenjis

Copy link
Copy Markdown
MemberAuthor
There was 1 PHPUnit test runner warning:
1) Class CodeIgniter\Cache\Handlers\AbstractHandlerTest declared in /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Cache/Handlers/AbstractHandlerTest.php is abstract
--
There was 1 PHPUnit test runner deprecation:
1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
--
There were 41 errors:
1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpers
Test was run in child process and ended unexpectedly
2) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRoute
Test was run in child process and ended unexpectedly
3) CodeIgniter\CodeIgniterTest::testOutputBufferingControl
Test was run in child process and ended unexpectedly
4) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRouteReturnResponse
Test was run in child process and ended unexpectedly
5) CodeIgniter\CodeIgniterTest::testRunClosureRoute
Test was run in child process and ended unexpectedly
6) CodeIgniter\CodeIgniterTest::testRun404Override
Test was run in child process and ended unexpectedly
7) CodeIgniter\CodeIgniterTest::testRun404OverrideControllerReturnsResponse
Test was run in child process and ended unexpectedly
8) CodeIgniter\CodeIgniterTest::testRun404OverrideReturnResponse
Test was run in child process and ended unexpectedly
9) CodeIgniter\CodeIgniterTest::testRun404OverrideByClosure
Test was run in child process and ended unexpectedly
1) CodeIgniter\Validation\StrictRules\ValidationTest::testPlaceholderReplacementTestFails
Failed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.
2) CodeIgniter\Validation\ValidationTest::testPlaceholderReplacementTestFails
Failed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.
--
6 tests triggered 6 PHPUnit deprecations:
1) CodeIgniter\AutoReview\FrameworkCodeTest::testEachTestClassHasCorrectGroupAnnotation
Data Provider method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAnnotation() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/AutoReview/FrameworkCodeTest.php:46
2) CodeIgniter\HTTP\SiteURITest::testConstructor
Data Provider method CodeIgniter\HTTP\SiteURITest::provideConstructor() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/HTTP/SiteURITest.php:32
3) CodeIgniter\Validation\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/CreditCardRulesTest.php:54
4) CodeIgniter\Validation\StrictRules\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\StrictRules\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/StrictRules/CreditCardRulesTest.php:55
5) CodeIgniter\Validation\StrictRules\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\StrictRules\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
6) CodeIgniter\Validation\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
ERRORS!
Tests: 5017, Assertions: 8400, Errors: 41, Failures: 2, Warnings: 1, Deprecations: 7, Skipped: 1.

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6593809497/job/17916881103?pr=8069

@paulbalandan

Copy link
Copy Markdown
Member

The first warning is easy. Just change the name to AbstractHandlerTestCase. Abstract tests need to be suffixed with TestCase.

For the static issues, just run the rule php_unit_data_provider_static for php-cs-fixer

@kenjis

Copy link
Copy Markdown
MemberAuthor

Unfortunately php-cs-fixer was not able to refactor the dataProviders because of $this.

@paulbalandan

Copy link
Copy Markdown
Member

Ah yes. The rule is risky because of uses of $this. Those cases should be modified to use static properties/methods.

@kenjis

Copy link
Copy Markdown
MemberAuthor

Why does this test fail?

$ vendor/bin/phpunit tests/system/Validation/StrictRules/ValidationTest.php PHPUnit 10.4.1 by Sebastian Bergmann and contributors.Runtime: PHP 8.1.24Configuration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml.................................................................................................... 100 / 121 ( 82%)...........F......... 121 / 121 (100%)Time: 00:00.930, Memory: 16.00 MB...--There was 1 failure:1) CodeIgniter\Validation\StrictRules\ValidationTest::testPlaceholderReplacementTestFailsFailed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.FAILURES!Tests: 121, Assertions: 173, Failures: 1, Warnings: 1.

@kenjis

Copy link
Copy Markdown
MemberAuthor

I got the reason. The error message of PHPUnit has been changed.

@MGatnerMGatner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will want to update DevKit as well - not sure when the appropriate time to do that is though, maybe when we actually drop 8.0? I know @paulbalandan is working on Tachycardia comparability - that would be great to include.

Edit: oops! I missed the existing conversation. All good.

@paulbalandan

Copy link
Copy Markdown
Member

nexusphp/tachycardia v2.0 is out

@kenjis
kenjisforce-pushed the update-phpunit-10 branch 2 times, most recently from 2052f1a to a524abcCompareOctober 27, 2023 04:39
@kenjis

Copy link
Copy Markdown
MemberAuthor

I don't know why, but only in PHP 8.3, the NoTestCaseObjectOnCallStackException occurs.

$ vendor/bin/phpunit tests/system/Autoloader/AutoloaderTest.php PHPUnit 10.4.2 by Sebastian Bergmann and contributors.Runtime: PHP 8.3.0-devConfiguration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml..........................E 27 / 27 (100%)Time: 00:00.486, Memory: 16.00 MBThere was 1 error:1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpersPHPUnit\Framework\Exception: PHP Fatal error: Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44Stack trace:#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter->format(Array)#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler->format(Array)#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\Debug\ExceptionHandler->handle(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException))#6 {main} thrown in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php on line 44ERRORS!Tests: 27, Assertions: 45, Errors: 1.

@kenjiskenjis added the help wanted More help is needed for the proper resolution of an issue or pull request label Oct 27, 2023
@kenjis

Copy link
Copy Markdown
MemberAuthor
--- a/system/Format/JSONFormatter.php+++ b/system/Format/JSONFormatter.php@@ -37,6 +37,7 @@ class JSONFormatter implements FormatterInterface
$options = ENVIRONMENT === 'production' ? $options : $options | JSON_PRETTY_PRINT;
+ log_message('debug', var_export($data, true));
$result = json_encode($data, $options, 512);
if (! in_array(json_last_error(), [JSON_ERROR_NONE, JSON_ERROR_RECURSION], true)) {
CRITICAL - 2023-10-27 07:08:34 --> Cannot find TestCase object on call stack
in VENDORPATH/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php on line 63.
1 VENDORPATH/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
2 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke(2, 'rewind(): Stream does not support seeking', 'Standard input code', 71)
3 Standard input code(71): rewind(resource (stream))
4 Standard input code(118): __phpunit_run_isolated_test()
DEBUG - 2023-10-27 07:08:34 --> array (
'title' => 'PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException',
'type' => 'PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException',
'code' => 500,
'message' => 'Cannot find TestCase object on call stack',
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php',
'line' => 63,
'trace' => array (
0 => array (
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php',
'line' => 83,
'function' => 'fromCallStack',
'class' => 'PHPUnit\\Event\\Code\\TestMethodBuilder',
'type' => '::',
'args' => array (
),
),
1 => array (
'function' => '__invoke',
'class' => 'PHPUnit\\Runner\\ErrorHandler',
'type' => '->',
'args' => array (
0 => 2,
1 => 'rewind(): Stream does not support seeking',
2 => 'Standard input code',
3 => 71,
),
),
2 => array (
'file' => 'Standard input code',
'line' => 71,
'function' => 'rewind',
'args' => array (
0 => NULL,
),
),
3 => array (
'file' => 'Standard input code',
'line' => 118,
'function' => '__phpunit_run_isolated_test',
'args' => array (
),
),
),
)
CRITICAL - 2023-10-27 07:08:34 --> Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter->format(Array)
#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler->format(Array)
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\Debug\ExceptionHandler->handle(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)
#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException))
#6 {main}
thrown
【Previous Exception】
PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException
Cannot find TestCase object on call stack
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke(2, 'rewind(): Strea...', 'Standard input ...', 71)
#2 Standard input code(71): rewind(Resource id #2)
#3 Standard input code(118): __phpunit_run_isolated_test()
#4 {main}
in SYSTEMPATH/Format/JSONFormatter.php on line 44.
1 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
DEBUG - 2023-10-27 07:08:34 --> array (
'title' => 'ErrorException',
'type' => 'ErrorException',
'code' => 500,
'message' => 'Uncaught CodeIgniter\\Format\\Exceptions\\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\\Format\\Exceptions\\FormatException::forInvalidJSON(\'Type is not sup...\')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\\Format\\JSONFormatter->format(Array)
#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\\Debug\\ExceptionHandler->format(Array)
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\\Debug\\ExceptionHandler->respond(Array, 500)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\\Debug\\ExceptionHandler->handle(Object(PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\\HTTP\\IncomingRequest), Object(CodeIgniter\\HTTP\\Response), 500, 1)
#5 [internal function]: CodeIgniter\\Debug\\Exceptions->exceptionHandler(Object(PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException))
#6 {main}
thrown
【Previous Exception】
PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException
Cannot find TestCase object on call stack
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\\Event\\Code\\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\\Runner\\ErrorHandler->__invoke(2, \'rewind(): Strea...\', \'Standard input ...\', 71)
#2 Standard input code(71): rewind(Resource id #2)
#3 Standard input code(118): __phpunit_run_isolated_test()
#4 {main}',
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php',
'line' => 44,
'trace' => array (
0 => array (
'function' => 'shutdownHandler',
'class' => 'CodeIgniter\\Debug\\Exceptions',
'type' => '->',
'args' => array (
),
),
),
)

@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Oct 28, 2023
@github-actions

This comment was marked as outdated.

@kenjiskenjis removed the stale Pull requests with conflicts label Oct 30, 2023
@github-actions

This comment was marked as outdated.

@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Nov 30, 2023
@kenjiskenjis removed the stale Pull requests with conflicts label Nov 30, 2023
@kenjis

Copy link
Copy Markdown
MemberAuthor

No good. Tests on PHP 8.3 fails.

There were 42 errors:
1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpers
Test was run in child process and ended unexpectedly
2) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRoute
Test was run in child process and ended unexpectedly
3) CodeIgniter\CodeIgniterTest::testOutputBufferingControl
Test was run in child process and ended unexpectedly

https://github.com/codeigniter4/CodeIgniter4/actions/runs/7043858533/job/19170759175?pr=8069

@kenjis
kenjisforce-pushed the update-phpunit-10 branch 2 times, most recently from 5b2f18f to 47bf62eCompareApril 2, 2024 23:26
@kenjis
kenjis marked this pull request as ready for review April 2, 2024 23:45
@kenjiskenjis changed the title chore: update PHPUnit to 10refactor: update PHPUnit to 10Apr 2, 2024
@kenjis
kenjisforce-pushed the update-phpunit-10 branch from 47bf62e to fe41852CompareApril 6, 2024 00:26
kenjis added 17 commits April 7, 2024 12:38
vendor/bin/phpunit --migrate-configuration -c phpunit.xml.dist
Message: file_put_contents(/home/runner/work/CodeIgniter4/CodeIgniter4/build/coverage/text/coverage.txt): Failed to open stream: No such file or directory
Location: /home/runner/work/CodeIgniter4/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/CodeCoverage.php:317
Script done.
Error: Process completed with exit code 255.
1) CodeIgniter\Database\DatabaseTestCase\DatabaseTestCaseMigrationOnce1Test::testMigrationDone
TypeError: json_encode(): Argument #2 ($flags) must be of type int, bool given
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/Constraints/SeeInDatabase.php:118
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:282
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce1Test.php:86
There was 1 error:
1) CodeIgniter\Security\SecurityCSRFSessionRandomizeTokenTest::testCSRFVerifyPostInvalidToken
PHPUnit\Framework\Exception: PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Security/Security.php on line 378
PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Security/Security.php on line 378
There was 1 error:
1) CodeIgniter\CommonFunctionsTest::testTraceWithCSP
Test was run in child process and ended unexpectedly
@kenjis
kenjisforce-pushed the update-phpunit-10 branch from fe41852 to 9e009e9CompareApril 7, 2024 03:38
@kenjis

Copy link
Copy Markdown
MemberAuthor

Rebased to resolve the conflict.

@kenjis
kenjis merged commit 5c45ef1 into codeigniter4:4.5Apr 7, 2024
@kenjis
kenjis deleted the update-phpunit-10 branch April 7, 2024 03:57
@MGatner

Copy link
Copy Markdown
Member

Happy to see this one launched!

@kenjis

Copy link
Copy Markdown
MemberAuthor

But we still need restore_error_handler() to separate process testing.
I don't know the true cause of the errors.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wantedMore help is needed for the proper resolution of an issue or pull requestrefactorPull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@kenjis@paulbalandan@datamweb@MGatner@michalsn@samsonasik
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

refactor: update PHPUnit to 10 - #8069

Merged
kenjis merged 17 commits into
codeigniter4:4.5from
kenjis:update-phpunit-10
Apr 7, 2024
Merged

refactor: update PHPUnit to 10#8069
kenjis merged 17 commits into
codeigniter4:4.5from
kenjis:update-phpunit-10

Conversation

@kenjis

@kenjiskenjis commented Oct 20, 2023

Copy link
Copy Markdown
Member

Important

This PR will be merged just prior to the release of v4.5.0.

Description
PHPUnit requires PHP 8.1 or later.
https://packagist.org/packages/phpunit/phpunit#10.4.1

https://phpunit.de/announcements/phpunit-10.html

TODO

  • update nexusphp/tachycardia
  • fix errors on PHP 8.3

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjiskenjis added the 4.5 label Oct 20, 2023
@kenjis
kenjis marked this pull request as draft October 20, 2023 23:57
@kenjis

Copy link
Copy Markdown
MemberAuthor

@paulbalandan Any plan to release nexusphp/tachycardia that are compatible with PHPUnit10?

@paulbalandan

Copy link
Copy Markdown
Member

Is it ready but lacking integration tests. I'll try to finish this weekend. Thanks for reminding me.

@kenjis

Copy link
Copy Markdown
MemberAuthor
There was 1 PHPUnit test runner warning:
1) Class CodeIgniter\Cache\Handlers\AbstractHandlerTest declared in /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Cache/Handlers/AbstractHandlerTest.php is abstract
--
There was 1 PHPUnit test runner deprecation:
1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
--
6 tests triggered 6 PHPUnit deprecations:
1) CodeIgniter\AutoReview\FrameworkCodeTest::testEachTestClassHasCorrectGroupAnnotation
Data Provider method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAnnotation() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/AutoReview/FrameworkCodeTest.php:46
2) CodeIgniter\HTTP\SiteURITest::testConstructor
Data Provider method CodeIgniter\HTTP\SiteURITest::provideConstructor() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/HTTP/SiteURITest.php:32
3) CodeIgniter\Validation\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/CreditCardRulesTest.php:54
4) CodeIgniter\Validation\StrictRules\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\StrictRules\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/StrictRules/CreditCardRulesTest.php:55
5) CodeIgniter\Validation\StrictRules\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\StrictRules\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
6) CodeIgniter\Validation\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
WARNINGS!
Tests: 300, Assertions: 905, Warnings: 1, Deprecations: 7.

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6593809502/job/17916840733?pr=8069

@kenjis

Copy link
Copy Markdown
MemberAuthor
There was 1 PHPUnit test runner warning:
1) Class CodeIgniter\Cache\Handlers\AbstractHandlerTest declared in /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Cache/Handlers/AbstractHandlerTest.php is abstract
--
There was 1 PHPUnit test runner deprecation:
1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
--
There were 41 errors:
1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpers
Test was run in child process and ended unexpectedly
2) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRoute
Test was run in child process and ended unexpectedly
3) CodeIgniter\CodeIgniterTest::testOutputBufferingControl
Test was run in child process and ended unexpectedly
4) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRouteReturnResponse
Test was run in child process and ended unexpectedly
5) CodeIgniter\CodeIgniterTest::testRunClosureRoute
Test was run in child process and ended unexpectedly
6) CodeIgniter\CodeIgniterTest::testRun404Override
Test was run in child process and ended unexpectedly
7) CodeIgniter\CodeIgniterTest::testRun404OverrideControllerReturnsResponse
Test was run in child process and ended unexpectedly
8) CodeIgniter\CodeIgniterTest::testRun404OverrideReturnResponse
Test was run in child process and ended unexpectedly
9) CodeIgniter\CodeIgniterTest::testRun404OverrideByClosure
Test was run in child process and ended unexpectedly
1) CodeIgniter\Validation\StrictRules\ValidationTest::testPlaceholderReplacementTestFails
Failed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.
2) CodeIgniter\Validation\ValidationTest::testPlaceholderReplacementTestFails
Failed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.
--
6 tests triggered 6 PHPUnit deprecations:
1) CodeIgniter\AutoReview\FrameworkCodeTest::testEachTestClassHasCorrectGroupAnnotation
Data Provider method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAnnotation() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/AutoReview/FrameworkCodeTest.php:46
2) CodeIgniter\HTTP\SiteURITest::testConstructor
Data Provider method CodeIgniter\HTTP\SiteURITest::provideConstructor() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/HTTP/SiteURITest.php:32
3) CodeIgniter\Validation\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/CreditCardRulesTest.php:54
4) CodeIgniter\Validation\StrictRules\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\StrictRules\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/StrictRules/CreditCardRulesTest.php:55
5) CodeIgniter\Validation\StrictRules\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\StrictRules\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
6) CodeIgniter\Validation\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
ERRORS!
Tests: 5017, Assertions: 8400, Errors: 41, Failures: 2, Warnings: 1, Deprecations: 7, Skipped: 1.

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6593809497/job/17916881103?pr=8069

@paulbalandan

Copy link
Copy Markdown
Member

The first warning is easy. Just change the name to AbstractHandlerTestCase. Abstract tests need to be suffixed with TestCase.

For the static issues, just run the rule php_unit_data_provider_static for php-cs-fixer

@kenjis

Copy link
Copy Markdown
MemberAuthor

Unfortunately php-cs-fixer was not able to refactor the dataProviders because of $this.

@paulbalandan

Copy link
Copy Markdown
Member

Ah yes. The rule is risky because of uses of $this. Those cases should be modified to use static properties/methods.

@kenjis

Copy link
Copy Markdown
MemberAuthor

Why does this test fail?

$ vendor/bin/phpunit tests/system/Validation/StrictRules/ValidationTest.php PHPUnit 10.4.1 by Sebastian Bergmann and contributors.Runtime: PHP 8.1.24Configuration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml.................................................................................................... 100 / 121 ( 82%)...........F......... 121 / 121 (100%)Time: 00:00.930, Memory: 16.00 MB...--There was 1 failure:1) CodeIgniter\Validation\StrictRules\ValidationTest::testPlaceholderReplacementTestFailsFailed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.FAILURES!Tests: 121, Assertions: 173, Failures: 1, Warnings: 1.

@kenjis

Copy link
Copy Markdown
MemberAuthor

I got the reason. The error message of PHPUnit has been changed.

@MGatnerMGatner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will want to update DevKit as well - not sure when the appropriate time to do that is though, maybe when we actually drop 8.0? I know @paulbalandan is working on Tachycardia comparability - that would be great to include.

Edit: oops! I missed the existing conversation. All good.

@paulbalandan

Copy link
Copy Markdown
Member

nexusphp/tachycardia v2.0 is out

@kenjis
kenjisforce-pushed the update-phpunit-10 branch 2 times, most recently from 2052f1a to a524abcCompareOctober 27, 2023 04:39
@kenjis

Copy link
Copy Markdown
MemberAuthor

I don't know why, but only in PHP 8.3, the NoTestCaseObjectOnCallStackException occurs.

$ vendor/bin/phpunit tests/system/Autoloader/AutoloaderTest.php PHPUnit 10.4.2 by Sebastian Bergmann and contributors.Runtime: PHP 8.3.0-devConfiguration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml..........................E 27 / 27 (100%)Time: 00:00.486, Memory: 16.00 MBThere was 1 error:1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpersPHPUnit\Framework\Exception: PHP Fatal error: Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44Stack trace:#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter->format(Array)#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler->format(Array)#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\Debug\ExceptionHandler->handle(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException))#6 {main} thrown in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php on line 44ERRORS!Tests: 27, Assertions: 45, Errors: 1.

@kenjiskenjis added the help wanted More help is needed for the proper resolution of an issue or pull request label Oct 27, 2023
@kenjis

Copy link
Copy Markdown
MemberAuthor
--- a/system/Format/JSONFormatter.php+++ b/system/Format/JSONFormatter.php@@ -37,6 +37,7 @@ class JSONFormatter implements FormatterInterface
$options = ENVIRONMENT === 'production' ? $options : $options | JSON_PRETTY_PRINT;
+ log_message('debug', var_export($data, true));
$result = json_encode($data, $options, 512);
if (! in_array(json_last_error(), [JSON_ERROR_NONE, JSON_ERROR_RECURSION], true)) {
CRITICAL - 2023-10-27 07:08:34 --> Cannot find TestCase object on call stack
in VENDORPATH/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php on line 63.
1 VENDORPATH/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
2 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke(2, 'rewind(): Stream does not support seeking', 'Standard input code', 71)
3 Standard input code(71): rewind(resource (stream))
4 Standard input code(118): __phpunit_run_isolated_test()
DEBUG - 2023-10-27 07:08:34 --> array (
'title' => 'PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException',
'type' => 'PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException',
'code' => 500,
'message' => 'Cannot find TestCase object on call stack',
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php',
'line' => 63,
'trace' => array (
0 => array (
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php',
'line' => 83,
'function' => 'fromCallStack',
'class' => 'PHPUnit\\Event\\Code\\TestMethodBuilder',
'type' => '::',
'args' => array (
),
),
1 => array (
'function' => '__invoke',
'class' => 'PHPUnit\\Runner\\ErrorHandler',
'type' => '->',
'args' => array (
0 => 2,
1 => 'rewind(): Stream does not support seeking',
2 => 'Standard input code',
3 => 71,
),
),
2 => array (
'file' => 'Standard input code',
'line' => 71,
'function' => 'rewind',
'args' => array (
0 => NULL,
),
),
3 => array (
'file' => 'Standard input code',
'line' => 118,
'function' => '__phpunit_run_isolated_test',
'args' => array (
),
),
),
)
CRITICAL - 2023-10-27 07:08:34 --> Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter->format(Array)
#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler->format(Array)
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\Debug\ExceptionHandler->handle(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)
#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException))
#6 {main}
thrown
【Previous Exception】
PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException
Cannot find TestCase object on call stack
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke(2, 'rewind(): Strea...', 'Standard input ...', 71)
#2 Standard input code(71): rewind(Resource id #2)
#3 Standard input code(118): __phpunit_run_isolated_test()
#4 {main}
in SYSTEMPATH/Format/JSONFormatter.php on line 44.
1 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
DEBUG - 2023-10-27 07:08:34 --> array (
'title' => 'ErrorException',
'type' => 'ErrorException',
'code' => 500,
'message' => 'Uncaught CodeIgniter\\Format\\Exceptions\\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\\Format\\Exceptions\\FormatException::forInvalidJSON(\'Type is not sup...\')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\\Format\\JSONFormatter->format(Array)
#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\\Debug\\ExceptionHandler->format(Array)
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\\Debug\\ExceptionHandler->respond(Array, 500)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\\Debug\\ExceptionHandler->handle(Object(PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\\HTTP\\IncomingRequest), Object(CodeIgniter\\HTTP\\Response), 500, 1)
#5 [internal function]: CodeIgniter\\Debug\\Exceptions->exceptionHandler(Object(PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException))
#6 {main}
thrown
【Previous Exception】
PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException
Cannot find TestCase object on call stack
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\\Event\\Code\\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\\Runner\\ErrorHandler->__invoke(2, \'rewind(): Strea...\', \'Standard input ...\', 71)
#2 Standard input code(71): rewind(Resource id #2)
#3 Standard input code(118): __phpunit_run_isolated_test()
#4 {main}',
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php',
'line' => 44,
'trace' => array (
0 => array (
'function' => 'shutdownHandler',
'class' => 'CodeIgniter\\Debug\\Exceptions',
'type' => '->',
'args' => array (
),
),
),
)

@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Oct 28, 2023
@github-actions

This comment was marked as outdated.

@kenjiskenjis removed the stale Pull requests with conflicts label Oct 30, 2023
@github-actions

This comment was marked as outdated.

@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Nov 30, 2023
@kenjiskenjis removed the stale Pull requests with conflicts label Nov 30, 2023
@kenjis

Copy link
Copy Markdown
MemberAuthor

No good. Tests on PHP 8.3 fails.

There were 42 errors:
1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpers
Test was run in child process and ended unexpectedly
2) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRoute
Test was run in child process and ended unexpectedly
3) CodeIgniter\CodeIgniterTest::testOutputBufferingControl
Test was run in child process and ended unexpectedly

https://github.com/codeigniter4/CodeIgniter4/actions/runs/7043858533/job/19170759175?pr=8069

@kenjis
kenjisforce-pushed the update-phpunit-10 branch 2 times, most recently from 5b2f18f to 47bf62eCompareApril 2, 2024 23:26
@kenjis
kenjis marked this pull request as ready for review April 2, 2024 23:45
@kenjiskenjis changed the title chore: update PHPUnit to 10refactor: update PHPUnit to 10Apr 2, 2024
@kenjis
kenjisforce-pushed the update-phpunit-10 branch from 47bf62e to fe41852CompareApril 6, 2024 00:26
kenjis added 17 commits April 7, 2024 12:38
vendor/bin/phpunit --migrate-configuration -c phpunit.xml.dist
Message: file_put_contents(/home/runner/work/CodeIgniter4/CodeIgniter4/build/coverage/text/coverage.txt): Failed to open stream: No such file or directory
Location: /home/runner/work/CodeIgniter4/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/CodeCoverage.php:317
Script done.
Error: Process completed with exit code 255.
1) CodeIgniter\Database\DatabaseTestCase\DatabaseTestCaseMigrationOnce1Test::testMigrationDone
TypeError: json_encode(): Argument #2 ($flags) must be of type int, bool given
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/Constraints/SeeInDatabase.php:118
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:282
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce1Test.php:86
There was 1 error:
1) CodeIgniter\Security\SecurityCSRFSessionRandomizeTokenTest::testCSRFVerifyPostInvalidToken
PHPUnit\Framework\Exception: PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Security/Security.php on line 378
PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Security/Security.php on line 378
There was 1 error:
1) CodeIgniter\CommonFunctionsTest::testTraceWithCSP
Test was run in child process and ended unexpectedly
@kenjis
kenjisforce-pushed the update-phpunit-10 branch from fe41852 to 9e009e9CompareApril 7, 2024 03:38
@kenjis

Copy link
Copy Markdown
MemberAuthor

Rebased to resolve the conflict.

@kenjis
kenjis merged commit 5c45ef1 into codeigniter4:4.5Apr 7, 2024
@kenjis
kenjis deleted the update-phpunit-10 branch April 7, 2024 03:57
@MGatner

Copy link
Copy Markdown
Member

Happy to see this one launched!

@kenjis

Copy link
Copy Markdown
MemberAuthor

But we still need restore_error_handler() to separate process testing.
I don't know the true cause of the errors.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wantedMore help is needed for the proper resolution of an issue or pull requestrefactorPull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@kenjis@paulbalandan@datamweb@MGatner@michalsn@samsonasik
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

refactor: update PHPUnit to 10 - #8069

Merged
kenjis merged 17 commits into
codeigniter4:4.5from
kenjis:update-phpunit-10
Apr 7, 2024
Merged

refactor: update PHPUnit to 10#8069
kenjis merged 17 commits into
codeigniter4:4.5from
kenjis:update-phpunit-10

Conversation

@kenjis

@kenjiskenjis commented Oct 20, 2023

Copy link
Copy Markdown
Member

Important

This PR will be merged just prior to the release of v4.5.0.

Description
PHPUnit requires PHP 8.1 or later.
https://packagist.org/packages/phpunit/phpunit#10.4.1

https://phpunit.de/announcements/phpunit-10.html

TODO

  • update nexusphp/tachycardia
  • fix errors on PHP 8.3

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjiskenjis added the 4.5 label Oct 20, 2023
@kenjis
kenjis marked this pull request as draft October 20, 2023 23:57
@kenjis

Copy link
Copy Markdown
MemberAuthor

@paulbalandan Any plan to release nexusphp/tachycardia that are compatible with PHPUnit10?

@paulbalandan

Copy link
Copy Markdown
Member

Is it ready but lacking integration tests. I'll try to finish this weekend. Thanks for reminding me.

@kenjis

Copy link
Copy Markdown
MemberAuthor
There was 1 PHPUnit test runner warning:
1) Class CodeIgniter\Cache\Handlers\AbstractHandlerTest declared in /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Cache/Handlers/AbstractHandlerTest.php is abstract
--
There was 1 PHPUnit test runner deprecation:
1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
--
6 tests triggered 6 PHPUnit deprecations:
1) CodeIgniter\AutoReview\FrameworkCodeTest::testEachTestClassHasCorrectGroupAnnotation
Data Provider method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAnnotation() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/AutoReview/FrameworkCodeTest.php:46
2) CodeIgniter\HTTP\SiteURITest::testConstructor
Data Provider method CodeIgniter\HTTP\SiteURITest::provideConstructor() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/HTTP/SiteURITest.php:32
3) CodeIgniter\Validation\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/CreditCardRulesTest.php:54
4) CodeIgniter\Validation\StrictRules\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\StrictRules\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/StrictRules/CreditCardRulesTest.php:55
5) CodeIgniter\Validation\StrictRules\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\StrictRules\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
6) CodeIgniter\Validation\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
WARNINGS!
Tests: 300, Assertions: 905, Warnings: 1, Deprecations: 7.

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6593809502/job/17916840733?pr=8069

@kenjis

Copy link
Copy Markdown
MemberAuthor
There was 1 PHPUnit test runner warning:
1) Class CodeIgniter\Cache\Handlers\AbstractHandlerTest declared in /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Cache/Handlers/AbstractHandlerTest.php is abstract
--
There was 1 PHPUnit test runner deprecation:
1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
--
There were 41 errors:
1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpers
Test was run in child process and ended unexpectedly
2) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRoute
Test was run in child process and ended unexpectedly
3) CodeIgniter\CodeIgniterTest::testOutputBufferingControl
Test was run in child process and ended unexpectedly
4) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRouteReturnResponse
Test was run in child process and ended unexpectedly
5) CodeIgniter\CodeIgniterTest::testRunClosureRoute
Test was run in child process and ended unexpectedly
6) CodeIgniter\CodeIgniterTest::testRun404Override
Test was run in child process and ended unexpectedly
7) CodeIgniter\CodeIgniterTest::testRun404OverrideControllerReturnsResponse
Test was run in child process and ended unexpectedly
8) CodeIgniter\CodeIgniterTest::testRun404OverrideReturnResponse
Test was run in child process and ended unexpectedly
9) CodeIgniter\CodeIgniterTest::testRun404OverrideByClosure
Test was run in child process and ended unexpectedly
1) CodeIgniter\Validation\StrictRules\ValidationTest::testPlaceholderReplacementTestFails
Failed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.
2) CodeIgniter\Validation\ValidationTest::testPlaceholderReplacementTestFails
Failed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.
--
6 tests triggered 6 PHPUnit deprecations:
1) CodeIgniter\AutoReview\FrameworkCodeTest::testEachTestClassHasCorrectGroupAnnotation
Data Provider method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAnnotation() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/AutoReview/FrameworkCodeTest.php:46
2) CodeIgniter\HTTP\SiteURITest::testConstructor
Data Provider method CodeIgniter\HTTP\SiteURITest::provideConstructor() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/HTTP/SiteURITest.php:32
3) CodeIgniter\Validation\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/CreditCardRulesTest.php:54
4) CodeIgniter\Validation\StrictRules\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\StrictRules\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/StrictRules/CreditCardRulesTest.php:55
5) CodeIgniter\Validation\StrictRules\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\StrictRules\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
6) CodeIgniter\Validation\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
ERRORS!
Tests: 5017, Assertions: 8400, Errors: 41, Failures: 2, Warnings: 1, Deprecations: 7, Skipped: 1.

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6593809497/job/17916881103?pr=8069

@paulbalandan

Copy link
Copy Markdown
Member

The first warning is easy. Just change the name to AbstractHandlerTestCase. Abstract tests need to be suffixed with TestCase.

For the static issues, just run the rule php_unit_data_provider_static for php-cs-fixer

@kenjis

Copy link
Copy Markdown
MemberAuthor

Unfortunately php-cs-fixer was not able to refactor the dataProviders because of $this.

@paulbalandan

Copy link
Copy Markdown
Member

Ah yes. The rule is risky because of uses of $this. Those cases should be modified to use static properties/methods.

@kenjis

Copy link
Copy Markdown
MemberAuthor

Why does this test fail?

$ vendor/bin/phpunit tests/system/Validation/StrictRules/ValidationTest.php PHPUnit 10.4.1 by Sebastian Bergmann and contributors.Runtime: PHP 8.1.24Configuration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml.................................................................................................... 100 / 121 ( 82%)...........F......... 121 / 121 (100%)Time: 00:00.930, Memory: 16.00 MB...--There was 1 failure:1) CodeIgniter\Validation\StrictRules\ValidationTest::testPlaceholderReplacementTestFailsFailed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.FAILURES!Tests: 121, Assertions: 173, Failures: 1, Warnings: 1.

@kenjis

Copy link
Copy Markdown
MemberAuthor

I got the reason. The error message of PHPUnit has been changed.

@MGatnerMGatner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will want to update DevKit as well - not sure when the appropriate time to do that is though, maybe when we actually drop 8.0? I know @paulbalandan is working on Tachycardia comparability - that would be great to include.

Edit: oops! I missed the existing conversation. All good.

@paulbalandan

Copy link
Copy Markdown
Member

nexusphp/tachycardia v2.0 is out

@kenjis
kenjisforce-pushed the update-phpunit-10 branch 2 times, most recently from 2052f1a to a524abcCompareOctober 27, 2023 04:39
@kenjis

Copy link
Copy Markdown
MemberAuthor

I don't know why, but only in PHP 8.3, the NoTestCaseObjectOnCallStackException occurs.

$ vendor/bin/phpunit tests/system/Autoloader/AutoloaderTest.php PHPUnit 10.4.2 by Sebastian Bergmann and contributors.Runtime: PHP 8.3.0-devConfiguration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml..........................E 27 / 27 (100%)Time: 00:00.486, Memory: 16.00 MBThere was 1 error:1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpersPHPUnit\Framework\Exception: PHP Fatal error: Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44Stack trace:#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter->format(Array)#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler->format(Array)#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\Debug\ExceptionHandler->handle(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException))#6 {main} thrown in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php on line 44ERRORS!Tests: 27, Assertions: 45, Errors: 1.

@kenjiskenjis added the help wanted More help is needed for the proper resolution of an issue or pull request label Oct 27, 2023
@kenjis

Copy link
Copy Markdown
MemberAuthor
--- a/system/Format/JSONFormatter.php+++ b/system/Format/JSONFormatter.php@@ -37,6 +37,7 @@ class JSONFormatter implements FormatterInterface
$options = ENVIRONMENT === 'production' ? $options : $options | JSON_PRETTY_PRINT;
+ log_message('debug', var_export($data, true));
$result = json_encode($data, $options, 512);
if (! in_array(json_last_error(), [JSON_ERROR_NONE, JSON_ERROR_RECURSION], true)) {
CRITICAL - 2023-10-27 07:08:34 --> Cannot find TestCase object on call stack
in VENDORPATH/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php on line 63.
1 VENDORPATH/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
2 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke(2, 'rewind(): Stream does not support seeking', 'Standard input code', 71)
3 Standard input code(71): rewind(resource (stream))
4 Standard input code(118): __phpunit_run_isolated_test()
DEBUG - 2023-10-27 07:08:34 --> array (
'title' => 'PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException',
'type' => 'PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException',
'code' => 500,
'message' => 'Cannot find TestCase object on call stack',
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php',
'line' => 63,
'trace' => array (
0 => array (
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php',
'line' => 83,
'function' => 'fromCallStack',
'class' => 'PHPUnit\\Event\\Code\\TestMethodBuilder',
'type' => '::',
'args' => array (
),
),
1 => array (
'function' => '__invoke',
'class' => 'PHPUnit\\Runner\\ErrorHandler',
'type' => '->',
'args' => array (
0 => 2,
1 => 'rewind(): Stream does not support seeking',
2 => 'Standard input code',
3 => 71,
),
),
2 => array (
'file' => 'Standard input code',
'line' => 71,
'function' => 'rewind',
'args' => array (
0 => NULL,
),
),
3 => array (
'file' => 'Standard input code',
'line' => 118,
'function' => '__phpunit_run_isolated_test',
'args' => array (
),
),
),
)
CRITICAL - 2023-10-27 07:08:34 --> Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter->format(Array)
#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler->format(Array)
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\Debug\ExceptionHandler->handle(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)
#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException))
#6 {main}
thrown
【Previous Exception】
PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException
Cannot find TestCase object on call stack
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke(2, 'rewind(): Strea...', 'Standard input ...', 71)
#2 Standard input code(71): rewind(Resource id #2)
#3 Standard input code(118): __phpunit_run_isolated_test()
#4 {main}
in SYSTEMPATH/Format/JSONFormatter.php on line 44.
1 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
DEBUG - 2023-10-27 07:08:34 --> array (
'title' => 'ErrorException',
'type' => 'ErrorException',
'code' => 500,
'message' => 'Uncaught CodeIgniter\\Format\\Exceptions\\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\\Format\\Exceptions\\FormatException::forInvalidJSON(\'Type is not sup...\')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\\Format\\JSONFormatter->format(Array)
#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\\Debug\\ExceptionHandler->format(Array)
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\\Debug\\ExceptionHandler->respond(Array, 500)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\\Debug\\ExceptionHandler->handle(Object(PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\\HTTP\\IncomingRequest), Object(CodeIgniter\\HTTP\\Response), 500, 1)
#5 [internal function]: CodeIgniter\\Debug\\Exceptions->exceptionHandler(Object(PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException))
#6 {main}
thrown
【Previous Exception】
PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException
Cannot find TestCase object on call stack
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\\Event\\Code\\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\\Runner\\ErrorHandler->__invoke(2, \'rewind(): Strea...\', \'Standard input ...\', 71)
#2 Standard input code(71): rewind(Resource id #2)
#3 Standard input code(118): __phpunit_run_isolated_test()
#4 {main}',
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php',
'line' => 44,
'trace' => array (
0 => array (
'function' => 'shutdownHandler',
'class' => 'CodeIgniter\\Debug\\Exceptions',
'type' => '->',
'args' => array (
),
),
),
)

@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Oct 28, 2023
@github-actions

This comment was marked as outdated.

@kenjiskenjis removed the stale Pull requests with conflicts label Oct 30, 2023
@github-actions

This comment was marked as outdated.

@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Nov 30, 2023
@kenjiskenjis removed the stale Pull requests with conflicts label Nov 30, 2023
@kenjis

Copy link
Copy Markdown
MemberAuthor

No good. Tests on PHP 8.3 fails.

There were 42 errors:
1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpers
Test was run in child process and ended unexpectedly
2) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRoute
Test was run in child process and ended unexpectedly
3) CodeIgniter\CodeIgniterTest::testOutputBufferingControl
Test was run in child process and ended unexpectedly

https://github.com/codeigniter4/CodeIgniter4/actions/runs/7043858533/job/19170759175?pr=8069

@kenjis
kenjisforce-pushed the update-phpunit-10 branch 2 times, most recently from 5b2f18f to 47bf62eCompareApril 2, 2024 23:26
@kenjis
kenjis marked this pull request as ready for review April 2, 2024 23:45
@kenjiskenjis changed the title chore: update PHPUnit to 10refactor: update PHPUnit to 10Apr 2, 2024
@kenjis
kenjisforce-pushed the update-phpunit-10 branch from 47bf62e to fe41852CompareApril 6, 2024 00:26
kenjis added 17 commits April 7, 2024 12:38
vendor/bin/phpunit --migrate-configuration -c phpunit.xml.dist
Message: file_put_contents(/home/runner/work/CodeIgniter4/CodeIgniter4/build/coverage/text/coverage.txt): Failed to open stream: No such file or directory
Location: /home/runner/work/CodeIgniter4/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/CodeCoverage.php:317
Script done.
Error: Process completed with exit code 255.
1) CodeIgniter\Database\DatabaseTestCase\DatabaseTestCaseMigrationOnce1Test::testMigrationDone
TypeError: json_encode(): Argument #2 ($flags) must be of type int, bool given
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/Constraints/SeeInDatabase.php:118
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:282
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce1Test.php:86
There was 1 error:
1) CodeIgniter\Security\SecurityCSRFSessionRandomizeTokenTest::testCSRFVerifyPostInvalidToken
PHPUnit\Framework\Exception: PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Security/Security.php on line 378
PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Security/Security.php on line 378
There was 1 error:
1) CodeIgniter\CommonFunctionsTest::testTraceWithCSP
Test was run in child process and ended unexpectedly
@kenjis
kenjisforce-pushed the update-phpunit-10 branch from fe41852 to 9e009e9CompareApril 7, 2024 03:38
@kenjis

Copy link
Copy Markdown
MemberAuthor

Rebased to resolve the conflict.

@kenjis
kenjis merged commit 5c45ef1 into codeigniter4:4.5Apr 7, 2024
@kenjis
kenjis deleted the update-phpunit-10 branch April 7, 2024 03:57
@MGatner

Copy link
Copy Markdown
Member

Happy to see this one launched!

@kenjis

Copy link
Copy Markdown
MemberAuthor

But we still need restore_error_handler() to separate process testing.
I don't know the true cause of the errors.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wantedMore help is needed for the proper resolution of an issue or pull requestrefactorPull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@kenjis@paulbalandan@datamweb@MGatner@michalsn@samsonasik
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

refactor: update PHPUnit to 10 - #8069

Merged
kenjis merged 17 commits into
codeigniter4:4.5from
kenjis:update-phpunit-10
Apr 7, 2024
Merged

refactor: update PHPUnit to 10#8069
kenjis merged 17 commits into
codeigniter4:4.5from
kenjis:update-phpunit-10

Conversation

@kenjis

@kenjiskenjis commented Oct 20, 2023

Copy link
Copy Markdown
Member

Important

This PR will be merged just prior to the release of v4.5.0.

Description
PHPUnit requires PHP 8.1 or later.
https://packagist.org/packages/phpunit/phpunit#10.4.1

https://phpunit.de/announcements/phpunit-10.html

TODO

  • update nexusphp/tachycardia
  • fix errors on PHP 8.3

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjiskenjis added the 4.5 label Oct 20, 2023
@kenjis
kenjis marked this pull request as draft October 20, 2023 23:57
@kenjis

Copy link
Copy Markdown
MemberAuthor

@paulbalandan Any plan to release nexusphp/tachycardia that are compatible with PHPUnit10?

@paulbalandan

Copy link
Copy Markdown
Member

Is it ready but lacking integration tests. I'll try to finish this weekend. Thanks for reminding me.

@kenjis

Copy link
Copy Markdown
MemberAuthor
There was 1 PHPUnit test runner warning:
1) Class CodeIgniter\Cache\Handlers\AbstractHandlerTest declared in /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Cache/Handlers/AbstractHandlerTest.php is abstract
--
There was 1 PHPUnit test runner deprecation:
1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
--
6 tests triggered 6 PHPUnit deprecations:
1) CodeIgniter\AutoReview\FrameworkCodeTest::testEachTestClassHasCorrectGroupAnnotation
Data Provider method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAnnotation() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/AutoReview/FrameworkCodeTest.php:46
2) CodeIgniter\HTTP\SiteURITest::testConstructor
Data Provider method CodeIgniter\HTTP\SiteURITest::provideConstructor() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/HTTP/SiteURITest.php:32
3) CodeIgniter\Validation\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/CreditCardRulesTest.php:54
4) CodeIgniter\Validation\StrictRules\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\StrictRules\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/StrictRules/CreditCardRulesTest.php:55
5) CodeIgniter\Validation\StrictRules\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\StrictRules\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
6) CodeIgniter\Validation\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
WARNINGS!
Tests: 300, Assertions: 905, Warnings: 1, Deprecations: 7.

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6593809502/job/17916840733?pr=8069

@kenjis

Copy link
Copy Markdown
MemberAuthor
There was 1 PHPUnit test runner warning:
1) Class CodeIgniter\Cache\Handlers\AbstractHandlerTest declared in /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Cache/Handlers/AbstractHandlerTest.php is abstract
--
There was 1 PHPUnit test runner deprecation:
1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
--
There were 41 errors:
1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpers
Test was run in child process and ended unexpectedly
2) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRoute
Test was run in child process and ended unexpectedly
3) CodeIgniter\CodeIgniterTest::testOutputBufferingControl
Test was run in child process and ended unexpectedly
4) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRouteReturnResponse
Test was run in child process and ended unexpectedly
5) CodeIgniter\CodeIgniterTest::testRunClosureRoute
Test was run in child process and ended unexpectedly
6) CodeIgniter\CodeIgniterTest::testRun404Override
Test was run in child process and ended unexpectedly
7) CodeIgniter\CodeIgniterTest::testRun404OverrideControllerReturnsResponse
Test was run in child process and ended unexpectedly
8) CodeIgniter\CodeIgniterTest::testRun404OverrideReturnResponse
Test was run in child process and ended unexpectedly
9) CodeIgniter\CodeIgniterTest::testRun404OverrideByClosure
Test was run in child process and ended unexpectedly
1) CodeIgniter\Validation\StrictRules\ValidationTest::testPlaceholderReplacementTestFails
Failed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.
2) CodeIgniter\Validation\ValidationTest::testPlaceholderReplacementTestFails
Failed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.
--
6 tests triggered 6 PHPUnit deprecations:
1) CodeIgniter\AutoReview\FrameworkCodeTest::testEachTestClassHasCorrectGroupAnnotation
Data Provider method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAnnotation() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/AutoReview/FrameworkCodeTest.php:46
2) CodeIgniter\HTTP\SiteURITest::testConstructor
Data Provider method CodeIgniter\HTTP\SiteURITest::provideConstructor() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/HTTP/SiteURITest.php:32
3) CodeIgniter\Validation\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/CreditCardRulesTest.php:54
4) CodeIgniter\Validation\StrictRules\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\StrictRules\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/StrictRules/CreditCardRulesTest.php:55
5) CodeIgniter\Validation\StrictRules\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\StrictRules\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
6) CodeIgniter\Validation\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
ERRORS!
Tests: 5017, Assertions: 8400, Errors: 41, Failures: 2, Warnings: 1, Deprecations: 7, Skipped: 1.

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6593809497/job/17916881103?pr=8069

@paulbalandan

Copy link
Copy Markdown
Member

The first warning is easy. Just change the name to AbstractHandlerTestCase. Abstract tests need to be suffixed with TestCase.

For the static issues, just run the rule php_unit_data_provider_static for php-cs-fixer

@kenjis

Copy link
Copy Markdown
MemberAuthor

Unfortunately php-cs-fixer was not able to refactor the dataProviders because of $this.

@paulbalandan

Copy link
Copy Markdown
Member

Ah yes. The rule is risky because of uses of $this. Those cases should be modified to use static properties/methods.

@kenjis

Copy link
Copy Markdown
MemberAuthor

Why does this test fail?

$ vendor/bin/phpunit tests/system/Validation/StrictRules/ValidationTest.php PHPUnit 10.4.1 by Sebastian Bergmann and contributors.Runtime: PHP 8.1.24Configuration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml.................................................................................................... 100 / 121 ( 82%)...........F......... 121 / 121 (100%)Time: 00:00.930, Memory: 16.00 MB...--There was 1 failure:1) CodeIgniter\Validation\StrictRules\ValidationTest::testPlaceholderReplacementTestFailsFailed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.FAILURES!Tests: 121, Assertions: 173, Failures: 1, Warnings: 1.

@kenjis

Copy link
Copy Markdown
MemberAuthor

I got the reason. The error message of PHPUnit has been changed.

@MGatnerMGatner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will want to update DevKit as well - not sure when the appropriate time to do that is though, maybe when we actually drop 8.0? I know @paulbalandan is working on Tachycardia comparability - that would be great to include.

Edit: oops! I missed the existing conversation. All good.

@paulbalandan

Copy link
Copy Markdown
Member

nexusphp/tachycardia v2.0 is out

@kenjis
kenjisforce-pushed the update-phpunit-10 branch 2 times, most recently from 2052f1a to a524abcCompareOctober 27, 2023 04:39
@kenjis

Copy link
Copy Markdown
MemberAuthor

I don't know why, but only in PHP 8.3, the NoTestCaseObjectOnCallStackException occurs.

$ vendor/bin/phpunit tests/system/Autoloader/AutoloaderTest.php PHPUnit 10.4.2 by Sebastian Bergmann and contributors.Runtime: PHP 8.3.0-devConfiguration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml..........................E 27 / 27 (100%)Time: 00:00.486, Memory: 16.00 MBThere was 1 error:1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpersPHPUnit\Framework\Exception: PHP Fatal error: Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44Stack trace:#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter->format(Array)#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler->format(Array)#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\Debug\ExceptionHandler->handle(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException))#6 {main} thrown in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php on line 44ERRORS!Tests: 27, Assertions: 45, Errors: 1.

@kenjiskenjis added the help wanted More help is needed for the proper resolution of an issue or pull request label Oct 27, 2023
@kenjis

Copy link
Copy Markdown
MemberAuthor
--- a/system/Format/JSONFormatter.php+++ b/system/Format/JSONFormatter.php@@ -37,6 +37,7 @@ class JSONFormatter implements FormatterInterface
$options = ENVIRONMENT === 'production' ? $options : $options | JSON_PRETTY_PRINT;
+ log_message('debug', var_export($data, true));
$result = json_encode($data, $options, 512);
if (! in_array(json_last_error(), [JSON_ERROR_NONE, JSON_ERROR_RECURSION], true)) {
CRITICAL - 2023-10-27 07:08:34 --> Cannot find TestCase object on call stack
in VENDORPATH/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php on line 63.
1 VENDORPATH/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
2 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke(2, 'rewind(): Stream does not support seeking', 'Standard input code', 71)
3 Standard input code(71): rewind(resource (stream))
4 Standard input code(118): __phpunit_run_isolated_test()
DEBUG - 2023-10-27 07:08:34 --> array (
'title' => 'PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException',
'type' => 'PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException',
'code' => 500,
'message' => 'Cannot find TestCase object on call stack',
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php',
'line' => 63,
'trace' => array (
0 => array (
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php',
'line' => 83,
'function' => 'fromCallStack',
'class' => 'PHPUnit\\Event\\Code\\TestMethodBuilder',
'type' => '::',
'args' => array (
),
),
1 => array (
'function' => '__invoke',
'class' => 'PHPUnit\\Runner\\ErrorHandler',
'type' => '->',
'args' => array (
0 => 2,
1 => 'rewind(): Stream does not support seeking',
2 => 'Standard input code',
3 => 71,
),
),
2 => array (
'file' => 'Standard input code',
'line' => 71,
'function' => 'rewind',
'args' => array (
0 => NULL,
),
),
3 => array (
'file' => 'Standard input code',
'line' => 118,
'function' => '__phpunit_run_isolated_test',
'args' => array (
),
),
),
)
CRITICAL - 2023-10-27 07:08:34 --> Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter->format(Array)
#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler->format(Array)
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\Debug\ExceptionHandler->handle(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)
#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException))
#6 {main}
thrown
【Previous Exception】
PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException
Cannot find TestCase object on call stack
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke(2, 'rewind(): Strea...', 'Standard input ...', 71)
#2 Standard input code(71): rewind(Resource id #2)
#3 Standard input code(118): __phpunit_run_isolated_test()
#4 {main}
in SYSTEMPATH/Format/JSONFormatter.php on line 44.
1 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
DEBUG - 2023-10-27 07:08:34 --> array (
'title' => 'ErrorException',
'type' => 'ErrorException',
'code' => 500,
'message' => 'Uncaught CodeIgniter\\Format\\Exceptions\\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\\Format\\Exceptions\\FormatException::forInvalidJSON(\'Type is not sup...\')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\\Format\\JSONFormatter->format(Array)
#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\\Debug\\ExceptionHandler->format(Array)
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\\Debug\\ExceptionHandler->respond(Array, 500)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\\Debug\\ExceptionHandler->handle(Object(PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\\HTTP\\IncomingRequest), Object(CodeIgniter\\HTTP\\Response), 500, 1)
#5 [internal function]: CodeIgniter\\Debug\\Exceptions->exceptionHandler(Object(PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException))
#6 {main}
thrown
【Previous Exception】
PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException
Cannot find TestCase object on call stack
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\\Event\\Code\\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\\Runner\\ErrorHandler->__invoke(2, \'rewind(): Strea...\', \'Standard input ...\', 71)
#2 Standard input code(71): rewind(Resource id #2)
#3 Standard input code(118): __phpunit_run_isolated_test()
#4 {main}',
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php',
'line' => 44,
'trace' => array (
0 => array (
'function' => 'shutdownHandler',
'class' => 'CodeIgniter\\Debug\\Exceptions',
'type' => '->',
'args' => array (
),
),
),
)

@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Oct 28, 2023
@github-actions

This comment was marked as outdated.

@kenjiskenjis removed the stale Pull requests with conflicts label Oct 30, 2023
@github-actions

This comment was marked as outdated.

@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Nov 30, 2023
@kenjiskenjis removed the stale Pull requests with conflicts label Nov 30, 2023
@kenjis

Copy link
Copy Markdown
MemberAuthor

No good. Tests on PHP 8.3 fails.

There were 42 errors:
1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpers
Test was run in child process and ended unexpectedly
2) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRoute
Test was run in child process and ended unexpectedly
3) CodeIgniter\CodeIgniterTest::testOutputBufferingControl
Test was run in child process and ended unexpectedly

https://github.com/codeigniter4/CodeIgniter4/actions/runs/7043858533/job/19170759175?pr=8069

@kenjis
kenjisforce-pushed the update-phpunit-10 branch 2 times, most recently from 5b2f18f to 47bf62eCompareApril 2, 2024 23:26
@kenjis
kenjis marked this pull request as ready for review April 2, 2024 23:45
@kenjiskenjis changed the title chore: update PHPUnit to 10refactor: update PHPUnit to 10Apr 2, 2024
@kenjis
kenjisforce-pushed the update-phpunit-10 branch from 47bf62e to fe41852CompareApril 6, 2024 00:26
kenjis added 17 commits April 7, 2024 12:38
vendor/bin/phpunit --migrate-configuration -c phpunit.xml.dist
Message: file_put_contents(/home/runner/work/CodeIgniter4/CodeIgniter4/build/coverage/text/coverage.txt): Failed to open stream: No such file or directory
Location: /home/runner/work/CodeIgniter4/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/CodeCoverage.php:317
Script done.
Error: Process completed with exit code 255.
1) CodeIgniter\Database\DatabaseTestCase\DatabaseTestCaseMigrationOnce1Test::testMigrationDone
TypeError: json_encode(): Argument #2 ($flags) must be of type int, bool given
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/Constraints/SeeInDatabase.php:118
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:282
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce1Test.php:86
There was 1 error:
1) CodeIgniter\Security\SecurityCSRFSessionRandomizeTokenTest::testCSRFVerifyPostInvalidToken
PHPUnit\Framework\Exception: PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Security/Security.php on line 378
PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Security/Security.php on line 378
There was 1 error:
1) CodeIgniter\CommonFunctionsTest::testTraceWithCSP
Test was run in child process and ended unexpectedly
@kenjis
kenjisforce-pushed the update-phpunit-10 branch from fe41852 to 9e009e9CompareApril 7, 2024 03:38
@kenjis

Copy link
Copy Markdown
MemberAuthor

Rebased to resolve the conflict.

@kenjis
kenjis merged commit 5c45ef1 into codeigniter4:4.5Apr 7, 2024
@kenjis
kenjis deleted the update-phpunit-10 branch April 7, 2024 03:57
@MGatner

Copy link
Copy Markdown
Member

Happy to see this one launched!

@kenjis

Copy link
Copy Markdown
MemberAuthor

But we still need restore_error_handler() to separate process testing.
I don't know the true cause of the errors.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wantedMore help is needed for the proper resolution of an issue or pull requestrefactorPull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@kenjis@paulbalandan@datamweb@MGatner@michalsn@samsonasik
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

refactor: update PHPUnit to 10 - #8069

Merged
kenjis merged 17 commits into
codeigniter4:4.5from
kenjis:update-phpunit-10
Apr 7, 2024
Merged

refactor: update PHPUnit to 10#8069
kenjis merged 17 commits into
codeigniter4:4.5from
kenjis:update-phpunit-10

Conversation

@kenjis

@kenjiskenjis commented Oct 20, 2023

Copy link
Copy Markdown
Member

Important

This PR will be merged just prior to the release of v4.5.0.

Description
PHPUnit requires PHP 8.1 or later.
https://packagist.org/packages/phpunit/phpunit#10.4.1

https://phpunit.de/announcements/phpunit-10.html

TODO

  • update nexusphp/tachycardia
  • fix errors on PHP 8.3

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjiskenjis added the 4.5 label Oct 20, 2023
@kenjis
kenjis marked this pull request as draft October 20, 2023 23:57
@kenjis

Copy link
Copy Markdown
MemberAuthor

@paulbalandan Any plan to release nexusphp/tachycardia that are compatible with PHPUnit10?

@paulbalandan

Copy link
Copy Markdown
Member

Is it ready but lacking integration tests. I'll try to finish this weekend. Thanks for reminding me.

@kenjis

Copy link
Copy Markdown
MemberAuthor
There was 1 PHPUnit test runner warning:
1) Class CodeIgniter\Cache\Handlers\AbstractHandlerTest declared in /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Cache/Handlers/AbstractHandlerTest.php is abstract
--
There was 1 PHPUnit test runner deprecation:
1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
--
6 tests triggered 6 PHPUnit deprecations:
1) CodeIgniter\AutoReview\FrameworkCodeTest::testEachTestClassHasCorrectGroupAnnotation
Data Provider method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAnnotation() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/AutoReview/FrameworkCodeTest.php:46
2) CodeIgniter\HTTP\SiteURITest::testConstructor
Data Provider method CodeIgniter\HTTP\SiteURITest::provideConstructor() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/HTTP/SiteURITest.php:32
3) CodeIgniter\Validation\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/CreditCardRulesTest.php:54
4) CodeIgniter\Validation\StrictRules\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\StrictRules\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/StrictRules/CreditCardRulesTest.php:55
5) CodeIgniter\Validation\StrictRules\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\StrictRules\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
6) CodeIgniter\Validation\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
WARNINGS!
Tests: 300, Assertions: 905, Warnings: 1, Deprecations: 7.

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6593809502/job/17916840733?pr=8069

@kenjis

Copy link
Copy Markdown
MemberAuthor
There was 1 PHPUnit test runner warning:
1) Class CodeIgniter\Cache\Handlers\AbstractHandlerTest declared in /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Cache/Handlers/AbstractHandlerTest.php is abstract
--
There was 1 PHPUnit test runner deprecation:
1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
--
There were 41 errors:
1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpers
Test was run in child process and ended unexpectedly
2) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRoute
Test was run in child process and ended unexpectedly
3) CodeIgniter\CodeIgniterTest::testOutputBufferingControl
Test was run in child process and ended unexpectedly
4) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRouteReturnResponse
Test was run in child process and ended unexpectedly
5) CodeIgniter\CodeIgniterTest::testRunClosureRoute
Test was run in child process and ended unexpectedly
6) CodeIgniter\CodeIgniterTest::testRun404Override
Test was run in child process and ended unexpectedly
7) CodeIgniter\CodeIgniterTest::testRun404OverrideControllerReturnsResponse
Test was run in child process and ended unexpectedly
8) CodeIgniter\CodeIgniterTest::testRun404OverrideReturnResponse
Test was run in child process and ended unexpectedly
9) CodeIgniter\CodeIgniterTest::testRun404OverrideByClosure
Test was run in child process and ended unexpectedly
1) CodeIgniter\Validation\StrictRules\ValidationTest::testPlaceholderReplacementTestFails
Failed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.
2) CodeIgniter\Validation\ValidationTest::testPlaceholderReplacementTestFails
Failed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.
--
6 tests triggered 6 PHPUnit deprecations:
1) CodeIgniter\AutoReview\FrameworkCodeTest::testEachTestClassHasCorrectGroupAnnotation
Data Provider method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAnnotation() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/AutoReview/FrameworkCodeTest.php:46
2) CodeIgniter\HTTP\SiteURITest::testConstructor
Data Provider method CodeIgniter\HTTP\SiteURITest::provideConstructor() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/HTTP/SiteURITest.php:32
3) CodeIgniter\Validation\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/CreditCardRulesTest.php:54
4) CodeIgniter\Validation\StrictRules\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\StrictRules\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/StrictRules/CreditCardRulesTest.php:55
5) CodeIgniter\Validation\StrictRules\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\StrictRules\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
6) CodeIgniter\Validation\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
ERRORS!
Tests: 5017, Assertions: 8400, Errors: 41, Failures: 2, Warnings: 1, Deprecations: 7, Skipped: 1.

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6593809497/job/17916881103?pr=8069

@paulbalandan

Copy link
Copy Markdown
Member

The first warning is easy. Just change the name to AbstractHandlerTestCase. Abstract tests need to be suffixed with TestCase.

For the static issues, just run the rule php_unit_data_provider_static for php-cs-fixer

@kenjis

Copy link
Copy Markdown
MemberAuthor

Unfortunately php-cs-fixer was not able to refactor the dataProviders because of $this.

@paulbalandan

Copy link
Copy Markdown
Member

Ah yes. The rule is risky because of uses of $this. Those cases should be modified to use static properties/methods.

@kenjis

Copy link
Copy Markdown
MemberAuthor

Why does this test fail?

$ vendor/bin/phpunit tests/system/Validation/StrictRules/ValidationTest.php PHPUnit 10.4.1 by Sebastian Bergmann and contributors.Runtime: PHP 8.1.24Configuration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml.................................................................................................... 100 / 121 ( 82%)...........F......... 121 / 121 (100%)Time: 00:00.930, Memory: 16.00 MB...--There was 1 failure:1) CodeIgniter\Validation\StrictRules\ValidationTest::testPlaceholderReplacementTestFailsFailed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.FAILURES!Tests: 121, Assertions: 173, Failures: 1, Warnings: 1.

@kenjis

Copy link
Copy Markdown
MemberAuthor

I got the reason. The error message of PHPUnit has been changed.

@MGatnerMGatner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will want to update DevKit as well - not sure when the appropriate time to do that is though, maybe when we actually drop 8.0? I know @paulbalandan is working on Tachycardia comparability - that would be great to include.

Edit: oops! I missed the existing conversation. All good.

@paulbalandan

Copy link
Copy Markdown
Member

nexusphp/tachycardia v2.0 is out

@kenjis
kenjisforce-pushed the update-phpunit-10 branch 2 times, most recently from 2052f1a to a524abcCompareOctober 27, 2023 04:39
@kenjis

Copy link
Copy Markdown
MemberAuthor

I don't know why, but only in PHP 8.3, the NoTestCaseObjectOnCallStackException occurs.

$ vendor/bin/phpunit tests/system/Autoloader/AutoloaderTest.php PHPUnit 10.4.2 by Sebastian Bergmann and contributors.Runtime: PHP 8.3.0-devConfiguration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml..........................E 27 / 27 (100%)Time: 00:00.486, Memory: 16.00 MBThere was 1 error:1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpersPHPUnit\Framework\Exception: PHP Fatal error: Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44Stack trace:#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter->format(Array)#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler->format(Array)#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\Debug\ExceptionHandler->handle(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException))#6 {main} thrown in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php on line 44ERRORS!Tests: 27, Assertions: 45, Errors: 1.

@kenjiskenjis added the help wanted More help is needed for the proper resolution of an issue or pull request label Oct 27, 2023
@kenjis

Copy link
Copy Markdown
MemberAuthor
--- a/system/Format/JSONFormatter.php+++ b/system/Format/JSONFormatter.php@@ -37,6 +37,7 @@ class JSONFormatter implements FormatterInterface
$options = ENVIRONMENT === 'production' ? $options : $options | JSON_PRETTY_PRINT;
+ log_message('debug', var_export($data, true));
$result = json_encode($data, $options, 512);
if (! in_array(json_last_error(), [JSON_ERROR_NONE, JSON_ERROR_RECURSION], true)) {
CRITICAL - 2023-10-27 07:08:34 --> Cannot find TestCase object on call stack
in VENDORPATH/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php on line 63.
1 VENDORPATH/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
2 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke(2, 'rewind(): Stream does not support seeking', 'Standard input code', 71)
3 Standard input code(71): rewind(resource (stream))
4 Standard input code(118): __phpunit_run_isolated_test()
DEBUG - 2023-10-27 07:08:34 --> array (
'title' => 'PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException',
'type' => 'PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException',
'code' => 500,
'message' => 'Cannot find TestCase object on call stack',
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php',
'line' => 63,
'trace' => array (
0 => array (
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php',
'line' => 83,
'function' => 'fromCallStack',
'class' => 'PHPUnit\\Event\\Code\\TestMethodBuilder',
'type' => '::',
'args' => array (
),
),
1 => array (
'function' => '__invoke',
'class' => 'PHPUnit\\Runner\\ErrorHandler',
'type' => '->',
'args' => array (
0 => 2,
1 => 'rewind(): Stream does not support seeking',
2 => 'Standard input code',
3 => 71,
),
),
2 => array (
'file' => 'Standard input code',
'line' => 71,
'function' => 'rewind',
'args' => array (
0 => NULL,
),
),
3 => array (
'file' => 'Standard input code',
'line' => 118,
'function' => '__phpunit_run_isolated_test',
'args' => array (
),
),
),
)
CRITICAL - 2023-10-27 07:08:34 --> Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter->format(Array)
#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler->format(Array)
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\Debug\ExceptionHandler->handle(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)
#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException))
#6 {main}
thrown
【Previous Exception】
PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException
Cannot find TestCase object on call stack
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke(2, 'rewind(): Strea...', 'Standard input ...', 71)
#2 Standard input code(71): rewind(Resource id #2)
#3 Standard input code(118): __phpunit_run_isolated_test()
#4 {main}
in SYSTEMPATH/Format/JSONFormatter.php on line 44.
1 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
DEBUG - 2023-10-27 07:08:34 --> array (
'title' => 'ErrorException',
'type' => 'ErrorException',
'code' => 500,
'message' => 'Uncaught CodeIgniter\\Format\\Exceptions\\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\\Format\\Exceptions\\FormatException::forInvalidJSON(\'Type is not sup...\')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\\Format\\JSONFormatter->format(Array)
#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\\Debug\\ExceptionHandler->format(Array)
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\\Debug\\ExceptionHandler->respond(Array, 500)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\\Debug\\ExceptionHandler->handle(Object(PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\\HTTP\\IncomingRequest), Object(CodeIgniter\\HTTP\\Response), 500, 1)
#5 [internal function]: CodeIgniter\\Debug\\Exceptions->exceptionHandler(Object(PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException))
#6 {main}
thrown
【Previous Exception】
PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException
Cannot find TestCase object on call stack
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\\Event\\Code\\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\\Runner\\ErrorHandler->__invoke(2, \'rewind(): Strea...\', \'Standard input ...\', 71)
#2 Standard input code(71): rewind(Resource id #2)
#3 Standard input code(118): __phpunit_run_isolated_test()
#4 {main}',
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php',
'line' => 44,
'trace' => array (
0 => array (
'function' => 'shutdownHandler',
'class' => 'CodeIgniter\\Debug\\Exceptions',
'type' => '->',
'args' => array (
),
),
),
)

@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Oct 28, 2023
@github-actions

This comment was marked as outdated.

@kenjiskenjis removed the stale Pull requests with conflicts label Oct 30, 2023
@github-actions

This comment was marked as outdated.

@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Nov 30, 2023
@kenjiskenjis removed the stale Pull requests with conflicts label Nov 30, 2023
@kenjis

Copy link
Copy Markdown
MemberAuthor

No good. Tests on PHP 8.3 fails.

There were 42 errors:
1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpers
Test was run in child process and ended unexpectedly
2) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRoute
Test was run in child process and ended unexpectedly
3) CodeIgniter\CodeIgniterTest::testOutputBufferingControl
Test was run in child process and ended unexpectedly

https://github.com/codeigniter4/CodeIgniter4/actions/runs/7043858533/job/19170759175?pr=8069

@kenjis
kenjisforce-pushed the update-phpunit-10 branch 2 times, most recently from 5b2f18f to 47bf62eCompareApril 2, 2024 23:26
@kenjis
kenjis marked this pull request as ready for review April 2, 2024 23:45
@kenjiskenjis changed the title chore: update PHPUnit to 10refactor: update PHPUnit to 10Apr 2, 2024
@kenjis
kenjisforce-pushed the update-phpunit-10 branch from 47bf62e to fe41852CompareApril 6, 2024 00:26
kenjis added 17 commits April 7, 2024 12:38
vendor/bin/phpunit --migrate-configuration -c phpunit.xml.dist
Message: file_put_contents(/home/runner/work/CodeIgniter4/CodeIgniter4/build/coverage/text/coverage.txt): Failed to open stream: No such file or directory
Location: /home/runner/work/CodeIgniter4/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/CodeCoverage.php:317
Script done.
Error: Process completed with exit code 255.
1) CodeIgniter\Database\DatabaseTestCase\DatabaseTestCaseMigrationOnce1Test::testMigrationDone
TypeError: json_encode(): Argument #2 ($flags) must be of type int, bool given
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/Constraints/SeeInDatabase.php:118
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:282
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce1Test.php:86
There was 1 error:
1) CodeIgniter\Security\SecurityCSRFSessionRandomizeTokenTest::testCSRFVerifyPostInvalidToken
PHPUnit\Framework\Exception: PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Security/Security.php on line 378
PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Security/Security.php on line 378
There was 1 error:
1) CodeIgniter\CommonFunctionsTest::testTraceWithCSP
Test was run in child process and ended unexpectedly
@kenjis
kenjisforce-pushed the update-phpunit-10 branch from fe41852 to 9e009e9CompareApril 7, 2024 03:38
@kenjis

Copy link
Copy Markdown
MemberAuthor

Rebased to resolve the conflict.

@kenjis
kenjis merged commit 5c45ef1 into codeigniter4:4.5Apr 7, 2024
@kenjis
kenjis deleted the update-phpunit-10 branch April 7, 2024 03:57
@MGatner

Copy link
Copy Markdown
Member

Happy to see this one launched!

@kenjis

Copy link
Copy Markdown
MemberAuthor

But we still need restore_error_handler() to separate process testing.
I don't know the true cause of the errors.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wantedMore help is needed for the proper resolution of an issue or pull requestrefactorPull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@kenjis@paulbalandan@datamweb@MGatner@michalsn@samsonasik
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

refactor: update PHPUnit to 10 - #8069

Merged
kenjis merged 17 commits into
codeigniter4:4.5from
kenjis:update-phpunit-10
Apr 7, 2024
Merged

refactor: update PHPUnit to 10#8069
kenjis merged 17 commits into
codeigniter4:4.5from
kenjis:update-phpunit-10

Conversation

@kenjis

@kenjiskenjis commented Oct 20, 2023

Copy link
Copy Markdown
Member

Important

This PR will be merged just prior to the release of v4.5.0.

Description
PHPUnit requires PHP 8.1 or later.
https://packagist.org/packages/phpunit/phpunit#10.4.1

https://phpunit.de/announcements/phpunit-10.html

TODO

  • update nexusphp/tachycardia
  • fix errors on PHP 8.3

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjiskenjis added the 4.5 label Oct 20, 2023
@kenjis
kenjis marked this pull request as draft October 20, 2023 23:57
@kenjis

Copy link
Copy Markdown
MemberAuthor

@paulbalandan Any plan to release nexusphp/tachycardia that are compatible with PHPUnit10?

@paulbalandan

Copy link
Copy Markdown
Member

Is it ready but lacking integration tests. I'll try to finish this weekend. Thanks for reminding me.

@kenjis

Copy link
Copy Markdown
MemberAuthor
There was 1 PHPUnit test runner warning:
1) Class CodeIgniter\Cache\Handlers\AbstractHandlerTest declared in /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Cache/Handlers/AbstractHandlerTest.php is abstract
--
There was 1 PHPUnit test runner deprecation:
1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
--
6 tests triggered 6 PHPUnit deprecations:
1) CodeIgniter\AutoReview\FrameworkCodeTest::testEachTestClassHasCorrectGroupAnnotation
Data Provider method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAnnotation() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/AutoReview/FrameworkCodeTest.php:46
2) CodeIgniter\HTTP\SiteURITest::testConstructor
Data Provider method CodeIgniter\HTTP\SiteURITest::provideConstructor() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/HTTP/SiteURITest.php:32
3) CodeIgniter\Validation\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/CreditCardRulesTest.php:54
4) CodeIgniter\Validation\StrictRules\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\StrictRules\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/StrictRules/CreditCardRulesTest.php:55
5) CodeIgniter\Validation\StrictRules\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\StrictRules\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
6) CodeIgniter\Validation\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
WARNINGS!
Tests: 300, Assertions: 905, Warnings: 1, Deprecations: 7.

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6593809502/job/17916840733?pr=8069

@kenjis

Copy link
Copy Markdown
MemberAuthor
There was 1 PHPUnit test runner warning:
1) Class CodeIgniter\Cache\Handlers\AbstractHandlerTest declared in /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Cache/Handlers/AbstractHandlerTest.php is abstract
--
There was 1 PHPUnit test runner deprecation:
1) Your XML configuration validates against a deprecated schema. Migrate your XML configuration using "--migrate-configuration"!
--
There were 41 errors:
1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpers
Test was run in child process and ended unexpectedly
2) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRoute
Test was run in child process and ended unexpectedly
3) CodeIgniter\CodeIgniterTest::testOutputBufferingControl
Test was run in child process and ended unexpectedly
4) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRouteReturnResponse
Test was run in child process and ended unexpectedly
5) CodeIgniter\CodeIgniterTest::testRunClosureRoute
Test was run in child process and ended unexpectedly
6) CodeIgniter\CodeIgniterTest::testRun404Override
Test was run in child process and ended unexpectedly
7) CodeIgniter\CodeIgniterTest::testRun404OverrideControllerReturnsResponse
Test was run in child process and ended unexpectedly
8) CodeIgniter\CodeIgniterTest::testRun404OverrideReturnResponse
Test was run in child process and ended unexpectedly
9) CodeIgniter\CodeIgniterTest::testRun404OverrideByClosure
Test was run in child process and ended unexpectedly
1) CodeIgniter\Validation\StrictRules\ValidationTest::testPlaceholderReplacementTestFails
Failed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.
2) CodeIgniter\Validation\ValidationTest::testPlaceholderReplacementTestFails
Failed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.
--
6 tests triggered 6 PHPUnit deprecations:
1) CodeIgniter\AutoReview\FrameworkCodeTest::testEachTestClassHasCorrectGroupAnnotation
Data Provider method CodeIgniter\AutoReview\FrameworkCodeTest::provideEachTestClassHasCorrectGroupAnnotation() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/AutoReview/FrameworkCodeTest.php:46
2) CodeIgniter\HTTP\SiteURITest::testConstructor
Data Provider method CodeIgniter\HTTP\SiteURITest::provideConstructor() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/HTTP/SiteURITest.php:32
3) CodeIgniter\Validation\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/CreditCardRulesTest.php:54
4) CodeIgniter\Validation\StrictRules\CreditCardRulesTest::testValidCCNumber
Data Provider method CodeIgniter\Validation\StrictRules\CreditCardRulesTest::provideValidCCNumber() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/StrictRules/CreditCardRulesTest.php:55
5) CodeIgniter\Validation\StrictRules\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\StrictRules\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
6) CodeIgniter\Validation\ValidationTest::testSetRuleRulesFormat
Data Provider method CodeIgniter\Validation\ValidationTest::provideSetRuleRulesFormat() is not static
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Validation/ValidationTest.php:193
ERRORS!
Tests: 5017, Assertions: 8400, Errors: 41, Failures: 2, Warnings: 1, Deprecations: 7, Skipped: 1.

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6593809497/job/17916881103?pr=8069

@paulbalandan

Copy link
Copy Markdown
Member

The first warning is easy. Just change the name to AbstractHandlerTestCase. Abstract tests need to be suffixed with TestCase.

For the static issues, just run the rule php_unit_data_provider_static for php-cs-fixer

@kenjis

Copy link
Copy Markdown
MemberAuthor

Unfortunately php-cs-fixer was not able to refactor the dataProviders because of $this.

@paulbalandan

Copy link
Copy Markdown
Member

Ah yes. The rule is risky because of uses of $this. Those cases should be modified to use static properties/methods.

@kenjis

Copy link
Copy Markdown
MemberAuthor

Why does this test fail?

$ vendor/bin/phpunit tests/system/Validation/StrictRules/ValidationTest.php PHPUnit 10.4.1 by Sebastian Bergmann and contributors.Runtime: PHP 8.1.24Configuration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml.................................................................................................... 100 / 121 ( 82%)...........F......... 121 / 121 (100%)Time: 00:00.930, Memory: 16.00 MB...--There was 1 failure:1) CodeIgniter\Validation\StrictRules\ValidationTest::testPlaceholderReplacementTestFailsFailed asserting that exception message 'Failed asserting that 'filter[{id}]' [ASCII](length: 12) does not contain "{id}" [ASCII](length: 4).' contains 'Failed asserting that 'filter[{id}]' does not contain "{id}".'.FAILURES!Tests: 121, Assertions: 173, Failures: 1, Warnings: 1.

@kenjis

Copy link
Copy Markdown
MemberAuthor

I got the reason. The error message of PHPUnit has been changed.

@MGatnerMGatner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will want to update DevKit as well - not sure when the appropriate time to do that is though, maybe when we actually drop 8.0? I know @paulbalandan is working on Tachycardia comparability - that would be great to include.

Edit: oops! I missed the existing conversation. All good.

@paulbalandan

Copy link
Copy Markdown
Member

nexusphp/tachycardia v2.0 is out

@kenjis
kenjisforce-pushed the update-phpunit-10 branch 2 times, most recently from 2052f1a to a524abcCompareOctober 27, 2023 04:39
@kenjis

Copy link
Copy Markdown
MemberAuthor

I don't know why, but only in PHP 8.3, the NoTestCaseObjectOnCallStackException occurs.

$ vendor/bin/phpunit tests/system/Autoloader/AutoloaderTest.php PHPUnit 10.4.2 by Sebastian Bergmann and contributors.Runtime: PHP 8.3.0-devConfiguration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml..........................E 27 / 27 (100%)Time: 00:00.486, Memory: 16.00 MBThere was 1 error:1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpersPHPUnit\Framework\Exception: PHP Fatal error: Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44Stack trace:#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter->format(Array)#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler->format(Array)#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\Debug\ExceptionHandler->handle(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException))#6 {main} thrown in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php on line 44ERRORS!Tests: 27, Assertions: 45, Errors: 1.

@kenjiskenjis added the help wanted More help is needed for the proper resolution of an issue or pull request label Oct 27, 2023
@kenjis

Copy link
Copy Markdown
MemberAuthor
--- a/system/Format/JSONFormatter.php+++ b/system/Format/JSONFormatter.php@@ -37,6 +37,7 @@ class JSONFormatter implements FormatterInterface
$options = ENVIRONMENT === 'production' ? $options : $options | JSON_PRETTY_PRINT;
+ log_message('debug', var_export($data, true));
$result = json_encode($data, $options, 512);
if (! in_array(json_last_error(), [JSON_ERROR_NONE, JSON_ERROR_RECURSION], true)) {
CRITICAL - 2023-10-27 07:08:34 --> Cannot find TestCase object on call stack
in VENDORPATH/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php on line 63.
1 VENDORPATH/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
2 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke(2, 'rewind(): Stream does not support seeking', 'Standard input code', 71)
3 Standard input code(71): rewind(resource (stream))
4 Standard input code(118): __phpunit_run_isolated_test()
DEBUG - 2023-10-27 07:08:34 --> array (
'title' => 'PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException',
'type' => 'PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException',
'code' => 500,
'message' => 'Cannot find TestCase object on call stack',
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php',
'line' => 63,
'trace' => array (
0 => array (
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php',
'line' => 83,
'function' => 'fromCallStack',
'class' => 'PHPUnit\\Event\\Code\\TestMethodBuilder',
'type' => '::',
'args' => array (
),
),
1 => array (
'function' => '__invoke',
'class' => 'PHPUnit\\Runner\\ErrorHandler',
'type' => '->',
'args' => array (
0 => 2,
1 => 'rewind(): Stream does not support seeking',
2 => 'Standard input code',
3 => 71,
),
),
2 => array (
'file' => 'Standard input code',
'line' => 71,
'function' => 'rewind',
'args' => array (
0 => NULL,
),
),
3 => array (
'file' => 'Standard input code',
'line' => 118,
'function' => '__phpunit_run_isolated_test',
'args' => array (
),
),
),
)
CRITICAL - 2023-10-27 07:08:34 --> Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\Format\Exceptions\FormatException::forInvalidJSON('Type is not sup...')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\Format\JSONFormatter->format(Array)
#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\Debug\ExceptionHandler->format(Array)
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\Debug\ExceptionHandler->respond(Array, 500)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\Debug\ExceptionHandler->handle(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), 500, 1)
#5 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException))
#6 {main}
thrown
【Previous Exception】
PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException
Cannot find TestCase object on call stack
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\Event\Code\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\Runner\ErrorHandler->__invoke(2, 'rewind(): Strea...', 'Standard input ...', 71)
#2 Standard input code(71): rewind(Resource id #2)
#3 Standard input code(118): __phpunit_run_isolated_test()
#4 {main}
in SYSTEMPATH/Format/JSONFormatter.php on line 44.
1 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
DEBUG - 2023-10-27 07:08:34 --> array (
'title' => 'ErrorException',
'type' => 'ErrorException',
'code' => 500,
'message' => 'Uncaught CodeIgniter\\Format\\Exceptions\\FormatException: Failed to parse JSON string. Error: Type is not supported in /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php:44
Stack trace:
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php(44): CodeIgniter\\Format\\Exceptions\\FormatException::forInvalidJSON(\'Type is not sup...\')
#1 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(345): CodeIgniter\\Format\\JSONFormatter->format(Array)
#2 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/API/ResponseTrait.php(98): CodeIgniter\\Debug\\ExceptionHandler->format(Array)
#3 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/ExceptionHandler.php(81): CodeIgniter\\Debug\\ExceptionHandler->respond(Array, 500)
#4 /Users/kenji/work/codeigniter/official/CodeIgniter4/system/Debug/Exceptions.php(148): CodeIgniter\\Debug\\ExceptionHandler->handle(Object(PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException), Object(CodeIgniter\\HTTP\\IncomingRequest), Object(CodeIgniter\\HTTP\\Response), 500, 1)
#5 [internal function]: CodeIgniter\\Debug\\Exceptions->exceptionHandler(Object(PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException))
#6 {main}
thrown
【Previous Exception】
PHPUnit\\Event\\Code\\NoTestCaseObjectOnCallStackException
Cannot find TestCase object on call stack
#0 /Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/ErrorHandler.php(83): PHPUnit\\Event\\Code\\TestMethodBuilder::fromCallStack()
#1 [internal function]: PHPUnit\\Runner\\ErrorHandler->__invoke(2, \'rewind(): Strea...\', \'Standard input ...\', 71)
#2 Standard input code(71): rewind(Resource id #2)
#3 Standard input code(118): __phpunit_run_isolated_test()
#4 {main}',
'file' => '/Users/kenji/work/codeigniter/official/CodeIgniter4/system/Format/JSONFormatter.php',
'line' => 44,
'trace' => array (
0 => array (
'function' => 'shutdownHandler',
'class' => 'CodeIgniter\\Debug\\Exceptions',
'type' => '->',
'args' => array (
),
),
),
)

@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Oct 28, 2023
@github-actions

This comment was marked as outdated.

@kenjiskenjis removed the stale Pull requests with conflicts label Oct 30, 2023
@github-actions

This comment was marked as outdated.

@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Nov 30, 2023
@kenjiskenjis removed the stale Pull requests with conflicts label Nov 30, 2023
@kenjis

Copy link
Copy Markdown
MemberAuthor

No good. Tests on PHP 8.3 fails.

There were 42 errors:
1) CodeIgniter\Autoloader\AutoloaderTest::testLoadHelpers
Test was run in child process and ended unexpectedly
2) CodeIgniter\CodeIgniterTest::testRunEmptyDefaultRoute
Test was run in child process and ended unexpectedly
3) CodeIgniter\CodeIgniterTest::testOutputBufferingControl
Test was run in child process and ended unexpectedly

https://github.com/codeigniter4/CodeIgniter4/actions/runs/7043858533/job/19170759175?pr=8069

@kenjis
kenjisforce-pushed the update-phpunit-10 branch 2 times, most recently from 5b2f18f to 47bf62eCompareApril 2, 2024 23:26
@kenjis
kenjis marked this pull request as ready for review April 2, 2024 23:45
@kenjiskenjis changed the title chore: update PHPUnit to 10refactor: update PHPUnit to 10Apr 2, 2024
@kenjis
kenjisforce-pushed the update-phpunit-10 branch from 47bf62e to fe41852CompareApril 6, 2024 00:26
kenjis added 17 commits April 7, 2024 12:38
vendor/bin/phpunit --migrate-configuration -c phpunit.xml.dist
Message: file_put_contents(/home/runner/work/CodeIgniter4/CodeIgniter4/build/coverage/text/coverage.txt): Failed to open stream: No such file or directory
Location: /home/runner/work/CodeIgniter4/CodeIgniter4/vendor/phpunit/phpunit/src/Runner/CodeCoverage.php:317
Script done.
Error: Process completed with exit code 255.
1) CodeIgniter\Database\DatabaseTestCase\DatabaseTestCaseMigrationOnce1Test::testMigrationDone
TypeError: json_encode(): Argument #2 ($flags) must be of type int, bool given
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/Constraints/SeeInDatabase.php:118
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:282
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce1Test.php:86
There was 1 error:
1) CodeIgniter\Security\SecurityCSRFSessionRandomizeTokenTest::testCSRFVerifyPostInvalidToken
PHPUnit\Framework\Exception: PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Security/Security.php on line 378
PHP Warning: hex2bin(): Hexadecimal input string must have an even length in /home/runner/work/CodeIgniter4/CodeIgniter4/system/Security/Security.php on line 378
There was 1 error:
1) CodeIgniter\CommonFunctionsTest::testTraceWithCSP
Test was run in child process and ended unexpectedly
@kenjis
kenjisforce-pushed the update-phpunit-10 branch from fe41852 to 9e009e9CompareApril 7, 2024 03:38
@kenjis

Copy link
Copy Markdown
MemberAuthor

Rebased to resolve the conflict.

@kenjis
kenjis merged commit 5c45ef1 into codeigniter4:4.5Apr 7, 2024
@kenjis
kenjis deleted the update-phpunit-10 branch April 7, 2024 03:57
@MGatner

Copy link
Copy Markdown
Member

Happy to see this one launched!

@kenjis

Copy link
Copy Markdown
MemberAuthor

But we still need restore_error_handler() to separate process testing.
I don't know the true cause of the errors.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wantedMore help is needed for the proper resolution of an issue or pull requestrefactorPull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@kenjis@paulbalandan@datamweb@MGatner@michalsn@samsonasik