Mock generator ignores class-only protocols
Narayane opened this issue · comments
New Issue Checklist
- I updated the framework and generator to the latest version
- I searched the existing GitHub issues and list of common problems
Overview
I need one of my protocols to inherit AnyObject
.
When I do this, mock generator generates relative mock but it only inherits of Mockingbird.Mock
instead of both Mockingbird.Mock
and MyPackageName.MyClassOnlyProtocol
.
Example
protocol MyClassOnlyProtocol: AnyObject { ... }
// MARK: - Mocked MyClassOnlyProtocol
public final class MyClassOnlyProtocolMock: Mockingbird.Mock { ... }
Expected Behavior
protocol MyClassOnlyProtocol: AnyObject { ... }
// MARK: - Mocked MyClassOnlyProtocol
public final class MyClassOnlyProtocolMock: MyPackageName.MyClassOnlyProtocol, Mockingbird.Mock { ... }
Environment
- Mockingbird CLI version (
mockingbird version
): 0.20.0 - Xcode and Swift version (
swift --version
):- Xcode Version 14.1 (14B47b)
- swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
Target: arm64-apple-macosx13.0
- Package manager (CocoaPods, Carthage, SPM project, SPM package): SPM
- Unit testing framework (XCTest, Quick/Nimble): XCTest
- Custom configuration
- Mockingbird ignore files
- Supporting source files
Having the same issue over here.
Hi @gabipago,
I found a workaround to solve this problem.
You can use Supporting source files mechanism.
Just create a AnyObject.swift
file containing code below
import Foundation
protocol AnyObject {}
and put it in the MockingbirdSupport
folder under MockingbirdSupport/Swift/AnyObject.swift
path.
You can now generate your class-only protocols inheriting AnyObject
;)