public function testTruncate()
{
// Unknown unit
try {
$time = Time::now()->truncate('unknown');
$this->fail(sprintf('Expected exception %s.', \InvalidArgumentException::class));
} catch (\PHPUnit_Framework_AssertionFailedError $e) {
throw $e;
} catch (\Exception $e) {
// Correctly thrown exception
$this->assertInstanceOf(\InvalidArgumentException::class, $e);
}
$tests = [Time::SECOND => '2004-05-06 07:08:09', Time::MINUTE => '2004-05-06 07:08:00', Time::HOUR => '2004-05-06 07:00:00', Time::DAY => '2004-05-06 00:00:00', Time::MONTH => '2004-05-01 00:00:00', Time::YEAR => '2004-01-01 00:00:00'];
$time = new Time('2004-05-06 07:08:09');
foreach ($tests as $unit => $expected) {
$this->assertEquals(Time::get($expected), $time->truncate($unit));
}
}