typealiased / mockingbird

A Swifty mocking framework for Swift and Objective-C.

Home Page:https://mockingbirdswift.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mock generator ignores class-only protocols

Narayane opened this issue · 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
commented

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

commented

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!