Auto-Mocking with Sourcery (#597)

* work in progress, was able to generate a mock for the RoomProxyProtocol, I'll try if I can swap the mock we have with this one

* removing swiftformat from generated

* added the disable of swiftlint directly into the .stencil

* testing if danger still complains

* improved the stencil

* session verification controller proxy using auto mockable

* BugReport mocks and tests added

* changelog

* fixing a typo

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>

* fix typo in the test

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>

* removing the Protocol word from the type if present

* using extension in place of a subclass

* removed unused imports

* improved the yielding code

* moved Sourcery files

* stencil master

---------

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
This commit is contained in:
Mauro
2023-03-08 17:04:31 +01:00
committed by GitHub
parent 7d35876753
commit c67c4e362e
20 changed files with 554 additions and 148 deletions
@@ -0,0 +1,143 @@
// Generated using Sourcery 2.0.1 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
// swiftlint:disable all
import Combine
import MatrixRustSDK
class BugReportServiceMock: BugReportServiceProtocol {
var crashedLastRun: Bool {
get { return underlyingCrashedLastRun }
set(value) { underlyingCrashedLastRun = value }
}
var underlyingCrashedLastRun: Bool!
// MARK: - crash
var crashCallsCount = 0
var crashCalled: Bool {
return crashCallsCount > 0
}
var crashClosure: (() -> Void)?
func crash() {
crashCallsCount += 1
crashClosure?()
}
// MARK: - submitBugReport
var submitBugReportProgressListenerThrowableError: Error?
var submitBugReportProgressListenerCallsCount = 0
var submitBugReportProgressListenerCalled: Bool {
return submitBugReportProgressListenerCallsCount > 0
}
var submitBugReportProgressListenerReceivedArguments: (bugReport: BugReport, progressListener: ProgressListener?)?
var submitBugReportProgressListenerReceivedInvocations: [(bugReport: BugReport, progressListener: ProgressListener?)] = []
var submitBugReportProgressListenerReturnValue: SubmitBugReportResponse!
var submitBugReportProgressListenerClosure: ((BugReport, ProgressListener?) async throws -> SubmitBugReportResponse)?
func submitBugReport(_ bugReport: BugReport, progressListener: ProgressListener?) async throws -> SubmitBugReportResponse {
if let error = submitBugReportProgressListenerThrowableError {
throw error
}
submitBugReportProgressListenerCallsCount += 1
submitBugReportProgressListenerReceivedArguments = (bugReport: bugReport, progressListener: progressListener)
submitBugReportProgressListenerReceivedInvocations.append((bugReport: bugReport, progressListener: progressListener))
if let submitBugReportProgressListenerClosure = submitBugReportProgressListenerClosure {
return try await submitBugReportProgressListenerClosure(bugReport, progressListener)
} else {
return submitBugReportProgressListenerReturnValue
}
}
}
class SessionVerificationControllerProxyMock: SessionVerificationControllerProxyProtocol {
var callbacks: PassthroughSubject<SessionVerificationControllerProxyCallback, Never> {
get { return underlyingCallbacks }
set(value) { underlyingCallbacks = value }
}
var underlyingCallbacks: PassthroughSubject<SessionVerificationControllerProxyCallback, Never>!
var isVerified: Bool {
get { return underlyingIsVerified }
set(value) { underlyingIsVerified = value }
}
var underlyingIsVerified: Bool!
// MARK: - requestVerification
var requestVerificationCallsCount = 0
var requestVerificationCalled: Bool {
return requestVerificationCallsCount > 0
}
var requestVerificationReturnValue: Result<Void, SessionVerificationControllerProxyError>!
var requestVerificationClosure: (() async -> Result<Void, SessionVerificationControllerProxyError>)?
func requestVerification() async -> Result<Void, SessionVerificationControllerProxyError> {
requestVerificationCallsCount += 1
if let requestVerificationClosure = requestVerificationClosure {
return await requestVerificationClosure()
} else {
return requestVerificationReturnValue
}
}
// MARK: - startSasVerification
var startSasVerificationCallsCount = 0
var startSasVerificationCalled: Bool {
return startSasVerificationCallsCount > 0
}
var startSasVerificationReturnValue: Result<Void, SessionVerificationControllerProxyError>!
var startSasVerificationClosure: (() async -> Result<Void, SessionVerificationControllerProxyError>)?
func startSasVerification() async -> Result<Void, SessionVerificationControllerProxyError> {
startSasVerificationCallsCount += 1
if let startSasVerificationClosure = startSasVerificationClosure {
return await startSasVerificationClosure()
} else {
return startSasVerificationReturnValue
}
}
// MARK: - approveVerification
var approveVerificationCallsCount = 0
var approveVerificationCalled: Bool {
return approveVerificationCallsCount > 0
}
var approveVerificationReturnValue: Result<Void, SessionVerificationControllerProxyError>!
var approveVerificationClosure: (() async -> Result<Void, SessionVerificationControllerProxyError>)?
func approveVerification() async -> Result<Void, SessionVerificationControllerProxyError> {
approveVerificationCallsCount += 1
if let approveVerificationClosure = approveVerificationClosure {
return await approveVerificationClosure()
} else {
return approveVerificationReturnValue
}
}
// MARK: - declineVerification
var declineVerificationCallsCount = 0
var declineVerificationCalled: Bool {
return declineVerificationCallsCount > 0
}
var declineVerificationReturnValue: Result<Void, SessionVerificationControllerProxyError>!
var declineVerificationClosure: (() async -> Result<Void, SessionVerificationControllerProxyError>)?
func declineVerification() async -> Result<Void, SessionVerificationControllerProxyError> {
declineVerificationCallsCount += 1
if let declineVerificationClosure = declineVerificationClosure {
return await declineVerificationClosure()
} else {
return declineVerificationReturnValue
}
}
// MARK: - cancelVerification
var cancelVerificationCallsCount = 0
var cancelVerificationCalled: Bool {
return cancelVerificationCallsCount > 0
}
var cancelVerificationReturnValue: Result<Void, SessionVerificationControllerProxyError>!
var cancelVerificationClosure: (() async -> Result<Void, SessionVerificationControllerProxyError>)?
func cancelVerification() async -> Result<Void, SessionVerificationControllerProxyError> {
cancelVerificationCallsCount += 1
if let cancelVerificationClosure = cancelVerificationClosure {
return await cancelVerificationClosure()
} else {
return cancelVerificationReturnValue
}
}
}
// swiftlint:enable all