/** * @dataProvider fromFormatProvider * * @covers ::fromFormat * * @param string $format * @param string $dateTime * @param string $timezone * @param string $expected */ public function test_fromFormat($format, $dateTime, $timezone, $expected) { // When $dt = null; try { $gotErrMsg = ''; /** @var DateTime $dt */ $dt = DateTime::fromFormat($format, $dateTime, $timezone); } catch (\Exception $e) { $gotErrMsg = $e->getMessage(); } // Then if ($gotErrMsg) { $this->assertSame(null, $dt); $this->assertSame('Unexpected data found.', $gotErrMsg); } else { $this->assertSame($expected, $dt->format(DateTime::ATOM)); } }