1212use OC \SnowflakeIdGenerator ;
1313use OCP \AppFramework \Utility \ITimeFactory ;
1414use OCP \ICacheFactory ;
15+ use OCP \IConfig ;
1516use PHPUnit \Framework \Attributes \DataProvider ;
1617use PHPUnit \Framework \MockObject \MockObject ;
1718
2021 */
2122class SnowflakeIdGeneratorTest extends TestCase {
2223 private ICacheFactory |MockObject $ cacheFactory ;
24+ private IConfig |MockObject $ config ;
2325
2426 public function setUp (): void {
2527 $ this ->cacheFactory = $ this ->createMock (ICacheFactory::class);
28+ $ this ->config = $ this ->createMock (IConfig::class);
29+ $ this ->config ->method ('getSystemValueInt ' )
30+ ->with ('serverid ' )
31+ ->willReturn (42 );
2632 }
2733
2834 public function testGenerator (): void {
29- $ generator = new SnowflakeIdGenerator (new TimeFactory (), $ this ->cacheFactory );
35+ $ generator = new SnowflakeIdGenerator (new TimeFactory (), $ this ->config , $ this -> cacheFactory );
3036 $ snowflakeId = ($ generator )();
3137 $ this ->assertGreaterThan (0x100000000 , $ snowflakeId );
3238 if (PHP_INT_SIZE === 8 ) {
@@ -42,11 +48,13 @@ public function testGeneratorWithFixedTime(string $date, int $expectedSeconds, i
4248 $ timeFactory = $ this ->createMock (ITimeFactory::class);
4349 $ timeFactory ->method ('now ' )->willReturn ($ dt );
4450
45- $ generator = new SnowflakeIdGenerator ($ timeFactory , $ this ->cacheFactory );
51+ $ generator = new SnowflakeIdGenerator ($ timeFactory , $ this ->config , $ this -> cacheFactory );
4652 $ snowflakeId = new SnowflakeId ($ generator ());
4753
4854 $ this ->assertEquals ($ expectedSeconds , $ snowflakeId ->seconds ());
4955 $ this ->assertEquals ($ expectedMilliseconds , $ snowflakeId ->milliseconds ());
56+ $ this ->assertTrue ($ snowflakeId ->isCli ());
57+ $ this ->assertEquals (42 , $ snowflakeId ->serverId ());
5058 }
5159
5260 public static function provideSnowflakeData (): array {
0 commit comments