1010
1111use OCA \Libresign \Service \CaIdentifierService ;
1212use OCP \IAppConfig ;
13- use OCP \IConfig ;
1413use PHPUnit \Framework \Attributes \DataProvider ;
1514use PHPUnit \Framework \MockObject \MockObject ;
1615use PHPUnit \Framework \TestCase ;
2019 */
2120final class CaIdentifierServiceTest extends TestCase {
2221 private CaIdentifierService $ service ;
23- private IAppConfig &MockObject $ appConfig ;
24- private IConfig &MockObject $ config ;
22+ private MockObject $ appConfig ;
2523
2624 protected function setUp (): void {
25+ parent ::setUp ();
2726 $ this ->appConfig = $ this ->createMock (IAppConfig::class);
28- $ this ->config = $ this ->createMock (IConfig::class);
29- $ this ->service = new CaIdentifierService ($ this ->appConfig , $ this ->config );
27+ /** @var IAppConfig $appConfig */
28+ $ appConfig = $ this ->appConfig ;
29+ $ this ->service = new CaIdentifierService ($ appConfig );
3030 }
3131
3232 public function testGenerateCaIdWithOpenSSL (): void {
33- $ this ->config
34- ->expects ($ this ->once ())
35- ->method ('getSystemValueString ' )
36- ->with ('instanceid ' )
37- ->willReturn ('abc1234567 ' );
38-
3933 $ this ->appConfig
4034 ->expects ($ this ->once ())
4135 ->method ('getValueInt ' )
@@ -49,16 +43,10 @@ public function testGenerateCaIdWithOpenSSL(): void {
4943
5044 $ result = $ this ->service ->generateCaId ('openssl ' );
5145
52- $ this ->assertEquals ( ' libresign-ca-id:abc1234567_g:1_e:o ' , $ result );
46+ $ this ->assertMatchesRegularExpression ( ' /^ libresign-ca-id:[a-z0-9]{10}_g:\d+_e:o$/ ' , $ result );
5347 }
5448
5549 public function testGenerateCaIdWithCFSSL (): void {
56- $ this ->config
57- ->expects ($ this ->once ())
58- ->method ('getSystemValueString ' )
59- ->with ('instanceid ' )
60- ->willReturn ('xyz9876543 ' );
61-
6250 $ this ->appConfig
6351 ->expects ($ this ->once ())
6452 ->method ('getValueInt ' )
@@ -72,7 +60,7 @@ public function testGenerateCaIdWithCFSSL(): void {
7260
7361 $ result = $ this ->service ->generateCaId ('cfssl ' );
7462
75- $ this ->assertEquals ( ' libresign-ca-id:xyz9876543_g:3_e:c ' , $ result );
63+ $ this ->assertMatchesRegularExpression ( ' /^ libresign-ca-id:[a-z0-9]{10}_g:\d+_e:c$/ ' , $ result );
7664 }
7765
7866 #[DataProvider('providerIsValidCaId ' )]
0 commit comments