Skip to content

Commit 405e4fe

Browse files
committed
Added mock target for testing
1 parent 4cae06e commit 405e4fe

18 files changed

Lines changed: 279 additions & 6 deletions

Package.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,24 @@ let package = Package(
1616
dependencies: [
1717
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
1818
.package(url: "https://github.com/itsniper/Willow", branch: "main"),
19+
.package(url: "https://github.com/NordicSemiconductor/IOS-CoreBluetooth-Mock.git", .upToNextMinor(from: "1.0.1")),
1920
],
2021
targets: [
2122
.target(
2223
name: "ReliaBLE",
2324
dependencies: ["Willow"]
2425
),
26+
.target(
27+
name: "ReliaBLEMock",
28+
dependencies: [
29+
"Willow",
30+
.product(name: "CoreBluetoothMock", package: "IOS-CoreBluetooth-Mock")
31+
],
32+
exclude: ["ReliaBLE/CBCentralManagerFactory.swift", "ReliaBLE/Documentation.docc"]
33+
),
2534
.testTarget(
2635
name: "ReliaBLETests",
27-
dependencies: ["ReliaBLE"]
36+
dependencies: ["ReliaBLEMock"]
2837
),
2938
]
3039
)

ReliaBLE.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate {
6666
}
6767

6868
log.info("Initializing CBCentralManager")
69-
centralManager = CBCentralManager(delegate: self, queue: queue, options: nil)
69+
70+
// Use CBCentralManagerFactory for consistency between normal and test targets
71+
centralManager = CBCentralManagerFactory.instance(delegate: self, queue: queue, options: nil, forceMock: true)
7072
}
7173

7274
// MARK: - State
@@ -243,6 +245,8 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate {
243245
}
244246
}
245247

248+
// MARK: - Public Types
249+
246250
/// A typealias for the authorization status of the Core Bluetooth manager.
247251
///
248252
/// This typealias maps `CBManagerAuthorization` to `AuthorizationStatus`, providing a more readable and convenient
@@ -307,7 +311,7 @@ public enum BluetoothState: Sendable {
307311
}
308312
}
309313

310-
// MARK - Errors
314+
// MARK: Errors
311315

312316
/// A Swift error enumeration representing authorization-related errors in Bluetooth operations.
313317
///
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// CBCentralManagerFactory.swift
3+
// ReliaBLE
4+
//
5+
// Created by Justin Bergen on 6/30/25.
6+
//
7+
// Copyright (c) 2025 Five3 Apps, LLC <justin@five3apps.com>
8+
//
9+
// Permission is hereby granted, free of charge, to any person obtaining a copy
10+
// of this software and associated documentation files (the "Software"), to deal
11+
// in the Software without restriction, including without limitation the rights
12+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the Software is
14+
// furnished to do so, subject to the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be included in all
17+
// copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
// SOFTWARE.
26+
27+
28+
import Foundation
29+
import CoreBluetooth
30+
31+
// This is used to match CoreBluetoothMocks factory.
32+
// This file is ignored by the Package.swift when SwiftBluetoothMock is used.
33+
enum CBCentralManagerFactory {
34+
static func instance(delegate: CBCentralManagerDelegate? = nil, queue: DispatchQueue? = nil, options: [String: Any]? = nil, forceMock: Bool) -> CBCentralManager {
35+
return CBCentralManager(delegate: delegate, queue: queue, options: options)
36+
}
37+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)