Skip to content

Commit ab5216a

Browse files
[PM-27216] Use Sourcery in BitwardenKit (#2136)
1 parent e8d7c67 commit ab5216a

File tree

6 files changed

+39
-16
lines changed

6 files changed

+39
-16
lines changed

BitwardenKit/Core/Platform/Services/Mocks/MockActiveAccountStateProvider.swift

Lines changed: 0 additions & 13 deletions
This file was deleted.

BitwardenKit/Core/Platform/Utilities/ErrorReportBuilderTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ErrorReportBuilderTests: BitwardenTestCase {
4848
case ciphers
4949
}
5050

51-
activeAccountStateProvider.activeAccountId = "1"
51+
activeAccountStateProvider.getActiveAccountIdReturnValue = "1"
5252

5353
let errorReport = await subject.buildShareErrorLog(
5454
for: DecodingError.keyNotFound(
@@ -94,6 +94,7 @@ class ErrorReportBuilderTests: BitwardenTestCase {
9494
/// `buildShareErrorLog(for:callStack:)` builds an error report to share and handles there being
9595
/// no active account.
9696
func test_buildShareErrorLog_noActiveUser() async {
97+
activeAccountStateProvider.getActiveAccountIdClosure = { throw BitwardenTestError.example }
9798
let errorReport = await subject.buildShareErrorLog(
9899
for: BitwardenTestError.example,
99100
callStack: exampleCallStack,
@@ -128,7 +129,7 @@ class ErrorReportBuilderTests: BitwardenTestCase {
128129

129130
/// `buildShareErrorLog(for:callStack:)` builds an error report to share for a `StateServiceError`.
130131
func test_buildShareErrorLog_stateServiceError() async {
131-
activeAccountStateProvider.activeAccountId = "1"
132+
activeAccountStateProvider.getActiveAccountIdReturnValue = "1"
132133
let errorReport = await subject.buildShareErrorLog(
133134
for: BitwardenTestError.example,
134135
callStack: exampleCallStack,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignore SwiftGen generated files
2+
*.swift

BitwardenKit/Sourcery/sourcery.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
sources:
2+
- ..
3+
4+
templates:
5+
- ../../Sourcery/Templates/AutoMockable.stencil
6+
7+
output:
8+
Generated
9+
10+
exclude:
11+
- Generated
12+
- Tests
13+
- TestHelpers
14+
- Fixtures
15+
16+
args:
17+
autoMockableImports: ["Combine"]
18+
autoMockableTestableImports: ["BitwardenKit"]

BitwardenShared/Core/Platform/Models/Enum/FeatureFlag.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension FeatureFlag: @retroactive CaseIterable {
1919

2020
/// Flag to enable/disable forced KDF updates.
2121
static let forceUpdateKdfSettings = FeatureFlag(rawValue: "pm-18021-force-update-kdf-settings")
22-
22+
2323
/// Flag to enable/disable not logging out when a user's KDF settings are changed.
2424
static let noLogoutOnKdfChange = FeatureFlag(rawValue: "pm-23995-no-logout-on-kdf-change")
2525

project-bwk.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,28 @@ targets:
132132
- "**/*Tests.*"
133133
- "**/TestHelpers/*"
134134
- "**/__Snapshots__/*"
135+
- "**/Sourcery/Generated/*"
136+
- "**/sourcery.yml"
135137
- path: BitwardenKit
136138
includes:
137139
- "**/__Snapshots__/*"
138140
- "**/GoogleService-Info.*.plist"
141+
- "**/sourcery.yml"
139142
buildPhase: none
140143
dependencies:
141144
- package: SwiftUIIntrospect
142145
- target: BitwardenResources
143146
- target: Networking
147+
preBuildScripts:
148+
- name: Sourcery
149+
script: |
150+
if [[ ! "$PATH" =~ "/opt/homebrew/bin" ]]; then
151+
PATH="/opt/homebrew/bin:$PATH"
152+
fi
153+
mint run sourcery --config BitwardenKit/Sourcery/sourcery.yml
154+
basedOnDependencyAnalysis: false
155+
outputFiles:
156+
- $(SRCROOT)/BitwardenKit/Sourcery/Generated/AutoMockable.generated.swift
144157
BitwardenKitMocks:
145158
type: framework
146159
platform: iOS
@@ -153,6 +166,8 @@ targets:
153166
includes:
154167
- "**/Fixtures/*"
155168
- "**/Mocks/*"
169+
- path: BitwardenKit/Sourcery/Generated/AutoMockable.generated.swift
170+
optional: true
156171
dependencies:
157172
- target: BitwardenKit
158173
- target: TestHelpers

0 commit comments

Comments
 (0)