add unit test for qualifies to run

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2018-01-08 13:08:18 +01:00
parent e4310648df
commit b17c5fec40
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
2 changed files with 21 additions and 5 deletions

View File

@ -118,7 +118,7 @@ class Sync extends TimedJob {
/**
* @param array $argument
*/
protected function run($argument) {
public function run($argument) {
$this->setArgument($argument);
$isBackgroundJobModeAjax = $this->config
@ -252,7 +252,7 @@ class Sync extends TimedJob {
* @param $cycleData
* @return bool
*/
protected function qualifiesToRun($cycleData) {
public function qualifiesToRun($cycleData) {
$lastChange = $this->config->getAppValue('user_ldap', $cycleData['prefix'] . '_lastChange', 0);
if((time() - $lastChange) > 60 * 30) {
return true;

View File

@ -197,11 +197,15 @@ class SyncTest extends TestCase {
}
public function cycleDataProvider() {
$cycle1 = ['prefix' => 's01', 'offset' => 1000];
$lastCycle = ['prefix' => 's01', 'offset' => 1000];
$lastCycle2 = ['prefix' => '', 'offset' => 1000];
return [
[ null, ['s01'], ['prefix' => 's01', 'offset' => 0] ],
[ $cycle1, ['s01', 's02'], ['prefix' => 's02', 'offset' => 0] ],
[ $cycle1, [], null ],
[ null, [''], ['prefix' => '', 'offset' => 0] ],
[ $lastCycle, ['s01', 's02'], ['prefix' => 's02', 'offset' => 0] ],
[ $lastCycle, [''], ['prefix' => '', 'offset' => 0] ],
[ $lastCycle2, ['', 's01'], ['prefix' => 's01', 'offset' => 0] ],
[ $lastCycle, [], null ],
];
}
@ -237,4 +241,16 @@ class SyncTest extends TestCase {
}
}
public function testQualifiesToRun() {
$cycleData = ['prefix' => 's01'];
$this->config->expects($this->exactly(2))
->method('getAppValue')
->willReturnOnConsecutiveCalls(time() - 60*40, time() - 60*20);
$this->sync->setArgument($this->arguments);
$this->assertTrue($this->sync->qualifiesToRun($cycleData));
$this->assertFalse($this->sync->qualifiesToRun($cycleData));
}
}