1313use OC \Snowflake \Decoder ;
1414use OC \Snowflake \Generator ;
1515use OCP \AppFramework \Utility \ITimeFactory ;
16+ use OCP \IConfig ;
1617use OCP \Snowflake \IGenerator ;
1718use PHPUnit \Framework \Attributes \DataProvider ;
1819use Test \TestCase ;
2223 */
2324class GeneratorTest extends TestCase {
2425 private Decoder $ decoder ;
26+ private IConfig |MockObject $ config ;
2527
2628 public function setUp ():void {
2729 $ this ->decoder = new Decoder ();
30+ $ this ->config = $ this ->createMock (IConfig::class);
31+ $ this ->config ->method ('getSystemValueInt ' )
32+ ->with ('serverid ' )
33+ ->willReturn (42 );
2834 }
2935 public function testGenerator (): void {
30- $ generator = new Generator (new TimeFactory ());
36+ $ generator = new Generator (new TimeFactory (), $ this -> config );
3137 $ snowflakeId = $ generator ->nextId ();
3238 $ data = $ this ->decoder ->decode ($ generator ->nextId ());
3339
@@ -45,6 +51,9 @@ public function testGenerator(): void {
4551
4652 // Check CLI
4753 $ this ->assertTrue ($ data ['isCli ' ]);
54+
55+ // Check serverId
56+ $ this ->assertEquals (42 , $ data ['serverId ' ]);
4857 }
4958
5059 #[DataProvider('provideSnowflakeData ' )]
@@ -53,11 +62,12 @@ public function testGeneratorWithFixedTime(string $date, int $expectedSeconds, i
5362 $ timeFactory = $ this ->createMock (ITimeFactory::class);
5463 $ timeFactory ->method ('now ' )->willReturn ($ dt );
5564
56- $ generator = new Generator ($ timeFactory );
65+ $ generator = new Generator ($ timeFactory, $ this -> config );
5766 $ data = $ this ->decoder ->decode ($ generator ->nextId ());
5867
5968 $ this ->assertEquals ($ expectedSeconds , ($ data ['createdAt ' ]->format ('U ' ) - IGenerator::TS_OFFSET ));
6069 $ this ->assertEquals ($ expectedMilliseconds , (int )$ data ['createdAt ' ]->format ('v ' ));
70+ $ this ->assertEquals (42 , $ data ['serverId ' ]);
6171 }
6272
6373 public static function provideSnowflakeData (): array {
0 commit comments