@@ -29,13 +29,13 @@ class TotpFactoryTest extends TestCase
2929 private const int DIGITS = 8 ;
3030 private const string ALGORITHM = TotpConfiguration::ALGORITHM_SHA256 ;
3131
32- private function createUserMock (bool $ hasTotpConfiguration = true , string |null $ secret = self ::SECRET ): MockObject &TwoFactorInterface
32+ private function createUserMock (bool $ hasTotpConfiguration = true , string |null $ secret = self ::SECRET , string | null $ username = self :: USER_NAME ): MockObject &TwoFactorInterface
3333 {
3434 $ user = $ this ->createMock (TwoFactorInterface::class);
3535 $ user
3636 ->expects ($ this ->any ())
3737 ->method ('getTotpAuthenticationUsername ' )
38- ->willReturn (self :: USER_NAME );
38+ ->willReturn ($ username );
3939
4040 $ config = $ hasTotpConfiguration ? new TotpConfiguration ($ secret , self ::ALGORITHM , self ::PERIOD , self ::DIGITS ) : null ;
4141 $ user
@@ -86,9 +86,9 @@ public function createTotpForUser_factoryCalled_returnTotpObject(): void
8686 */
8787 #[Test]
8888 #[DataProvider('provideHostnameAndIssuer ' )]
89- public function getProvisioningUri_hostnameAndIssuerGiven_returnProvisioningUri (string |null $ hostname , string |null $ issuer , array $ customParameters , string $ expectedUrl ): void
89+ public function getProvisioningUri_hostnameAndIssuerGiven_returnProvisioningUri (string |null $ username , string | null $ hostname , string |null $ issuer , array $ customParameters , string $ expectedUrl ): void
9090 {
91- $ user = $ this ->createUserMock ();
91+ $ user = $ this ->createUserMock (username: $ username );
9292 $ totp = (new TotpFactory ($ hostname , $ issuer , $ customParameters ))->createTotpForUser ($ user );
9393
9494 $ returnValue = $ totp ->getProvisioningUri ();
@@ -101,12 +101,14 @@ public function getProvisioningUri_hostnameAndIssuerGiven_returnProvisioningUri(
101101 public static function provideHostnameAndIssuer (): array
102102 {
103103 return [
104- [null , null , [], 'otpauth://totp/User%20Name?algorithm=sha256&digits=8&period=20&secret=SECRET ' ],
105- [self ::SERVER , null , [], 'otpauth://totp/User%20Name%40Server%20Name?algorithm=sha256&digits=8&period=20&secret=SECRET ' ],
106- [null , self ::ISSUER , [], 'otpauth://totp/Issuer%20Name%3AUser%20Name?algorithm=sha256&digits=8&issuer=Issuer%20Name&period=20&secret=SECRET ' ],
107- [null , null , self ::CUSTOM_PARAMETERS , 'otpauth://totp/User%20Name?algorithm=sha256&digits=8&image=logo.png&period=20&secret=SECRET ' ],
108- [self ::SERVER , self ::ISSUER , [], 'otpauth://totp/Issuer%20Name%3AUser%20Name%40Server%20Name?algorithm=sha256&digits=8&issuer=Issuer%20Name&period=20&secret=SECRET ' ],
109- [self ::SERVER , self ::ISSUER , self ::CUSTOM_PARAMETERS , 'otpauth://totp/Issuer%20Name%3AUser%20Name%40Server%20Name?algorithm=sha256&digits=8&image=logo.png&issuer=Issuer%20Name&period=20&secret=SECRET ' ],
104+ [null , null , self ::ISSUER , [], 'otpauth://totp/Issuer%20Name?algorithm=sha256&digits=8&period=20&secret=SECRET ' ],
105+ [null , self ::SERVER , self ::ISSUER , [], 'otpauth://totp/Issuer%20Name%3AServer%20Name?algorithm=sha256&digits=8&issuer=Issuer%20Name&period=20&secret=SECRET ' ],
106+ [self ::USER_NAME , null , null , [], 'otpauth://totp/User%20Name?algorithm=sha256&digits=8&period=20&secret=SECRET ' ],
107+ [self ::USER_NAME , self ::SERVER , null , [], 'otpauth://totp/User%20Name%40Server%20Name?algorithm=sha256&digits=8&period=20&secret=SECRET ' ],
108+ [self ::USER_NAME , null , self ::ISSUER , [], 'otpauth://totp/Issuer%20Name%3AUser%20Name?algorithm=sha256&digits=8&issuer=Issuer%20Name&period=20&secret=SECRET ' ],
109+ [self ::USER_NAME , null , null , self ::CUSTOM_PARAMETERS , 'otpauth://totp/User%20Name?algorithm=sha256&digits=8&image=logo.png&period=20&secret=SECRET ' ],
110+ [self ::USER_NAME , self ::SERVER , self ::ISSUER , [], 'otpauth://totp/Issuer%20Name%3AUser%20Name%40Server%20Name?algorithm=sha256&digits=8&issuer=Issuer%20Name&period=20&secret=SECRET ' ],
111+ [self ::USER_NAME , self ::SERVER , self ::ISSUER , self ::CUSTOM_PARAMETERS , 'otpauth://totp/Issuer%20Name%3AUser%20Name%40Server%20Name?algorithm=sha256&digits=8&image=logo.png&issuer=Issuer%20Name&period=20&secret=SECRET ' ],
110112 ];
111113 }
112114}
0 commit comments