Functional tests Nette\Application\Application::$maxLoops
martinstainer opened this issue · comments
Hi,
I have multiple functional tests in my application. Each test sends at least one request to Nette\Application\Application::$requests. The 'requests' property contains the previous tests requests. This leads to a growing collection of requests, which after few tests causes an exception to be thrown at Application::140 if the number of requests exceeds the limit defined in $this->maxLoop.
Nette\Application\Application:140
if (count($this->requests) > $this->maxLoop) {
throw new ApplicationException('Too many loops detected in application life cycle.');
}
I believe I have found a simple solution for this issue by clearing the requests property after each test.
I have added the following code to the NetteApplicationModule::_after method:
public function _after(TestInterface $test): void
{
parent::_after($test);
/** @var NetteDIModule $diModule */
$diModule = $this->getModule(NetteDIModule::class);
/** @var Application $application */
$application = $diModule->grabService(Application::class);
$reflectionClass = new \ReflectionClass($application);
$property = $reflectionClass->getProperty('requests');
$property->setAccessible(true);
$property->setValue($application, []);
$_SESSION = [];
$_GET = [];
$_POST = [];
$_FILES = [];
$_COOKIE = [];
}
I am unsure if this is the best solution, so I would appreciate your thoughts. If you believe this is a suitable solution, please let me know and I will create a pull request.
Thank you for your time and efforts.
You can rebuild the container for every test or set max loop via config.
application:
setup:
- $maxLoop = 100000