CC-5651: Unit Test the Scheduler

Fixed show_service unit tests so they can access private/protected methods
This commit is contained in:
drigato 2014-01-20 12:20:05 -05:00
parent bdf5dc4982
commit e9d2874e83

View file

@ -5,10 +5,15 @@ require_once "ShowServiceData.php";
class ShowServiceUnitTest extends PHPUnit_Framework_TestCase class ShowServiceUnitTest extends PHPUnit_Framework_TestCase
{ {
// needed for accessing private methods
protected $_reflectionOfShowService;
protected $_showService; protected $_showService;
public function setUp() public function setUp()
{ {
$this->_reflectionOfShowService = new ReflectionClass('Application_Service_ShowService');
$this->_showService = new Application_Service_ShowService(); $this->_showService = new Application_Service_ShowService();
} }
@ -26,47 +31,49 @@ class ShowServiceUnitTest extends PHPUnit_Framework_TestCase
public function testCalculateEndDate() public function testCalculateEndDate()
{ {
$end = $this->_showService->calculateEndDate(ShowServiceData::getNoRepeatNoRRData()); $method = $this->_reflectionOfShowService->getMethod('calculateEndDate');
$method->setAccessible(true);
$end = $method->invokeArgs($this->_showService, array(ShowServiceData::getNoRepeatNoRRData()));
$this->assertEquals(null, $end); $this->assertEquals(null, $end);
$end = $this->_showService->calculateEndDate(ShowServiceData::getWeeklyRepeatWithEndNoRRData()); $end = $method->invokeArgs($this->_showService, array(ShowServiceData::getWeeklyRepeatWithEndNoRRData()));
$this->assertEquals(new DateTime("2016-01-27", new DateTimeZone("UTC")), $end); $this->assertEquals(new DateTime("2016-01-27", new DateTimeZone("UTC")), $end);
$end = $this->_showService->calculateEndDate(ShowServiceData::getWeeklyRepeatNoEndNoRRData()); $end = $method->invokeArgs($this->_showService, array(ShowServiceData::getWeeklyRepeatNoEndNoRRData()));
$this->assertEquals(null, $end); $this->assertEquals(null, $end);
} }
public function testGetMonthlyWeeklyRepeatInterval() public function testGetMonthlyWeeklyRepeatInterval()
{ {
$repeatInterval = $this->_showService->getMonthlyWeeklyRepeatInterval( $method = $this->_reflectionOfShowService->getMethod('getMonthlyWeeklyRepeatInterval');
new DateTime("2016-01-01"), new DateTimeZone("UTC")); $method->setAccessible(true);
$repeatInterval = $method->invokeArgs($this->_showService, array(new DateTime("2016-01-01"), new DateTimeZone("UTC")));
$this->assertEquals(array("first", "Friday"), $repeatInterval); $this->assertEquals(array("first", "Friday"), $repeatInterval);
$repeatInterval = $this->_showService->getMonthlyWeeklyRepeatInterval( $repeatInterval = $method->invokeArgs($this->_showService, array(new DateTime("2016-01-12"), new DateTimeZone("UTC")));
new DateTime("2016-01-12"), new DateTimeZone("UTC"));
$this->assertEquals(array("second", "Tuesday"), $repeatInterval); $this->assertEquals(array("second", "Tuesday"), $repeatInterval);
$repeatInterval = $this->_showService->getMonthlyWeeklyRepeatInterval( $repeatInterval = $method->invokeArgs($this->_showService, array(new DateTime("2016-01-18"), new DateTimeZone("UTC")));
new DateTime("2016-01-18"), new DateTimeZone("UTC"));
$this->assertEquals(array("third", "Monday"), $repeatInterval); $this->assertEquals(array("third", "Monday"), $repeatInterval);
$repeatInterval = $this->_showService->getMonthlyWeeklyRepeatInterval( $repeatInterval = $method->invokeArgs($this->_showService, array(new DateTime("2016-01-28"), new DateTimeZone("UTC")));
new DateTime("2016-01-28"), new DateTimeZone("UTC"));
$this->assertEquals(array("fourth", "Thursday"), $repeatInterval); $this->assertEquals(array("fourth", "Thursday"), $repeatInterval);
$repeatInterval = $this->_showService->getMonthlyWeeklyRepeatInterval( $repeatInterval = $method->invokeArgs($this->_showService, array(new DateTime("2016-01-30"), new DateTimeZone("UTC")));
new DateTime("2016-01-30"), new DateTimeZone("UTC"));
$this->assertEquals(array("fifth", "Saturday"), $repeatInterval); $this->assertEquals(array("fifth", "Saturday"), $repeatInterval);
} }
public function testGetNextMonthlyMonthlyRepeatDate() public function testGetNextMonthlyMonthlyRepeatDate()
{ {
$next = $this->_showService->getNextMonthlyMonthlyRepeatDate( $method = $this->_reflectionOfShowService->getMethod('getNextMonthlyMonthlyRepeatDate');
new DateTime("2016-01-01"), "UTC", "00:00"); $method->setAccessible(true);
$next = $method->invokeArgs($this->_showService, array(new DateTime("2016-01-01"), "UTC", "00:00"));
$this->assertEquals(new DateTime("2016-02-01", new DateTimeZone("UTC")), $next); $this->assertEquals(new DateTime("2016-02-01", new DateTimeZone("UTC")), $next);
$next = $this->_showService->getNextMonthlyMonthlyRepeatDate( $next = $method->invokeArgs($this->_showService, array(new DateTime("2016-01-30"), "UTC", "00:00"));
new DateTime("2016-01-30"), "UTC", "00:00");
$this->assertEquals(new DateTime("2016-03-30", new DateTimeZone("UTC")), $next); $this->assertEquals(new DateTime("2016-03-30", new DateTimeZone("UTC")), $next);
} }