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

Unable to resolve inherited type 'AnyObject'

lhunath opened this issue · comments

New Issue Checklist

Overview

When a protocol extends AnyObject, the generator does generate a mock for the protocol but the generated mock does not adopt the protocol it is generating for. As a result, we have a mock whose type does not conform the protocol and is unusable in practice.

Example

Failure scenario, UserProject: AnyObject yields a UserProjectMock which does not : UserProject:

public protocol UserProject: AnyObject {
    var isFavorite: Bool { get set }
}

// MARK: - Mocked UserProject
public final class UserProjectMock: Mockingbird.Mock {
  typealias MockingbirdSupertype = Projects.UserProject
  public static let mockingbirdContext = Mockingbird.Context()
  public let mockingbirdContext = Mockingbird.Context(["generator_version": "0.20.0", "module_name": "Projects"])
}

Success scenario, bare UserProject yields a UserProjectMock which does : UserProject:

public protocol UserProject {
    var isFavorite: Bool { get set }
}

public final class UserProjectMock: Projects.UserProject, Mockingbird.Mock {
  typealias MockingbirdSupertype = Projects.UserProject
  public static let mockingbirdContext = Mockingbird.Context()
  public let mockingbirdContext = Mockingbird.Context(["generator_version": "0.20.0", "module_name": "Projects"])

  // MARK: Mocked isFavorite
  public var `isFavorite`: Bool {
    ...
  }
}

Expected Behavior

The conformance of a protocol to : AnyObject should not affect the mock generation since the mock is already a class type.

Environment

  • Mockingbird CLI version: 0.20.0
  • Xcode and Swift version: swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
  • Package manager: SPM
  • Unit testing framework: XCTest

Running with --verbose, we see:

Unable to resolve inherited type 'AnyObject' for 'UserProject'

Work-around, add this to MockingbirdSupport/Swift/AnyObject.swift:

protocol AnyObject {}