@@ -33,12 +33,13 @@ class UserTests: RPCBaseTests {
3333 let kVerificationID = " 55432 "
3434 let kPhoneNumber = " 555-1234 "
3535
36- static var auth : Auth ?
36+ var auth : Auth ?
3737
38- override class func setUp( ) {
38+ override func setUp( ) {
39+ super. setUp ( )
3940 let options = FirebaseOptions ( googleAppID: " 0:0000000000000:ios:0000000000000000 " ,
4041 gcmSenderID: " 00000000000000000-00000000000-000000000 " )
41- options. apiKey = kFakeAPIKey
42+ options. apiKey = Self . kFakeAPIKey
4243 options. projectID = " myUserProjectID "
4344 FirebaseApp . configure ( name: " test-UserTests " , options: options)
4445 #if (os(macOS) && !FIREBASE_AUTH_TESTING_USE_MACOS_KEYCHAIN) || SWIFT_PACKAGE
@@ -48,13 +49,17 @@ class UserTests: RPCBaseTests {
4849 #endif // (os(macOS) && !FIREBASE_AUTH_TESTING_USE_MACOS_KEYCHAIN) || SWIFT_PACKAGE
4950 auth = Auth (
5051 app: FirebaseApp . app ( name: " test-UserTests " ) !,
51- keychainStorageProvider: keychainStorageProvider
52+ keychainStorageProvider: keychainStorageProvider,
53+ backend: authBackend
5254 )
5355 }
5456
5557 override func tearDown( ) {
5658 // Verifies that no tasks are left suspended on the AuthSerialTaskQueue.
57- try ? UserTests . auth? . signOut ( )
59+ try ? auth? . signOut ( )
60+ auth = nil
61+ FirebaseApp . resetApps ( )
62+ super. tearDown ( )
5863 }
5964
6065 /** @fn testUserPropertiesAndNSSecureCoding
@@ -415,7 +420,7 @@ class UserTests: RPCBaseTests {
415420 // Email should not have changed on the client side.
416421 XCTAssertEqual ( user. email, self . kEmail)
417422 // User is still signed in.
418- XCTAssertEqual ( UserTests . auth? . currentUser, user)
423+ XCTAssertEqual ( self . auth? . currentUser, user)
419424 expectation. fulfill ( )
420425 }
421426 }
@@ -441,7 +446,7 @@ class UserTests: RPCBaseTests {
441446 // Email should not have changed on the client side.
442447 XCTAssertEqual ( user. email, self . kEmail)
443448 // User is no longer signed in..
444- XCTAssertNil ( UserTests . auth? . currentUser)
449+ XCTAssertNil ( self . auth? . currentUser)
445450 expectation. fulfill ( )
446451 }
447452 }
@@ -457,7 +462,7 @@ class UserTests: RPCBaseTests {
457462 func testUpdatePhoneSuccess( ) throws {
458463 setFakeGetAccountProvider ( )
459464 let expectation = self . expectation ( description: #function)
460- let auth = try XCTUnwrap ( UserTests . auth)
465+ let auth = try XCTUnwrap ( self . auth)
461466 signInWithEmailPasswordReturnFakeUser { user in
462467 do {
463468 self . rpcIssuer. respondBlock = {
@@ -491,7 +496,7 @@ class UserTests: RPCBaseTests {
491496 func testUpdatePhoneNumberFailure( ) throws {
492497 setFakeGetAccountProvider ( )
493498 let expectation = self . expectation ( description: #function)
494- let auth = try XCTUnwrap ( UserTests . auth)
499+ let auth = try XCTUnwrap ( self . auth)
495500 signInWithEmailPasswordReturnFakeUser { user in
496501 do {
497502 self . rpcIssuer. respondBlock = {
@@ -523,7 +528,7 @@ class UserTests: RPCBaseTests {
523528 func testUpdatePhoneNumberFailureAutoSignOut( ) throws {
524529 setFakeGetAccountProvider ( )
525530 let expectation = self . expectation ( description: #function)
526- let auth = try XCTUnwrap ( UserTests . auth)
531+ let auth = try XCTUnwrap ( self . auth)
527532 signInWithEmailPasswordReturnFakeUser { user in
528533 do {
529534 self . rpcIssuer. respondBlock = {
@@ -540,7 +545,7 @@ class UserTests: RPCBaseTests {
540545 let error = try ! XCTUnwrap ( rawError)
541546 XCTAssertEqual ( ( error as NSError ) . code, AuthErrorCode . userTokenExpired. rawValue)
542547 // User is no longer signed in.
543- XCTAssertNil ( UserTests . auth? . currentUser)
548+ XCTAssertNil ( self . auth? . currentUser)
544549 expectation. fulfill ( )
545550 }
546551 }
@@ -579,7 +584,7 @@ class UserTests: RPCBaseTests {
579584 // Email should not have changed on the client side.
580585 XCTAssertEqual ( user. email, self . kEmail)
581586 // User is still signed in.
582- XCTAssertEqual ( UserTests . auth? . currentUser, user)
587+ XCTAssertEqual ( self . auth? . currentUser, user)
583588 expectation. fulfill ( )
584589 }
585590 }
@@ -605,7 +610,7 @@ class UserTests: RPCBaseTests {
605610 // Email should not have changed on the client side.
606611 XCTAssertEqual ( user. email, self . kEmail)
607612 // User is still signed in.
608- XCTAssertEqual ( UserTests . auth? . currentUser, user)
613+ XCTAssertEqual ( self . auth? . currentUser, user)
609614 expectation. fulfill ( )
610615 }
611616 }
@@ -632,7 +637,7 @@ class UserTests: RPCBaseTests {
632637 // Email should not have changed on the client side.
633638 XCTAssertEqual ( user. email, self . kEmail)
634639 // User is signed out.
635- XCTAssertNil ( UserTests . auth? . currentUser)
640+ XCTAssertNil ( self . auth? . currentUser)
636641 expectation. fulfill ( )
637642 }
638643 }
@@ -688,7 +693,7 @@ class UserTests: RPCBaseTests {
688693 XCTAssertEqual ( user. email, self . kEmail)
689694 XCTAssertEqual ( user. displayName, self . kDisplayName)
690695 // User is still signed in.
691- XCTAssertEqual ( UserTests . auth? . currentUser, user)
696+ XCTAssertEqual ( self . auth? . currentUser, user)
692697 expectation. fulfill ( )
693698 }
694699 }
@@ -716,7 +721,7 @@ class UserTests: RPCBaseTests {
716721 // Email should not have changed on the client side.
717722 XCTAssertEqual ( user. email, self . kEmail)
718723 // User is signed out.
719- XCTAssertNil ( UserTests . auth? . currentUser)
724+ XCTAssertNil ( self . auth? . currentUser)
720725 expectation. fulfill ( )
721726 }
722727 }
@@ -821,7 +826,7 @@ class UserTests: RPCBaseTests {
821826 let error = try ! XCTUnwrap ( rawError)
822827 XCTAssertEqual ( ( error as NSError ) . code, AuthErrorCode . quotaExceeded. rawValue)
823828 // User is still signed in.
824- XCTAssertEqual ( UserTests . auth? . currentUser, user)
829+ XCTAssertEqual ( self . auth? . currentUser, user)
825830 expectation. fulfill ( )
826831 }
827832 }
@@ -848,7 +853,7 @@ class UserTests: RPCBaseTests {
848853 let error = try ! XCTUnwrap ( rawError)
849854 XCTAssertEqual ( ( error as NSError ) . code, AuthErrorCode . userTokenExpired. rawValue)
850855 // User is no longer signed in.
851- XCTAssertNil ( UserTests . auth? . currentUser)
856+ XCTAssertNil ( self . auth? . currentUser)
852857 expectation. fulfill ( )
853858 }
854859 }
@@ -878,7 +883,7 @@ class UserTests: RPCBaseTests {
878883 XCTAssertEqual ( result. user. email, user. email)
879884 XCTAssertEqual ( result. additionalUserInfo? . isNewUser, false )
880885 // User is still signed in.
881- XCTAssertEqual ( UserTests . auth? . currentUser, user)
886+ XCTAssertEqual ( self . auth? . currentUser, user)
882887 expectation. fulfill ( )
883888 }
884889 }
@@ -914,7 +919,7 @@ class UserTests: RPCBaseTests {
914919 }
915920 XCTAssertNil ( error)
916921 // Verify that the current user is unchanged.
917- XCTAssertEqual ( UserTests . auth? . currentUser, user)
922+ XCTAssertEqual ( self . auth? . currentUser, user)
918923 // Verify that the current user and reauthenticated user are not same pointers.
919924 XCTAssertNotEqual ( user, reauthenticatedAuthResult? . user)
920925 // Verify that anyway the current user and reauthenticated user have same IDs.
@@ -933,7 +938,7 @@ class UserTests: RPCBaseTests {
933938 }
934939 }
935940 waitForExpectations ( timeout: 5 )
936- try assertUserGoogle ( UserTests . auth? . currentUser)
941+ try assertUserGoogle ( auth? . currentUser)
937942 }
938943
939944 /** @fn testReauthenticateFailure
@@ -958,7 +963,7 @@ class UserTests: RPCBaseTests {
958963 // Email should not have changed on the client side.
959964 XCTAssertEqual ( user. email, self . kEmail)
960965 // User is still signed in.
961- XCTAssertEqual ( UserTests . auth? . currentUser, user)
966+ XCTAssertEqual ( self . auth? . currentUser, user)
962967 expectation. fulfill ( )
963968 }
964969 }
@@ -987,7 +992,7 @@ class UserTests: RPCBaseTests {
987992 // Email should not have changed on the client side.
988993 XCTAssertEqual ( user. email, self . kEmail)
989994 // User is still signed in.
990- XCTAssertEqual ( UserTests . auth? . currentUser, user)
995+ XCTAssertEqual ( self . auth? . currentUser, user)
991996 expectation. fulfill ( )
992997 }
993998 }
@@ -1001,7 +1006,7 @@ class UserTests: RPCBaseTests {
10011006 func testLinkAndRetrieveDataSuccess( ) throws {
10021007 setFakeGetAccountProvider ( )
10031008 let expectation = self . expectation ( description: #function)
1004- let auth = try XCTUnwrap ( UserTests . auth)
1009+ let auth = try XCTUnwrap ( self . auth)
10051010 signInWithFacebookCredential { user in
10061011 XCTAssertNotNil ( user)
10071012 do {
@@ -1069,7 +1074,7 @@ class UserTests: RPCBaseTests {
10691074 // Email should not have changed on the client side.
10701075 XCTAssertEqual ( user. email, self . kFacebookEmail)
10711076 // User is still signed in.
1072- XCTAssertEqual ( UserTests . auth? . currentUser, user)
1077+ XCTAssertEqual ( self . auth? . currentUser, user)
10731078 expectation. fulfill ( )
10741079 }
10751080 }
@@ -1100,7 +1105,7 @@ class UserTests: RPCBaseTests {
11001105 XCTFail ( " Expected to throw providerAlreadyLinked error. " )
11011106 }
11021107 // User is still signed in.
1103- XCTAssertEqual ( UserTests . auth? . currentUser, user)
1108+ XCTAssertEqual ( self . auth? . currentUser, user)
11041109 expectation. fulfill ( )
11051110 }
11061111 }
@@ -1130,7 +1135,7 @@ class UserTests: RPCBaseTests {
11301135 let error = try ! XCTUnwrap ( rawError)
11311136 XCTAssertEqual ( ( error as NSError ) . code, AuthErrorCode . userDisabled. rawValue)
11321137 // User is signed out.
1133- XCTAssertNil ( UserTests . auth? . currentUser)
1138+ XCTAssertNil ( self . auth? . currentUser)
11341139 expectation. fulfill ( )
11351140 }
11361141 }
@@ -1145,7 +1150,7 @@ class UserTests: RPCBaseTests {
11451150 func testLinkEmailAndRetrieveDataSuccess( ) throws {
11461151 setFakeGetAccountProvider ( )
11471152 let expectation = self . expectation ( description: #function)
1148- let auth = try XCTUnwrap ( UserTests . auth)
1153+ let auth = try XCTUnwrap ( self . auth)
11491154 signInWithFacebookCredential { user in
11501155 XCTAssertNotNil ( user)
11511156 do {
@@ -1213,7 +1218,7 @@ class UserTests: RPCBaseTests {
12131218 XCTFail ( " Expected to throw providerAlreadyLinked error. " )
12141219 }
12151220 // User is still signed in.
1216- XCTAssertEqual ( UserTests . auth? . currentUser, user)
1221+ XCTAssertEqual ( self . auth? . currentUser, user)
12171222 expectation. fulfill ( )
12181223 }
12191224 }
@@ -1247,7 +1252,7 @@ class UserTests: RPCBaseTests {
12471252 let error = try ! XCTUnwrap ( rawError)
12481253 XCTAssertEqual ( ( error as NSError ) . code, AuthErrorCode . tooManyRequests. rawValue)
12491254 // User is still signed in.
1250- XCTAssertEqual ( UserTests . auth? . currentUser, user)
1255+ XCTAssertEqual ( self . auth? . currentUser, user)
12511256 expectation. fulfill ( )
12521257 }
12531258 }
@@ -1277,7 +1282,7 @@ class UserTests: RPCBaseTests {
12771282 let error = try ! XCTUnwrap ( rawError)
12781283 XCTAssertEqual ( ( error as NSError ) . code, AuthErrorCode . userTokenExpired. rawValue)
12791284 // User is signed out.
1280- XCTAssertNil ( UserTests . auth? . currentUser)
1285+ XCTAssertNil ( self . auth? . currentUser)
12811286 expectation. fulfill ( )
12821287 }
12831288 }
@@ -1307,7 +1312,7 @@ class UserTests: RPCBaseTests {
13071312 func testLinkProviderFailure( ) throws {
13081313 setFakeGetAccountProvider ( )
13091314 let expectation = self . expectation ( description: #function)
1310- let auth = try XCTUnwrap ( UserTests . auth)
1315+ let auth = try XCTUnwrap ( self . auth)
13111316 signInWithFacebookCredential { user in
13121317 XCTAssertNotNil ( user)
13131318 do {
@@ -1322,7 +1327,7 @@ class UserTests: RPCBaseTests {
13221327 let error = try ! XCTUnwrap ( rawError)
13231328 XCTAssertEqual ( ( error as NSError ) . code, AuthErrorCode . userTokenExpired. rawValue)
13241329 // User is signed out.
1325- XCTAssertNil ( UserTests . auth? . currentUser)
1330+ XCTAssertNil ( self . auth? . currentUser)
13261331 expectation. fulfill ( )
13271332 }
13281333 }
@@ -1336,7 +1341,7 @@ class UserTests: RPCBaseTests {
13361341 func testReauthenticateWithProviderFailure( ) throws {
13371342 setFakeGetAccountProvider ( )
13381343 let expectation = self . expectation ( description: #function)
1339- let auth = try XCTUnwrap ( UserTests . auth)
1344+ let auth = try XCTUnwrap ( self . auth)
13401345 signInWithFacebookCredential { user in
13411346 XCTAssertNotNil ( user)
13421347 do {
@@ -1351,7 +1356,7 @@ class UserTests: RPCBaseTests {
13511356 let error = try ! XCTUnwrap ( rawError)
13521357 XCTAssertEqual ( ( error as NSError ) . code, AuthErrorCode . userTokenExpired. rawValue)
13531358 // User is still signed in.
1354- XCTAssertEqual ( UserTests . auth? . currentUser, user)
1359+ XCTAssertEqual ( self . auth? . currentUser, user)
13551360 expectation. fulfill ( )
13561361 }
13571362 }
@@ -1365,7 +1370,7 @@ class UserTests: RPCBaseTests {
13651370 func testLinkPhoneAuthCredentialSuccess( ) throws {
13661371 setFakeGetAccountProvider ( )
13671372 let expectation = self . expectation ( description: #function)
1368- let auth = try XCTUnwrap ( UserTests . auth)
1373+ let auth = try XCTUnwrap ( self . auth)
13691374 signInWithEmailPasswordReturnFakeUser { user in
13701375 XCTAssertNotNil ( user)
13711376 self . expectVerifyPhoneNumberRequest ( isLink: true )
@@ -1410,7 +1415,7 @@ class UserTests: RPCBaseTests {
14101415 func testUnlinkPhoneAuthCredentialSuccess( ) throws {
14111416 setFakeGetAccountProvider ( )
14121417 let expectation = self . expectation ( description: #function)
1413- let auth = try XCTUnwrap ( UserTests . auth)
1418+ let auth = try XCTUnwrap ( self . auth)
14141419 signInWithEmailPasswordReturnFakeUser { user in
14151420 XCTAssertNotNil ( user)
14161421 self . expectVerifyPhoneNumberRequest ( isLink: true )
@@ -1506,7 +1511,7 @@ class UserTests: RPCBaseTests {
15061511 func testlinkPhoneCredentialAlreadyExistsError( ) throws {
15071512 setFakeGetAccountProvider ( )
15081513 let expectation = self . expectation ( description: #function)
1509- let auth = try XCTUnwrap ( UserTests . auth)
1514+ let auth = try XCTUnwrap ( self . auth)
15101515 signInWithEmailPasswordReturnFakeUser { user in
15111516 XCTAssertNotNil ( user)
15121517 self . expectVerifyPhoneNumberRequest ( isLink: true )
@@ -1668,12 +1673,12 @@ class UserTests: RPCBaseTests {
16681673 }
16691674 // 1. After setting up fakes, sign out and sign in.
16701675 do {
1671- try UserTests . auth? . signOut ( )
1676+ try auth? . signOut ( )
16721677 } catch {
16731678 XCTFail ( " Sign out failed: \( error) " )
16741679 return
16751680 }
1676- UserTests . auth? . signIn ( withEmail: kEmail, password: kFakePassword) { authResult, error in
1681+ auth? . signIn ( withEmail: kEmail, password: kFakePassword) { authResult, error in
16771682 // 4. After the response triggers the callback, verify the returned result.
16781683 XCTAssertTrue ( Thread . isMainThread)
16791684 guard let user = authResult? . user else {
@@ -1716,10 +1721,10 @@ class UserTests: RPCBaseTests {
17161721 }
17171722
17181723 do {
1719- try UserTests . auth? . signOut ( )
1724+ try auth? . signOut ( )
17201725 let googleCredential = GoogleAuthProvider . credential ( withIDToken: kGoogleIDToken,
17211726 accessToken: kGoogleAccessToken)
1722- UserTests . auth? . signIn ( with: googleCredential) { authResult, error in
1727+ auth? . signIn ( with: googleCredential) { authResult, error in
17231728 // 4. After the response triggers the callback, verify the returned result.
17241729 XCTAssertTrue ( Thread . isMainThread)
17251730 guard let user = authResult? . user else {
@@ -1783,10 +1788,10 @@ class UserTests: RPCBaseTests {
17831788 }
17841789
17851790 do {
1786- try UserTests . auth? . signOut ( )
1791+ try auth? . signOut ( )
17871792 let facebookCredential = FacebookAuthProvider
17881793 . credential ( withAccessToken: kFacebookAccessToken)
1789- UserTests . auth? . signIn ( with: facebookCredential) { authResult, error in
1794+ auth? . signIn ( with: facebookCredential) { authResult, error in
17901795 // 4. After the response triggers the callback, verify the returned result.
17911796 XCTAssertTrue ( Thread . isMainThread)
17921797 guard let user = authResult? . user else {
@@ -1838,8 +1843,8 @@ class UserTests: RPCBaseTests {
18381843 }
18391844
18401845 do {
1841- try UserTests . auth? . signOut ( )
1842- UserTests . auth? . signIn (
1846+ try auth? . signOut ( )
1847+ auth? . signIn (
18431848 withEmail: kEmail,
18441849 link: " https://www.google.com?oobCode=aCode&mode=signIn "
18451850 ) { authResult, error in
0 commit comments