Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock generator ignores class-only protocols #321

Open
2 of 4 tasks
Narayane opened this issue Jan 25, 2023 · 3 comments
Open
2 of 4 tasks

Mock generator ignores class-only protocols #321

Narayane opened this issue Jan 25, 2023 · 3 comments
Labels
framework bug Breaks tests or user testing code

Comments

@Narayane
Copy link

Narayane commented Jan 25, 2023

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 Narayane added the framework bug Breaks tests or user testing code label Jan 25, 2023
@gabitreat
Copy link

Having the same issue over here.

@Narayane
Copy link
Author

Narayane commented Oct 4, 2023

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

@gabitreat
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework bug Breaks tests or user testing code
Projects
None yet
Development

No branches or pull requests

2 participants