/** * @dataProvider taskShouldBeExecutedTestCases */ public function testTaskShouldBeExecuted($expectedDecision, $taskName, $timetable) { self::stubPiwikOption(serialize($timetable)); $timetable = new Timetable(); $this->assertEquals($expectedDecision, $timetable->shouldExecuteTask($taskName)); self::resetPiwikOption(); }
/** * @dataProvider runDataProvider */ public function testRun($expectedTimetable, $expectedExecutedTasks, $timetableBeforeTaskExecution, $configuredTasks) { $taskLoader = $this->getMock('Piwik\\Scheduler\\TaskLoader'); $taskLoader->expects($this->atLeastOnce())->method('loadTasks')->willReturn($configuredTasks); // stub the piwik option object to control the returned option value self::stubPiwikOption(serialize($timetableBeforeTaskExecution)); $scheduler = new Scheduler($taskLoader, new NullLogger()); // execute tasks $executionResults = $scheduler->run(); // assert methods are executed $executedTasks = array(); foreach ($executionResults as $executionResult) { $executedTasks[] = $executionResult['task']; $this->assertNotEmpty($executionResult['output']); } $this->assertEquals($expectedExecutedTasks, $executedTasks); // assert the timetable is correctly updated $timetable = new Timetable(); $this->assertEquals($expectedTimetable, $timetable->getTimetable()); self::resetPiwikOption(); }
/** * @dataProvider runDataProvider */ public function testRunTaskNow($expectedTimetable, $expectedExecutedTasks, $timetableBeforeTaskExecution, $configuredTasks) { $taskLoader = $this->getMock('Piwik\\Scheduler\\TaskLoader'); $taskLoader->expects($this->atLeastOnce())->method('loadTasks')->willReturn($configuredTasks); // stub the piwik option object to control the returned option value self::stubPiwikOption(serialize($timetableBeforeTaskExecution)); $timetable = new Timetable(); $initialTimetable = $timetable->getTimetable(); $scheduler = new Scheduler($taskLoader, new NullLogger()); foreach ($configuredTasks as $task) { /** @var Task $task */ $result = $scheduler->runTaskNow($task->getName()); $this->assertNotEmpty($result); } // assert the timetable is NOT updated $this->assertSame($initialTimetable, $timetable->getTimetable()); self::resetPiwikOption(); }
/** * Return the next scheduled time given the class and method names of a scheduled task. * * @param string $className The name of the class that contains the scheduled task method. * @param string $methodName The name of the scheduled task method. * @param string|null $methodParameter Optional method parameter. * @return mixed int|bool The time in miliseconds when the scheduled task will be executed * next or false if it is not scheduled to run. */ public function getScheduledTimeForMethod($className, $methodName, $methodParameter = null) { return $this->timetable->getScheduledTimeForMethod($className, $methodName, $methodParameter); }
/** * Returns the next scheduled time for the auto updater. * * @return Date|false */ public static function getNextRunTime() { $task = new GeoIPAutoUpdater(); $timetable = new Timetable(); return $timetable->getScheduledTaskTime($task->getName()); }