Skip to content

Instantly share code, notes, and snippets.

@Nikoloutsos
Created December 8, 2021 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nikoloutsos/1dfa20129f1f95155fd107362a331e16 to your computer and use it in GitHub Desktop.
Save Nikoloutsos/1dfa20129f1f95155fd107362a331e16 to your computer and use it in GitHub Desktop.
class FooProtocolMock: FooProtocol {
//MARK: - foo1
var foo1CallsCount = 0
var foo1Called: Bool {
return foo1CallsCount > 0
}
var foo1Closure: (() -> Void)?
func foo1() {
foo1CallsCount += 1
foo1Closure?()
}
//MARK: - foo2
var foo2CallsCount = 0
var foo2Called: Bool {
return foo2CallsCount > 0
}
var foo2ReturnValue: String!
var foo2Closure: (() -> String)?
func foo2() -> String {
foo2CallsCount += 1
return foo2Closure.map({ $0() }) ?? foo2ReturnValue
}
//MARK: - foo3
var foo3StrIntCallsCount = 0
var foo3StrIntCalled: Bool {
return foo3StrIntCallsCount > 0
}
var foo3StrIntReceivedArguments: (str: String, int: Int)?
var foo3StrIntReceivedInvocations: [(str: String, int: Int)] = []
var foo3StrIntReturnValue: Int!
var foo3StrIntClosure: ((String, Int) -> Int)?
func foo3(str: String, int: Int) -> Int {
foo3StrIntCallsCount += 1
foo3StrIntReceivedArguments = (str: str, int: int)
foo3StrIntReceivedInvocations.append((str: str, int: int))
return foo3StrIntClosure.map({ $0(str, int) }) ?? foo3StrIntReturnValue
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment