mockingbird
mockingbird copied to clipboard
Full support of Combine
New Issue Checklist
- [x] I updated my Mockingbird framework and CLI to the latest version
- [x] I searched for existing GitHub issues
Description
Full support of Combine
Generator Bugs
If the generator produces code that is malformed or does not compile, please provide:
- A minimal example of the original source
import Foundation
import Combine
enum RCAlertState {
case idle, analysis, alert
}
protocol RCAlertProtocol {
var alertState: RCAlertState { get }
var alertStateStream: Published<RCAlertState>.Publisher { get }
func stopAlert()
}
final class RCAlertController: RCAlertProtocol {
@Published private(set) var alertState: RCAlertState = .idle
var alertStateStream: Published<RCAlertState>.Publisher { self.$alertState }
func stopAlert() {
self.alertState = .idle
}
}
- The actual mocking code generated (when I use
mock(RCAlertProtocol.self)
)
![Capture d’écran 2021-10-20 à 00 11 02](https://user-images.githubusercontent.com/4921308/137997896-b81f0b67-62c3-4b22-b4ba-c58639a7509e.png)
- The expected mocking code that should be generated (or a description)
No errors in .generated.swift file.
Environment
- Mockingbird CLI version (
mockingbird version
) 0.18.1 - Xcode and macOS version (are you running a beta?) Xcode 13 / macOS Big Sur 11.6
- Swift version (
swift --version
) Swift 5.5 - Installation method (CocoaPods, Carthage, from source, etc) SPM
- Unit testing framework (XCTest, Quick + Nimble, etc) XCTest
- Does your project use
.mockingbird-ignore
? no - Are you using supporting source files? no
@andrewchang-bird When I add Combine.
before type in error (-->Combine.<--
below) in .generated.swift
file, I do not have errors anymore when I build.
// MARK: Mocked alertStateStream
public var `alertStateStream`: Published<RCAlertState>.Publisher {
get {
return self.mockingbirdContext.mocking.didInvoke(Mockingbird.SwiftInvocation(selectorName: "alertStateStream.getter", setterSelectorName: "alertStateStream.setter", selectorType: Mockingbird.SelectorType.getter, arguments: [], returnType: Swift.ObjectIdentifier((-->Combine.<-- Published<RCAlertState>.Publisher).self))) {
self.mockingbirdContext.recordInvocation($0)
let mkbImpl = self.mockingbirdContext.stubbing.implementation(for: $0)
if let mkbImpl = mkbImpl as? () -> Published<RCAlertState>.Publisher { return mkbImpl() }
if let mkbImpl = mkbImpl as? () -> Any? { return Mockingbird.dynamicCast(mkbImpl()) as Published<RCAlertState>.Publisher }
if let mkbImpl = mkbImpl as? () -> Any? { return Mockingbird.dynamicCast(mkbImpl()) as Published<RCAlertState>.Publisher }
for mkbTargetBox in self.mockingbirdContext.proxy.targets(for: $0) {
switch mkbTargetBox.target {
case .super:
break
case .object(let mkbObject):
guard var mkbObject = mkbObject as? MockingbirdSupertype else { break }
let mkbValue: Published<RCAlertState>.Publisher = mkbObject.`alertStateStream`
self.mockingbirdContext.proxy.updateTarget(&mkbObject, in: mkbTargetBox)
return mkbValue
}
}
if let mkbValue = self.mockingbirdContext.stubbing.defaultValueProvider.value.provideValue(for: (-->Combine.<--Published<RCAlertState>.Publisher).self) { return mkbValue }
self.mockingbirdContext.stubbing.failTest(for: $0, at: self.mockingbirdContext.sourceLocation)
}
}
}
public func getAlertStateStream() -> Mockingbird.Mockable<Mockingbird.PropertyGetterDeclaration, () -> Published<RCAlertState>.Publisher, Published<RCAlertState>.Publisher> {
return Mockingbird.Mockable<Mockingbird.PropertyGetterDeclaration, () -> Published<RCAlertState>.Publisher, Published<RCAlertState>.Publisher>(mock: self, invocation: Mockingbird.SwiftInvocation(selectorName: "alertStateStream.getter", setterSelectorName: "alertStateStream.setter", selectorType: Mockingbird.SelectorType.getter, arguments: [], returnType: Swift.ObjectIdentifier((-->Combine.<--Published<RCAlertState>.Publisher).self)))
}
A trivial example of this issue:
import Combine
protocol SomeProtocol {
var somePublisher: Published<String>.Publisher { get }
}
And the fix that allows the generator to produce code without errors:
import Combine
protocol SomeProtocol {
var somePublisher: Combine.Published<String>.Publisher { get }
}