add unit test for determining next cycle

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2018-01-08 12:57:14 +01:00
parent a565bf0b9f
commit e4310648df
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
1 changed files with 41 additions and 0 deletions

View File

@ -196,4 +196,45 @@ class SyncTest extends TestCase {
$this->assertSame($expected, $hasMoreResults); $this->assertSame($expected, $hasMoreResults);
} }
public function cycleDataProvider() {
$cycle1 = ['prefix' => 's01', 'offset' => 1000];
return [
[ null, ['s01'], ['prefix' => 's01', 'offset' => 0] ],
[ $cycle1, ['s01', 's02'], ['prefix' => 's02', 'offset' => 0] ],
[ $cycle1, [], null ],
];
}
/**
* @dataProvider cycleDataProvider
*/
public function testDetermineNextCycle($cycleData, $prefixes, $expectedCycle) {
$this->helper->expects($this->any())
->method('getServerConfigurationPrefixes')
->with(true)
->willReturn($prefixes);
if(is_array($expectedCycle)) {
$this->config->expects($this->exactly(2))
->method('setAppValue')
->withConsecutive(
['user_ldap', 'background_sync_prefix', $expectedCycle['prefix']],
['user_ldap', 'background_sync_offset', $expectedCycle['offset']]
);
} else {
$this->config->expects($this->never())
->method('setAppValue');
}
$this->sync->setArgument($this->arguments);
$nextCycle = $this->sync->determineNextCycle($cycleData);
if($expectedCycle === null) {
$this->assertNull($nextCycle);
} else {
$this->assertSame($expectedCycle['prefix'], $nextCycle['prefix']);
$this->assertSame($expectedCycle['offset'], $nextCycle['offset']);
}
}
} }