getMockBuilder(TimezoneInterface::class)->getMock(); $timezone->method('date')->willReturn(new \DateTime($this->testDate)); $expected = gmdate('U', strtotime($this->testDate)); $this->assertEquals($expected, (new DateTime($timezone))->gmtTimestamp($input)); } /** * @param int|string|\DateTimeInterface $input * @dataProvider dateTimeInputDataProvider */ public function testTimestamp($input) { /** @var TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject $timezone */ $timezone = $this->getMockBuilder(TimezoneInterface::class)->getMock(); $timezone->method('date')->willReturn(new \DateTime($this->testDate)); $expected = gmdate('U', strtotime($this->testDate)); $this->assertEquals($expected, (new DateTime($timezone))->timestamp($input)); } /** * @return array */ public function dateTimeInputDataProvider() { return [ 'string' => [$this->testDate], 'int' => [strtotime($this->testDate)], \DateTimeInterface::class => [new \DateTimeImmutable($this->testDate)], ]; } }