mockingbird icon indicating copy to clipboard operation
mockingbird copied to clipboard

Mock generator ignores class-only protocols

Open Narayane opened this issue 3 years ago • 3 comments

New Issue Checklist

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

Narayane avatar Jan 25 '23 11:01 Narayane

Having the same issue over here.

gabitreat avatar Oct 03 '23 17:10 gabitreat

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 ;)

Narayane avatar Oct 04 '23 08:10 Narayane

Hi @Narayane indeed. This could work, but if the variables are declared as weak some other issues appear. 🤔 I'm not near that project but will try again later and will leave the actual error here. Thanks for the heads up!

gabitreat avatar Oct 04 '23 08:10 gabitreat