-
Notifications
You must be signed in to change notification settings - Fork 44
Description
We have just started using Timecop for controlling time in our unit tests. Works REALLY well.
We also run PHPStan against all our code, to make sure things are sane and that they obey our standards.
One of the things the PHPStan is picking up on is a lack of a constructor in Timecop's DateTimeImmutable.
I've linked the PHPStan issue above, but the here is a snippet of the code and the error that PHPStan is generating.
<?php
namespace DT\ValueObjects;
use DateTimeImmutable;
class DateTimeMicro extends DateTimeImmutable
{
public function __construct($time = 'now', $timezone = null)
{
if ($time === 'now') {
list($dateTime, $micro) = explode('.', microtime(true));
$time = date('Y-m-d H:i:s.', $dateTime).$micro;
}
parent::__construct($time, $timezone);
}
}With the Timecop extension enabled, we'll get an error:
DT\ValueObjects\DateTimeMicro::__construct() calls parent constructor but parent does not have one.
We have now configured things to only enable Timecop when running unit tests and use a polyfill for the Timecop functions we are using for PHPStan. That is all working fine.
But it is all a bit of a kerfuffle which could probably be fixed within Timecop.