Problem implementing MockUsable when there are inheritances
Do you have any solution for the case below? AuthenticationSession extends Model. However, I need to make both of then implement MockUsable. Since you are using static var, its impossible to override..
extension AuthenticationSession_: MockUsable {
public static var any: AuthenticationSession_ {
let ret = AuthenticationSession_()
ret.id = "anyId"
return ret
}
public static var anyValue: MockUsable {
return self.any
}
public func equal(to value: MockUsable?) -> Bool {
guard let mock = value as? AuthenticationSession_ else { return false }
return self.id == mock.id
}
}
extension Model: MockUsable {
public static var any: Model {
let ret = Model()
return ret
}
public static var anyValue: MockUsable {
return self.any
}
public func equal(to value: MockUsable?) -> Bool {
guard let mock = value as? Model else { return false }
return false
}
}
Yes for now, we can't make a class MockUsable, if it inherits from another MockUsable class.
We should avoid static variables indeed, but the challenge is to make sure the MockUsable protocol can return an instance of the given type. Don't hesitate to share ideas on how we could deal with this.
Best option I have in mind would be to make usage of factories for MockUsable types, like:
protocol MockUsableFactory {
associatedtype T: MockUsable
func anyValue() -> T
}
Those factories would have to be provided by Mock instances through a MockUsableFactoryProvider protocol like:
protocol MockUsableFactoryProvider {
var factories: [MockUsableFactory] { get }
}
That would make the creation of mocks a bit more complex.
I'll thing about it...
I don't have any idea. However, It would not be nice to complicate the current way.
I'm really getting stuck since I can't for example have a UIViewController as a MockUsable and a HomeViewController as a MockUsable, knowing that HomeViewController extends UIViewController, as all of the other views.
I really would appreciate if we could have a new version solving this issue.
@pirishd any news?