Repository: firebase/firebase-ios-sdk (language: cpp)

Issue:
Heartbeat Logging unit test failure in Xcode 15
### Description

The `testRequest_IncludesHeartbeatPayload_WhenHeartbeatsNeedSending` test fails in Xcode 15.

### Reproducing the issue

Run the Auth unit tests on Xcode 15

### Firebase SDK Version

10.11

### Xcode Version

15.0-beta1

### Installation Method

Swift Package Manager

### Firebase Product(s)

Authentication

### Targeted Platforms

iOS

### Relevant Log Output

_No response_

### If using Swift Package Manager, the project's Package.resolved

<!--- Look below for instructions on how to share your Package.resolved. --->

<details>
<summary>Expand <code>Package.resolved</code> snippet</summary>
<br>

```json

Replace this line with the contents of your Package.resolved.

```

</details>


### If using CocoaPods, the project's Podfile.lock

<!--- Look below for instructions on how to share your Podfile.lock. --->

<details>
<summary>Expand <code>Podfile.lock</code> snippet</summary>
<br>

```yml

Replace this line with the contents of your Podfile.lock!

```

</details>



Discussion / hints:
Similar failure in AppCheck unit tests:

testDataRequestSuccessWhenHeartbeatsNeedSending: ((request.allHTTPHeaderFields) equal to (expectedHTTPHeaderFields)) failed: ("{
    "X-Goog-Api-Key" = "api_key";
    "X-Ios-Bundle-Identifier" = "com.apple.dt.xctest.tool";
    "X-firebase-client" = "H4sIAAAAAAAAE6tWKkstKs7Mz1OyMtJRykhNLCpJSk0sKVayiq5WSkksSQWxlIwMjAx1DQ11DQyVdBAcI6VYHaXE9NS8EiUrpZTS3NzKeDAv3lCpVqcaq4wRUD-mqcZKsbWxtQBgc6kdiwAAAA";
    header1 = value1;
}") is not equal to ("{
    "X-Goog-Api-Key" = "api_key";
    "X-Ios-Bundle-Identifier" = "com.apple.dt.xctest.tool";
    "X-firebase-client" = "H4sIAAAAAAAAE6tWykhNLCpJSk0sKVayiq5WSkxPzStRslJKKc3NrYwH8-INlXSUUhJLUkEqlIwMjAx1DQ11DUCicI6RUmytDnbdRlh1GwM1xOoolaUWFWfm5ylZGdUCAC6zVoOLAAAA";
    header1 = value1;
}")

Fix patch:
diff --git a/FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatsPayload.swift b/FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatsPayload.swift
index 8e18bdecfd4..72dbe3b3058 100644
--- a/FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatsPayload.swift
+++ b/FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatsPayload.swift
@@ -91,6 +91,14 @@ extension HeartbeatsPayload: HTTPHeaderRepresentable {
   public func headerValue() -> String {
     let encoder = JSONEncoder()
     encoder.dateEncodingStrategy = .formatted(Self.dateFormatter)
+    #if DEBUG
+      // TODO: Remove the following #available check when FirebaseCore's minimum deployment target
+      // is iOS 11+; all other supported platforms already meet the minimum for `.sortedKeys`.
+      if #available(iOS 11, *) {
+        // Sort keys in debug builds to simplify output comparisons in unit tests.
+        encoder.outputFormatting = .sortedKeys
+      }
+    #endif // DEBUG
 
     guard let data = try? encoder.encode(self) else {
       // If encoding fails, fall back to encoding with an empty payload.


Test patch: