I have such as Testcase:
class GenerateTest extends AbstractTestCase
{
private int $requestTime = 0;
...
protected function setUp(): void
{
$this->requestTime = $_SERVER['REQUEST_TIME']; // this is not null, verified by var_dump()
parent::setUp();
}
protected function tearDown(): void
{
parent::tearDown();
$_SERVER['REQUEST_TIME'] = $this->requestTime;
}
I am getting the error
Cannot assign null to property GenerateTest::$requestTime of type int"
without a line number.
Even if I comment the lines in setup/teardown, I get the error. In the class are no further assignments to requestTime
.
Where does this come from?
If i use ?int
it works, but I want to understand the root cause.
Does PHPUnit “automagically” reset class variables?
EDIT:
<?php
declare(strict_types=1);
class Test extends PHPUnitFrameworkTestCase
{
private int $requestTime = 0;
protected function setUp(): void
{
$this->requestTime = $_SERVER['REQUEST_TIME']; // this is not null, verified by var_dump()
parent::setUp();
}
protected function tearDown(): void
{
parent::tearDown();
$_SERVER['REQUEST_TIME'] = $this->requestTime;
}
public function testFoo()
{
}
}
is NOT an MRE – problem is not reproducible here. This is an integration test in Magento 2 context, have to dig futher.