Skip to content

Commit 540b7e8

Browse files
authored
Get Database Swift API Test building on Xcode13b4 (#8466)
* Test builds for Xcode13b4 * Fix comment mistake
1 parent 9b4c5c0 commit 540b7e8

File tree

1 file changed

+60
-61
lines changed

1 file changed

+60
-61
lines changed

FirebaseDatabase/Tests/Unit/Swift/DatabaseAPITests.swift

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ final class DatabaseAPITests {
6666

6767
// MARK: - DatabaseQuery
6868

69-
var uint: UInt = 0
69+
let uint: UInt = 0
7070
let dataEventType: DataEventType = .value
71-
var child = "child"
72-
var childKey: String? = "key"
73-
var value: Any? = "value"
74-
var priority: Any? = "priority"
71+
let child = "child"
72+
let childKey: String? = "key"
73+
let value: Any? = "value"
74+
let priority: Any? = "priority"
7575

7676
var databaseHandle: DatabaseHandle = uint
7777
var databaseQuery: DatabaseQuery = DatabaseQuery()
@@ -115,9 +115,9 @@ final class DatabaseAPITests {
115115
#if swift(>=5.5)
116116
if #available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) {
117117
// async/await is a Swift 5.5+ feature available on iOS 15+
118-
async {
118+
Task {
119119
do {
120-
let /* dataSnapshot */ _: DataSnapshot = try await databaseQuery.getData()
120+
let /* dataSnapshot */ _: DataSnapshot = try await DatabaseQuery().getData()
121121
} catch {
122122
// ...
123123
}
@@ -141,14 +141,10 @@ final class DatabaseAPITests {
141141
#if swift(>=5.5)
142142
if #available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) {
143143
// async/await is a Swift 5.5+ feature available on iOS 15+
144-
async {
145-
do {
146-
// observeSingleEvent(of eventType:)
147-
let _: (DataSnapshot, String?) = try await databaseQuery
148-
.observeSingleEventAndPreviousSiblingKey(of: dataEventType)
149-
} catch {
150-
// ...
151-
}
144+
Task {
145+
// observeSingleEvent(of eventType:)
146+
let _: (DataSnapshot, String?) = await DatabaseQuery()
147+
.observeSingleEventAndPreviousSiblingKey(of: dataEventType)
152148
}
153149
}
154150
#endif // swift(>=5.5)
@@ -198,7 +194,7 @@ final class DatabaseAPITests {
198194
// MARK: - DatabaseReference
199195

200196
let priorityAny: Any = "priority"
201-
var values = [AnyHashable: Any]()
197+
let values = [AnyHashable: Any]()
202198
var transactionResult = TransactionResult()
203199

204200
// Retreive Child DatabaseReference
@@ -217,10 +213,10 @@ final class DatabaseAPITests {
217213
#if swift(>=5.5)
218214
if #available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) {
219215
// async/await is a Swift 5.5+ feature available on iOS 15+
220-
async {
216+
Task {
221217
do {
222218
// setValue(_ value:)
223-
databaseReference = try await databaseReference.setValue(value)
219+
let /* ref */ _: DatabaseReference = try await DatabaseReference().setValue(value)
224220
} catch {
225221
// ...
226222
}
@@ -239,10 +235,11 @@ final class DatabaseAPITests {
239235
#if swift(>=5.5)
240236
if #available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) {
241237
// async/await is a Swift 5.5+ feature available on iOS 15+
242-
async {
238+
Task {
243239
do {
244240
// setValue(_ value:andPriority priority:)
245-
databaseReference = try await databaseReference.setValue(value, andPriority: priority)
241+
let /* ref */ _: DatabaseReference = try await DatabaseReference()
242+
.setValue(value, andPriority: priority)
246243
} catch {
247244
// ...
248245
}
@@ -262,9 +259,9 @@ final class DatabaseAPITests {
262259
#if swift(>=5.5)
263260
if #available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) {
264261
// async/await is a Swift 5.5+ feature available on iOS 15+
265-
async {
262+
Task {
266263
do {
267-
databaseReference = try await databaseReference.removeValue()
264+
let /* ref */ _: DatabaseReference = try await DatabaseReference().removeValue()
268265
} catch {
269266
// ...
270267
}
@@ -284,10 +281,10 @@ final class DatabaseAPITests {
284281
#if swift(>=5.5)
285282
if #available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) {
286283
// async/await is a Swift 5.5+ feature available on iOS 15+
287-
async {
284+
Task {
288285
do {
289286
// setPriority(_ priority:)
290-
databaseReference = try await databaseReference.setPriority(priority)
287+
let /* ref */ _: DatabaseReference = try await DatabaseReference().setPriority(priority)
291288
} catch {
292289
// ...
293290
}
@@ -307,10 +304,11 @@ final class DatabaseAPITests {
307304
#if swift(>=5.5)
308305
if #available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) {
309306
// async/await is a Swift 5.5+ feature available on iOS 15+
310-
async {
307+
Task {
311308
do {
312309
// updateChildValues(_ values:)
313-
databaseReference = try await databaseReference.updateChildValues(values)
310+
let /* ref */ _: DatabaseReference = try await DatabaseReference()
311+
.updateChildValues(values)
314312
} catch {
315313
// ...
316314
}
@@ -362,14 +360,10 @@ final class DatabaseAPITests {
362360
#if swift(>=5.5)
363361
if #available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) {
364362
// async/await is a Swift 5.5+ feature available on iOS 15+
365-
async {
366-
do {
367-
// observeSingleEvent(of eventType:)
368-
let _: (DataSnapshot, String?) = try await databaseReference
369-
.observeSingleEventAndPreviousSiblingKey(of: dataEventType)
370-
} catch {
371-
// ...
372-
}
363+
Task {
364+
// observeSingleEvent(of eventType:)
365+
let _: (DataSnapshot, String?) = await DatabaseReference()
366+
.observeSingleEventAndPreviousSiblingKey(of: dataEventType)
373367
}
374368
}
375369
#endif // swift(>=5.5)
@@ -400,9 +394,9 @@ final class DatabaseAPITests {
400394
#if swift(>=5.5)
401395
if #available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) {
402396
// async/await is a Swift 5.5+ feature available on iOS 15+
403-
async {
397+
Task {
404398
do {
405-
let /* dataSnapshot */ _: DataSnapshot = try await databaseReference.getData()
399+
let /* dataSnapshot */ _: DataSnapshot = try await DatabaseReference().getData()
406400
} catch {
407401
// ...
408402
}
@@ -444,10 +438,11 @@ final class DatabaseAPITests {
444438
#if swift(>=5.5)
445439
if #available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) {
446440
// async/await is a Swift 5.5+ feature available on iOS 15+
447-
async {
441+
Task {
448442
do {
449443
// onDisconnectSetValue(_ value:)
450-
databaseReference = try await databaseReference.onDisconnectSetValue(value)
444+
let /* ref */ _: DatabaseReference = try await DatabaseReference()
445+
.onDisconnectSetValue(value)
451446
} catch {
452447
// ...
453448
}
@@ -467,10 +462,10 @@ final class DatabaseAPITests {
467462
#if swift(>=5.5)
468463
if #available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) {
469464
// async/await is a Swift 5.5+ feature available on iOS 15+
470-
async {
465+
Task {
471466
do {
472467
// onDisconnectSetValue(_ value:andPriority priority:)
473-
databaseReference = try await databaseReference.onDisconnectSetValue(
468+
let /* ref */ _: DatabaseReference = try await DatabaseReference().onDisconnectSetValue(
474469
value,
475470
andPriority: priority
476471
)
@@ -493,9 +488,10 @@ final class DatabaseAPITests {
493488
#if swift(>=5.5)
494489
if #available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) {
495490
// async/await is a Swift 5.5+ feature available on iOS 15+
496-
async {
491+
Task {
497492
do {
498-
databaseReference = try await databaseReference.onDisconnectRemoveValue()
493+
let /* ref */ _: DatabaseReference = try await DatabaseReference()
494+
.onDisconnectRemoveValue()
499495
} catch {
500496
// ...
501497
}
@@ -515,10 +511,11 @@ final class DatabaseAPITests {
515511
#if swift(>=5.5)
516512
if #available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) {
517513
// async/await is a Swift 5.5+ feature available on iOS 15+
518-
async {
514+
Task {
519515
do {
520516
// onDisconnectUpdateChildValues(_ values:)
521-
databaseReference = try await databaseReference.onDisconnectUpdateChildValues(values)
517+
let /* ref */ _: DatabaseReference = try await DatabaseReference()
518+
.onDisconnectUpdateChildValues(values)
522519
} catch {
523520
// ...
524521
}
@@ -538,9 +535,10 @@ final class DatabaseAPITests {
538535
#if swift(>=5.5)
539536
if #available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) {
540537
// async/await is a Swift 5.5+ feature available on iOS 15+
541-
async {
538+
Task {
542539
do {
543-
databaseReference = try await databaseReference.cancelDisconnectOperations()
540+
let /* ref */ _: DatabaseReference = try await DatabaseReference()
541+
.cancelDisconnectOperations()
544542
} catch {
545543
// ...
546544
}
@@ -569,13 +567,13 @@ final class DatabaseAPITests {
569567
#if swift(>=5.5)
570568
if #available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *) {
571569
// async/await is a Swift 5.5+ feature available on iOS 15+
572-
async {
570+
Task {
573571
do {
574572
// runTransactionBlock(_ block:)
575-
let _: (Bool, DataSnapshot) = try await databaseReference
573+
let _: (Bool, DataSnapshot) = try await DatabaseReference()
576574
.runTransactionBlock { mutableData in
577575
let /* mutableData */ _: MutableData = mutableData
578-
return transactionResult
576+
return TransactionResult()
579577
}
580578
} catch {
581579
// ...
@@ -603,8 +601,8 @@ final class DatabaseAPITests {
603601

604602
// Instance properties
605603
let /* parent */ _: DatabaseReference? = databaseReference.parent
604+
let /* childKey */ _: String? = databaseReference.key
606605
databaseReference = databaseReference.root
607-
childKey = databaseReference.key
608606
url = databaseReference.url
609607
database = databaseReference.database
610608

@@ -638,15 +636,15 @@ final class DatabaseAPITests {
638636
let /* exists */ _: Bool = dataSnapshot.exists()
639637

640638
// Data export
641-
value = dataSnapshot.valueInExportFormat()
639+
let /* value */ _: Any? = dataSnapshot.valueInExportFormat()
642640

643641
// Properties
644-
value = dataSnapshot.value
645-
uint = dataSnapshot.childrenCount
646642
databaseReference = dataSnapshot.ref
647-
child = dataSnapshot.key
643+
let /* value */ _: Any? = dataSnapshot.value
644+
let /* uint */ _: UInt = dataSnapshot.childrenCount
645+
let /* child */ _: String? = dataSnapshot.key
648646
let /* children */ _: NSEnumerator = dataSnapshot.children
649-
priority = dataSnapshot.priority
647+
let /* priority */ _: Any? = dataSnapshot.priority
650648

651649
// MARK: - MutableData
652650

@@ -658,18 +656,19 @@ final class DatabaseAPITests {
658656
mutableData = mutableData.childData(byAppendingPath: path)
659657

660658
// Properties
661-
value = mutableData.value
662-
priority = mutableData.priority
663-
uint = mutableData.childrenCount
659+
let /* value */ _: Any? = mutableData.value
660+
let /* priority */ _: Any? = mutableData.priority
661+
662+
let /* uint */ _: UInt = mutableData.childrenCount
664663
let /* children */ _: NSEnumerator = mutableData.children
665-
childKey = mutableData.key
664+
let /* childKey */ _: String? = mutableData.key
666665

667666
// MARK: - ServerValue
668667

669668
let nsNumber: NSNumber = 0
670669

671-
values = ServerValue.timestamp()
672-
values = ServerValue.increment(nsNumber)
670+
let /* values */ _: [AnyHashable: Any] = ServerValue.timestamp()
671+
let /* values */ _: [AnyHashable: Any] = ServerValue.increment(nsNumber)
673672

674673
// MARK: - TransactionResult
675674

0 commit comments

Comments
 (0)