You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.
Running a unit test with @runInSeparateProcess fails with an error:
PHPUnit 5.7.25 by Sebastian Bergmann and contributors.
E 1 / 1 (100%)
Time: 203 ms, Memory: 8.00MB
There was 1 error:
1) Vendor\Package\Tests\Unit\MyTestCase::myTest
PHPUnit_Framework_Exception: PHP Fatal error: Uncaught RuntimeException: TYPO3_REQUESTTYPE has already been set, cannot be called multiple times in /.../vendor/typo3/cms/typo3/sysext/core/Classes/Core/Bootstrap.php:714
Stack trace:
#0 /.../vendor/nimut/testing-framework/src/TestingFramework/Bootstrap/Bootstrap.php(46): TYPO3\CMS\Core\Core\Bootstrap->setRequestType(6)
#1 /.../vendor/nimut/testing-framework/src/TestingFramework/Bootstrap/AbstractBootstrap.php(76): Nimut\TestingFramework\Bootstrap\Bootstrap->includeAndStartCoreBootstrap()
#2 /.../vendor/nimut/testing-framework/res/Configuration/UnitTestsBootstrap.php(35): Nimut\TestingFramework\Bootstrap\AbstractBootstrap->bootstrapUnitTestSystem()
#3 /.../vendor/nimut/testing-framework/res/Configuration/UnitTestsBootstrap.php(36): {closure}()
#4 -(463): require_once('/var/www/web/ty...')
#5 {main}
thrown in /.../vendor/typo3/cms/typo3/sysext/core/Classes/Core/Bootstrap.php on line 714
/.../vendor/phpunit/phpunit/phpunit:52
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
Any idea how to fix this?
The text was updated successfully, but these errors were encountered:
I wondered, why it works for the typo3/testing-framwork and had a closer look into it. It works there, because ->setRequestType is not called for unit test bootstrap.
Here is what phpunit does for isolated tests:
gather all defined constants of current process and write them as code into a template file
gather all included files of current process and write them as code into a template file
A new process is started and the generated file is evaluated.
First all constants are defined, then all files are included.
Because of the UnitTestBootstrap.php file was among the included files it is included as well. However the TYPO3_REQUESTTYPE was already defined before.
With a bit of luck, it works for typo3/testing-framework because the bootstrap executed there does not re-define constants defined before, but in general such issues could occur there as well.
This would be pretty tough to fix thoroughly. But maybe we should indeed consider not setting request type for unit test bootstrap. no unit test should rely on this constant to be set anyway imho (in general no unit test should rely on global constants, but that is a different story).
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Running a unit test with
@runInSeparateProcess
fails with an error:Any idea how to fix this?
The text was updated successfully, but these errors were encountered: