Skip to content

Instantly share code, notes, and snippets.

@tomasnorre
Last active October 13, 2015 19:02
Show Gist options
  • Save tomasnorre/86ae534667f2091ff062 to your computer and use it in GitHub Desktop.
Save tomasnorre/86ae534667f2091ff062 to your computer and use it in GitHub Desktop.
/**
* @test
*
* @param $isRunning
* @param $starttime
* @param $starttimeFormatted
* @param $endtime
* @param $endtimeFormatted
* @param $expectedString
*
* @dataProvider getTimespanReturnsStringDataProvider()
*/
public function getTimespanReturnsString($isRunning, $starttime, $starttimeFormatted, $endtime, $endtimeFormatted, $expectedString) {
$stub = $this->getAccessibleMock(
'Tx_SchedulerTimeline_Domain_Model_Log',
array('isRunning','getStarttime', 'getEndtime', 'getFormattedDateFromTimestamp')
);
$stub->expects($this->any())->method('isRunning')->willReturn($isRunning);
$stub->expects($this->any())->method('getStarttime')->willReturn($starttime);
$stub->expects($this->any())->method('getEndtime')->willReturn($endtime);
$stub->expects($this->at(1))
->method('getFormattedDateFromTimestamp')
->willReturn($starttimeFormatted);
$stub->expects($this->at(2))
->method('getFormattedDateFromTimestamp')
->willReturn($endtimeFormatted);
$this->assertSame(
$expectedString,
$stub->getTimespan()
);
}
/**
* @return array
*/
public function getTimespanReturnsStringDataProvider() {
return array(
'Task zero as starttime, task still running no endtime' => array(
'isRunning' => TRUE,
'starttime' => 0,
'starttimeFormatted' => '01:00',
'endtime' => NULL,
'endtimeFormatted' => NULL,
'expectedString' => '01:00 - (still running)'
),
'Task with starttime 2015-10-13 16:26 and no endtime' => array(
'isRunning' => TRUE,
'starttime' => 1444746403,
'starttimeFormatted' => '16:26',
'endtime' => NULL,
'endtimeFormatted' => NULL,
'expectedString' => '16:26 - (still running)'
),
'Task with starttime 2015-11-13 9:26 and endtime 2015-11-13 10:13' => array(
'isRunning' => FALSE,
'starttime' => 1447403203,
'starttimeFormatted' => '09:26',
'endtime' => 1447406023,
'endtimeFormatted' => '10:13',
'expectedString' => '09:26 - 10:13'
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment