Best Mockingbird code snippet using ArgumentMatcher
iOSMockingBirdMocks.generated.swift
Source:iOSMockingBirdMocks.generated.swift  
...28  }29  public enum InitializerProxy {}30  // MARK: Mocked `application`(_ `application`: UIApplication, `configurationForConnecting` `connectingSceneSession`: UISceneSession, `options`: UIScene.ConnectionOptions)31  public override func `application`(_ `application`: UIApplication, `configurationForConnecting` `connectingSceneSession`: UISceneSession, `options`: UIScene.ConnectionOptions) -> UISceneConfiguration {32    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`application`(_ `application`: UIApplication, `configurationForConnecting` `connectingSceneSession`: UISceneSession, `options`: UIScene.ConnectionOptions) -> UISceneConfiguration", arguments: [Mockingbird.ArgumentMatcher(`application`), Mockingbird.ArgumentMatcher(`connectingSceneSession`), Mockingbird.ArgumentMatcher(`options`)])33    mockingContext.didInvoke(invocation)34    let implementation = stubbingContext.implementation(for: invocation, optional: false)35    if let concreteImplementation = implementation as? (UIApplication, UISceneSession, UIScene.ConnectionOptions) -> UISceneConfiguration {36      return concreteImplementation(`application`, `connectingSceneSession`, `options`)37    } else {38      return (implementation as! () -> UISceneConfiguration)()39    }40  }41  public func `application`(_ `application`: @escaping @autoclosure () -> UIApplication, `configurationForConnecting` `connectingSceneSession`: @escaping @autoclosure () -> UISceneSession, `options`: @escaping @autoclosure () -> UIScene.ConnectionOptions) -> Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIApplication, UISceneSession, UIScene.ConnectionOptions) -> UISceneConfiguration, UISceneConfiguration> {42    let arguments: [Mockingbird.ArgumentMatcher] = [Mockingbird.resolve(`application`), Mockingbird.resolve(`connectingSceneSession`), Mockingbird.resolve(`options`)]43    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`application`(_ `application`: UIApplication, `configurationForConnecting` `connectingSceneSession`: UISceneSession, `options`: UIScene.ConnectionOptions) -> UISceneConfiguration", arguments: arguments)44    return Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIApplication, UISceneSession, UIScene.ConnectionOptions) -> UISceneConfiguration, UISceneConfiguration>(mock: self, invocation: invocation)45  }46  // MARK: Mocked `application`(_ `application`: UIApplication, `didDiscardSceneSessions` `sceneSessions`: Set<UISceneSession>)47  public override func `application`(_ `application`: UIApplication, `didDiscardSceneSessions` `sceneSessions`: Set<UISceneSession>) -> Void {48    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`application`(_ `application`: UIApplication, `didDiscardSceneSessions` `sceneSessions`: Set<UISceneSession>) -> Void", arguments: [Mockingbird.ArgumentMatcher(`application`), Mockingbird.ArgumentMatcher(`sceneSessions`)])49    mockingContext.didInvoke(invocation)50    let implementation = stubbingContext.implementation(for: invocation, optional: true)51    if let concreteImplementation = implementation as? (UIApplication, Set<UISceneSession>) -> Void {52      concreteImplementation(`application`, `sceneSessions`)53    } else {54      (implementation as? () -> Void)?()55    }56  }57  public func `application`(_ `application`: @escaping @autoclosure () -> UIApplication, `didDiscardSceneSessions` `sceneSessions`: @escaping @autoclosure () -> Set<UISceneSession>) -> Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIApplication, Set<UISceneSession>) -> Void, Void> {58    let arguments: [Mockingbird.ArgumentMatcher] = [Mockingbird.resolve(`application`), Mockingbird.resolve(`sceneSessions`)]59    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`application`(_ `application`: UIApplication, `didDiscardSceneSessions` `sceneSessions`: Set<UISceneSession>) -> Void", arguments: arguments)60    return Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIApplication, Set<UISceneSession>) -> Void, Void>(mock: self, invocation: invocation)61  }62  // MARK: Mocked `application`(_ `application`: UIApplication, `didFinishLaunchingWithOptions` `launchOptions`: [UIApplication.LaunchOptionsKey: Any]?)63  public override func `application`(_ `application`: UIApplication, `didFinishLaunchingWithOptions` `launchOptions`: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {64    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`application`(_ `application`: UIApplication, `didFinishLaunchingWithOptions` `launchOptions`: [UIApplication.LaunchOptionsKey: Any]?) -> Bool", arguments: [Mockingbird.ArgumentMatcher(`application`), Mockingbird.ArgumentMatcher(`launchOptions`)])65    mockingContext.didInvoke(invocation)66    let implementation = stubbingContext.implementation(for: invocation, optional: false)67    if let concreteImplementation = implementation as? (UIApplication, [UIApplication.LaunchOptionsKey: Any]?) -> Bool {68      return concreteImplementation(`application`, `launchOptions`)69    } else {70      return (implementation as! () -> Bool)()71    }72  }73  public func `application`(_ `application`: @escaping @autoclosure () -> UIApplication, `didFinishLaunchingWithOptions` `launchOptions`: @escaping @autoclosure () -> [UIApplication.LaunchOptionsKey: Any]?) -> Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIApplication, [UIApplication.LaunchOptionsKey: Any]?) -> Bool, Bool> {74    let arguments: [Mockingbird.ArgumentMatcher] = [Mockingbird.resolve(`application`), Mockingbird.resolve(`launchOptions`)]75    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`application`(_ `application`: UIApplication, `didFinishLaunchingWithOptions` `launchOptions`: [UIApplication.LaunchOptionsKey: Any]?) -> Bool", arguments: arguments)76    return Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIApplication, [UIApplication.LaunchOptionsKey: Any]?) -> Bool, Bool>(mock: self, invocation: invocation)77  }78}79/// Initialize an initializable class mock of `iOSMockingBird.AppDelegate`.80public func mock(_ type: iOSMockingBird.AppDelegate.Type, file: StaticString = #file, line: UInt = #line) -> AppDelegateMock.InitializerProxy.Type {81  return AppDelegateMock.InitializerProxy.self82}83// MARK: - Mocked RestAPI84public final class RestAPIMock: iOSMockingBird.RestAPI, Mockingbird.Mock {85  static let staticMock = Mockingbird.StaticMock()86  public let mockingContext = Mockingbird.MockingContext()87  public let stubbingContext = Mockingbird.StubbingContext()88  public let mockMetadata = Mockingbird.MockMetadata(["generator_version": "0.11.1", "module_name": "iOSMockingBird"])89  public var sourceLocation: Mockingbird.SourceLocation? {90    get { return stubbingContext.sourceLocation }91    set {92      stubbingContext.sourceLocation = newValue93      RestAPIMock.staticMock.stubbingContext.sourceLocation = newValue94    }95  }96  fileprivate init(sourceLocation: Mockingbird.SourceLocation) {97    super.init()98    Mockingbird.checkVersion(for: self)99    self.sourceLocation = sourceLocation100  }101  // MARK: Mocked `index`(`ascOrder`: Bool)102  public override func `index`(`ascOrder`: Bool) -> AnyPublisher<[String], URLError> {103    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`index`(`ascOrder`: Bool) -> AnyPublisher<[String], URLError>", arguments: [Mockingbird.ArgumentMatcher(`ascOrder`)])104    mockingContext.didInvoke(invocation)105    let implementation = stubbingContext.implementation(for: invocation, optional: false)106    if let concreteImplementation = implementation as? (Bool) -> AnyPublisher<[String], URLError> {107      return concreteImplementation(`ascOrder`)108    } else {109      return (implementation as! () -> AnyPublisher<[String], URLError>)()110    }111  }112  public func `index`(`ascOrder`: @escaping @autoclosure () -> Bool) -> Mockingbird.Mockable<Mockingbird.MethodDeclaration, (Bool) -> AnyPublisher<[String], URLError>, AnyPublisher<[String], URLError>> {113    let arguments: [Mockingbird.ArgumentMatcher] = [Mockingbird.resolve(`ascOrder`)]114    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`index`(`ascOrder`: Bool) -> AnyPublisher<[String], URLError>", arguments: arguments)115    return Mockingbird.Mockable<Mockingbird.MethodDeclaration, (Bool) -> AnyPublisher<[String], URLError>, AnyPublisher<[String], URLError>>(mock: self, invocation: invocation)116  }117}118/// Initialize a class mock of `iOSMockingBird.RestAPI`.119public func mock(_ type: iOSMockingBird.RestAPI.Type, file: StaticString = #file, line: UInt = #line) -> RestAPIMock {120  return RestAPIMock(sourceLocation: SourceLocation(file, line))121}122// MARK: - Mocked SceneDelegate123public final class SceneDelegateMock: iOSMockingBird.SceneDelegate, Mockingbird.Mock {124  static let staticMock = Mockingbird.StaticMock()125  public let mockingContext = Mockingbird.MockingContext()126  public let stubbingContext = Mockingbird.StubbingContext()127  public let mockMetadata = Mockingbird.MockMetadata(["generator_version": "0.11.1", "module_name": "iOSMockingBird"])128  public var sourceLocation: Mockingbird.SourceLocation? {129    get { return stubbingContext.sourceLocation }130    set {131      stubbingContext.sourceLocation = newValue132      SceneDelegateMock.staticMock.stubbingContext.sourceLocation = newValue133    }134  }135  public enum InitializerProxy {}136  // MARK: Mocked window137  override public var `window`: UIWindow? {138    get {139      let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "window.get", arguments: [])140      mockingContext.didInvoke(invocation)141      return (stubbingContext.implementation(for: invocation) as! () -> UIWindow?)()142    }143    set {144      let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "window.set", arguments: [ArgumentMatcher(newValue)])145      mockingContext.didInvoke(invocation)146      let implementation = stubbingContext.implementation(for: invocation, optional: true)147      if let concreteImplementation = implementation as? (UIWindow?) -> Void {148        concreteImplementation(newValue)149      } else {150        (implementation as? () -> Void)?()151      }152    }153  }154  public func getWindow() -> Mockingbird.Mockable<Mockingbird.VariableDeclaration, () -> UIWindow?, UIWindow?> {155    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "window.get", arguments: [])156    return Mockingbird.Mockable<Mockingbird.VariableDeclaration, () -> UIWindow?, UIWindow?>(mock: self, invocation: invocation)157  }158  public func setWindow(_ newValue: @escaping @autoclosure () -> UIWindow?) -> Mockingbird.Mockable<Mockingbird.VariableDeclaration, (UIWindow?) -> Void, Void> {159    let arguments: [Mockingbird.ArgumentMatcher] = [Mockingbird.resolve(newValue)]160    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "window.set", arguments: arguments)161    return Mockingbird.Mockable<Mockingbird.VariableDeclaration, (UIWindow?) -> Void, Void>(mock: self, invocation: invocation)162  }163  // MARK: Mocked `scene`(_ `scene`: UIScene, `willConnectTo` `session`: UISceneSession, `options` `connectionOptions`: UIScene.ConnectionOptions)164  public override func `scene`(_ `scene`: UIScene, `willConnectTo` `session`: UISceneSession, `options` `connectionOptions`: UIScene.ConnectionOptions) -> Void {165    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`scene`(_ `scene`: UIScene, `willConnectTo` `session`: UISceneSession, `options` `connectionOptions`: UIScene.ConnectionOptions) -> Void", arguments: [Mockingbird.ArgumentMatcher(`scene`), Mockingbird.ArgumentMatcher(`session`), Mockingbird.ArgumentMatcher(`connectionOptions`)])166    mockingContext.didInvoke(invocation)167    let implementation = stubbingContext.implementation(for: invocation, optional: true)168    if let concreteImplementation = implementation as? (UIScene, UISceneSession, UIScene.ConnectionOptions) -> Void {169      concreteImplementation(`scene`, `session`, `connectionOptions`)170    } else {171      (implementation as? () -> Void)?()172    }173  }174  public func `scene`(_ `scene`: @escaping @autoclosure () -> UIScene, `willConnectTo` `session`: @escaping @autoclosure () -> UISceneSession, `options` `connectionOptions`: @escaping @autoclosure () -> UIScene.ConnectionOptions) -> Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIScene, UISceneSession, UIScene.ConnectionOptions) -> Void, Void> {175    let arguments: [Mockingbird.ArgumentMatcher] = [Mockingbird.resolve(`scene`), Mockingbird.resolve(`session`), Mockingbird.resolve(`connectionOptions`)]176    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`scene`(_ `scene`: UIScene, `willConnectTo` `session`: UISceneSession, `options` `connectionOptions`: UIScene.ConnectionOptions) -> Void", arguments: arguments)177    return Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIScene, UISceneSession, UIScene.ConnectionOptions) -> Void, Void>(mock: self, invocation: invocation)178  }179  // MARK: Mocked `sceneDidBecomeActive`(_ `scene`: UIScene)180  public override func `sceneDidBecomeActive`(_ `scene`: UIScene) -> Void {181    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`sceneDidBecomeActive`(_ `scene`: UIScene) -> Void", arguments: [Mockingbird.ArgumentMatcher(`scene`)])182    mockingContext.didInvoke(invocation)183    let implementation = stubbingContext.implementation(for: invocation, optional: true)184    if let concreteImplementation = implementation as? (UIScene) -> Void {185      concreteImplementation(`scene`)186    } else {187      (implementation as? () -> Void)?()188    }189  }190  public func `sceneDidBecomeActive`(_ `scene`: @escaping @autoclosure () -> UIScene) -> Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIScene) -> Void, Void> {191    let arguments: [Mockingbird.ArgumentMatcher] = [Mockingbird.resolve(`scene`)]192    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`sceneDidBecomeActive`(_ `scene`: UIScene) -> Void", arguments: arguments)193    return Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIScene) -> Void, Void>(mock: self, invocation: invocation)194  }195  // MARK: Mocked `sceneDidDisconnect`(_ `scene`: UIScene)196  public override func `sceneDidDisconnect`(_ `scene`: UIScene) -> Void {197    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`sceneDidDisconnect`(_ `scene`: UIScene) -> Void", arguments: [Mockingbird.ArgumentMatcher(`scene`)])198    mockingContext.didInvoke(invocation)199    let implementation = stubbingContext.implementation(for: invocation, optional: true)200    if let concreteImplementation = implementation as? (UIScene) -> Void {201      concreteImplementation(`scene`)202    } else {203      (implementation as? () -> Void)?()204    }205  }206  public func `sceneDidDisconnect`(_ `scene`: @escaping @autoclosure () -> UIScene) -> Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIScene) -> Void, Void> {207    let arguments: [Mockingbird.ArgumentMatcher] = [Mockingbird.resolve(`scene`)]208    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`sceneDidDisconnect`(_ `scene`: UIScene) -> Void", arguments: arguments)209    return Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIScene) -> Void, Void>(mock: self, invocation: invocation)210  }211  // MARK: Mocked `sceneDidEnterBackground`(_ `scene`: UIScene)212  public override func `sceneDidEnterBackground`(_ `scene`: UIScene) -> Void {213    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`sceneDidEnterBackground`(_ `scene`: UIScene) -> Void", arguments: [Mockingbird.ArgumentMatcher(`scene`)])214    mockingContext.didInvoke(invocation)215    let implementation = stubbingContext.implementation(for: invocation, optional: true)216    if let concreteImplementation = implementation as? (UIScene) -> Void {217      concreteImplementation(`scene`)218    } else {219      (implementation as? () -> Void)?()220    }221  }222  public func `sceneDidEnterBackground`(_ `scene`: @escaping @autoclosure () -> UIScene) -> Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIScene) -> Void, Void> {223    let arguments: [Mockingbird.ArgumentMatcher] = [Mockingbird.resolve(`scene`)]224    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`sceneDidEnterBackground`(_ `scene`: UIScene) -> Void", arguments: arguments)225    return Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIScene) -> Void, Void>(mock: self, invocation: invocation)226  }227  // MARK: Mocked `sceneWillEnterForeground`(_ `scene`: UIScene)228  public override func `sceneWillEnterForeground`(_ `scene`: UIScene) -> Void {229    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`sceneWillEnterForeground`(_ `scene`: UIScene) -> Void", arguments: [Mockingbird.ArgumentMatcher(`scene`)])230    mockingContext.didInvoke(invocation)231    let implementation = stubbingContext.implementation(for: invocation, optional: true)232    if let concreteImplementation = implementation as? (UIScene) -> Void {233      concreteImplementation(`scene`)234    } else {235      (implementation as? () -> Void)?()236    }237  }238  public func `sceneWillEnterForeground`(_ `scene`: @escaping @autoclosure () -> UIScene) -> Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIScene) -> Void, Void> {239    let arguments: [Mockingbird.ArgumentMatcher] = [Mockingbird.resolve(`scene`)]240    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`sceneWillEnterForeground`(_ `scene`: UIScene) -> Void", arguments: arguments)241    return Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIScene) -> Void, Void>(mock: self, invocation: invocation)242  }243  // MARK: Mocked `sceneWillResignActive`(_ `scene`: UIScene)244  public override func `sceneWillResignActive`(_ `scene`: UIScene) -> Void {245    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`sceneWillResignActive`(_ `scene`: UIScene) -> Void", arguments: [Mockingbird.ArgumentMatcher(`scene`)])246    mockingContext.didInvoke(invocation)247    let implementation = stubbingContext.implementation(for: invocation, optional: true)248    if let concreteImplementation = implementation as? (UIScene) -> Void {249      concreteImplementation(`scene`)250    } else {251      (implementation as? () -> Void)?()252    }253  }254  public func `sceneWillResignActive`(_ `scene`: @escaping @autoclosure () -> UIScene) -> Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIScene) -> Void, Void> {255    let arguments: [Mockingbird.ArgumentMatcher] = [Mockingbird.resolve(`scene`)]256    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`sceneWillResignActive`(_ `scene`: UIScene) -> Void", arguments: arguments)257    return Mockingbird.Mockable<Mockingbird.MethodDeclaration, (UIScene) -> Void, Void>(mock: self, invocation: invocation)258  }259}260/// Initialize an initializable class mock of `iOSMockingBird.SceneDelegate`.261public func mock(_ type: iOSMockingBird.SceneDelegate.Type, file: StaticString = #file, line: UInt = #line) -> SceneDelegateMock.InitializerProxy.Type {262  return SceneDelegateMock.InitializerProxy.self263}264// MARK: - Mocked UseCase265public final class UseCaseMock: iOSMockingBird.UseCase, Mockingbird.Mock {266  static let staticMock = Mockingbird.StaticMock()267  public let mockingContext = Mockingbird.MockingContext()268  public let stubbingContext = Mockingbird.StubbingContext()269  public let mockMetadata = Mockingbird.MockMetadata(["generator_version": "0.11.1", "module_name": "iOSMockingBird"])270  public var sourceLocation: Mockingbird.SourceLocation? {271    get { return stubbingContext.sourceLocation }272    set {273      stubbingContext.sourceLocation = newValue274      UseCaseMock.staticMock.stubbingContext.sourceLocation = newValue275    }276  }277  public enum InitializerProxy {278    public static func initialize(`restApi`: iOSMockingBird.RestAPI, __file: StaticString = #file, __line: UInt = #line) -> UseCaseMock {279      let mock: UseCaseMock = UseCaseMock(restApi: `restApi`)280      mock.sourceLocation = SourceLocation(__file, __line)281      return mock282    }283  }284  // MARK: Mocked `get`()285  public override func `get`() -> AnyPublisher<[String], URLError> {286    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`get`() -> AnyPublisher<[String], URLError>", arguments: [])287    mockingContext.didInvoke(invocation)288    let implementation = stubbingContext.implementation(for: invocation, optional: false)289    if let concreteImplementation = implementation as? () -> AnyPublisher<[String], URLError> {290      return concreteImplementation()291    } else {292      return (implementation as! () -> AnyPublisher<[String], URLError>)()293    }294  }295  public func `get`() -> Mockingbird.Mockable<Mockingbird.MethodDeclaration, () -> AnyPublisher<[String], URLError>, AnyPublisher<[String], URLError>> {296    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`get`() -> AnyPublisher<[String], URLError>", arguments: [])297    return Mockingbird.Mockable<Mockingbird.MethodDeclaration, () -> AnyPublisher<[String], URLError>, AnyPublisher<[String], URLError>>(mock: self, invocation: invocation)298  }299  // MARK: Mocked init(`restApi`: iOSMockingBird.RestAPI)300  public required override init(`restApi`: iOSMockingBird.RestAPI) {301    super.init(restApi: `restApi`)302    Mockingbird.checkVersion(for: self)303    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "init(`restApi`: iOSMockingBird.RestAPI) ", arguments: [Mockingbird.ArgumentMatcher(`restApi`)])304    mockingContext.didInvoke(invocation)305  }306}307/// Initialize an initializable class mock of `iOSMockingBird.UseCase`.308public func mock(_ type: iOSMockingBird.UseCase.Type, file: StaticString = #file, line: UInt = #line) -> UseCaseMock.InitializerProxy.Type {309  return UseCaseMock.InitializerProxy.self310}...TypeFacade.swift
Source:TypeFacade.swift  
...5//  Created by Andrew Chang on 8/3/19.6//7import Foundation8/// This is a hack to get strongly-typed stubbing/verification parameters. The goal is to have9/// `ArgumentMatcher` "conform" to any reference or value type so that it's possible to pass both10/// an actual concrete instance of a type OR a matcher. This provides better compile-time11/// guarantees and autocompletion compared to conforming all parameter types to a common protocol.12///13/// It goes without saying that this should probably never be done in production.14private class ResolutionContext {15  enum Constants {16    static let contextKey = DispatchSpecificKey<ResolutionContext>()17    static let resultSentinel = NSException(18      name: NSExceptionName(rawValue: "co.bird.mockingbird.ResolutionContext.result"),19      reason: nil,20      userInfo: nil)21  }22  23  class Result {24    var value: Any? {25      didSet {26        MKBThrowException(Constants.resultSentinel)27      }28    }29  }30  let result = Result()31  32  private static let sharedQueue = DispatchQueue(label: "co.bird.mockingbird.ResolutionContext")33  34  static var sharedContext: ResolutionContext? {35    return DispatchQueue.getSpecific(key: Constants.contextKey)36  }37  38  func resolveTypeFacade<T>(_ block: () -> T) -> Any? {39    return Self.sharedQueue.sync {40      _ = MKBTryBlock {41        Self.sharedQueue.setSpecific(key: Constants.contextKey, value: self)42        result.value = block() // Returns the real value if not an argument matcher.43      }44      Self.sharedQueue.setSpecific(key: Constants.contextKey, value: nil)45      return result.value46    }47  }48}49func unsafeFakeValue<T>() -> T {50  return UnsafeMutableRawPointer51    .allocate(byteCount: 512, alignment: MemoryLayout<Int8>.alignment)52    .bindMemory(to: T.self, capacity: 1)53    .pointee54}55func fakePrimitiveValue<T>() -> T {56  if let value = ValueProvider.standardProvider.provideValue(for: T.self) {57    return value58  }59  // Fall back to returning a buffer of ample size. This can break for bridged primitive types.60  return unsafeFakeValue()61}62/// Wraps a value into any type `T` when resolved inside of a `ResolutionContext<T>`.63func createTypeFacade<T>(_ value: Any?) -> T {64  if let context = ResolutionContext.sharedContext {65    context.result.value = value66    fatalError("This should never run")67  }68  69  guard let recorder = InvocationRecorder.sharedRecorder else {70    preconditionFailure("Invalid resolution thread context state")71  }72  73  if let argumentIndex = recorder.argumentIndex {74    recorder.recordFacadeValue(value, at: argumentIndex)75  } else {76    let error = TestFailure.missingExplicitArgumentPosition(matcher: value as? ArgumentMatcher)77    recorder.recordUnindexedFacadeValue(value, error: error)78  }79  80  // This is actually an invocation recording context, but the type is not mockable in Obj-C.81  return fakePrimitiveValue()82}83/// Wraps a value into an Obj-C object `T` when resolved inside of a `ResolutionContext<T>`.84func createTypeFacade<T: NSObjectProtocol>(_ value: Any?) -> T {85  if let context = ResolutionContext.sharedContext {86    context.result.value = value87    fatalError("This should never run")88  }89  guard InvocationRecorder.sharedRecorder != nil else {90    preconditionFailure("Invalid resolution thread context state")91  }92  // This is actually an invocation recording context.93  return MKBTypeFacade(mock: MKBMock(T.self), object: value as Any).fixupType()94}95/// Resolve `parameter` when `T` is _not_ known to be `Equatable`.96func resolve<T>(_ parameter: () -> T) -> ArgumentMatcher {97  let resolvedValue = ResolutionContext().resolveTypeFacade(parameter)98  if let matcher = resolvedValue as? ArgumentMatcher { return matcher }99  if let typedValue = resolvedValue as? T { return ArgumentMatcher(typedValue) }100  return ArgumentMatcher(resolvedValue)101}102/// Resolve `parameter` when `T` is known to be `Equatable`.103func resolve<T: Equatable>(_ parameter: () -> T) -> ArgumentMatcher {104  let resolvedValue = ResolutionContext().resolveTypeFacade(parameter)105  if let matcher = resolvedValue as? ArgumentMatcher { return matcher }106  if let typedValue = resolvedValue as? T { return ArgumentMatcher(typedValue) }107  return ArgumentMatcher(resolvedValue)108}109/// Resolve `parameter` when the closure returns an `ArgumentMatcher`.110func resolve(_ parameter: @escaping () -> ArgumentMatcher) -> ArgumentMatcher {111  return parameter()112}ArgumentMatcher.swift
Source:ArgumentMatcher.swift  
1//2//  ArgumentMatcher.swift3//  Mockingbird4//5//  Created by Andrew Chang on 7/29/19.6//7import Foundation8/// Matches argument values with a comparator.9@objc(MKBArgumentMatcher) public class ArgumentMatcher: NSObject {10  /// Necessary for custom comparators such as `any()` that only work on the lhs.11  enum Priority: UInt {12    case low = 0, `default` = 500, high = 100013  }14  /// A base instance to compare using `comparator`.15  let base: Any?16  17  /// The original type of the base instance.18  let baseType: Any?19  /// A debug description for verbose test failure output.20  let internalDescription: String21  public override var description: String { return internalDescription }22  23  /// The declaration of the matcher to use in test failure examples.24  let declaration: String25  /// The commutativity of the matcher comparator.26  let priority: Priority27  /// The method to compare base instances, returning `true` if they should be considered the same.28  let comparator: (_ lhs: Any?, _ rhs: Any?) -> Bool29  func compare(with rhs: Any?) -> Bool {30    return comparator(base, rhs)31  }32  init<T: Equatable>(_ base: T?,33                     description: String? = nil,34                     declaration: String? = nil,35                     priority: Priority = .default) {36    self.base = base37    self.baseType = T.self38    self.priority = priority39    self.comparator = { base == $1 as? T }40    41    let internalDescription = description ?? "\(String.describe(base))"42    self.internalDescription = internalDescription43    self.declaration = declaration ?? internalDescription44  }45  46  convenience init(description: String,47                   declaration: String? = nil,48                   priority: Priority = .low,49                   comparator: @escaping () -> Bool) {50    self.init(Optional<ArgumentMatcher>(nil), description: description, priority: priority) {51      (_, _) -> Bool in52      return comparator()53    }54  }55  56  init<T>(_ base: T? = nil,57          description: String? = nil,58          declaration: String? = nil,59          priority: Priority = .low,60          comparator: ((Any?, Any?) -> Bool)? = nil) {61    self.base = base62    self.baseType = type(of: base)63    self.priority = priority64    self.comparator = comparator ?? { $0 as AnyObject === $1 as AnyObject }65    let annotation = comparator == nil ? " (by reference)" : ""66    67    let internalDescription = description ?? "\(String.describe(base))\(annotation)"68    self.internalDescription = internalDescription69    self.declaration = declaration ?? internalDescription70  }71  72  @objc public init(_ base: Any? = nil,73                    description: String? = nil,74                    comparator: @escaping (Any?, Any?) -> Bool) {75    self.base = base76    self.baseType = type(of: base)77    self.priority = .low78    self.comparator = comparator79    80    let internalDescription = description ?? String.describe(base)81    self.internalDescription = internalDescription82    self.declaration = internalDescription83  }84  85  init(_ matcher: ArgumentMatcher) {86    self.base = matcher.base87    self.baseType = type(of: matcher.base)88    self.priority = matcher.priority89    self.comparator = matcher.comparator90    self.internalDescription = matcher.description91    self.declaration = matcher.declaration92  }93}94// MARK: - Equatable95extension ArgumentMatcher {96  public static func == (lhs: ArgumentMatcher, rhs: ArgumentMatcher) -> Bool {97    if lhs.priority.rawValue >= rhs.priority.rawValue {98      return lhs.compare(with: rhs.base)99    } else {100      return rhs.compare(with: lhs.base)101    }102  }103  104  public static func != (lhs: ArgumentMatcher, rhs: ArgumentMatcher) -> Bool {105    return !(lhs == rhs)106  }107}ArgumentMatcher
Using AI Code Generation
1class ArgumentMatcher<T>: Matcher {2    let matcher: (T) -> Bool3    init(matcher: @escaping (T) -> Bool) {4    }5    func matches(_ value: Any?) -> Bool {6        guard let value = value as? T else { return false }7        return matcher(value)8    }9}10func argThat<T>(_ matcher: @escaping (T) -> Bool) -> T {11    return ArgumentMatcher(matcher: matcher).cast()12}13class ArgumentMatcher<T>: Matcher {14    let matcher: (T) -> Bool15    init(matcher: @escaping (T) -> Bool) {16    }17    func matches(_ value: Any?) -> Bool {18        guard let value = value as? T else { return false }19        return matcher(value)20    }21}22func argThat<T>(_ matcher: @escaping (T) -> Bool) -> T {23    return ArgumentMatcher(matcher: matcher).cast()24}25class ArgumentMatcher<T>: Matcher {26    let matcher: (T) -> Bool27    init(matcher: @escaping (T) -> Bool) {28    }29    func matches(_ value: Any?) -> Bool {30        guard let value = value as? T else { return false }31        return matcher(value)32    }33}34func argThat<T>(_ matcher: @escaping (T) -> Bool) -> T {35    return ArgumentMatcher(matcher: matcher).cast()36}37class ArgumentMatcher<T>: Matcher {38    let matcher: (T) -> Bool39    init(matcher: @escaping (T) -> Bool) {40    }41    func matches(_ value: Any?) -> Bool {42        guard let value = value as? T else { return false }43        return matcher(value)44    }45}46func argThat<T>(_ matcher: @escaping (T) -> Bool) -> T {47    return ArgumentMatcher(matcher: matcher).cast()48}49class ArgumentMatcher<T>: Matcher {ArgumentMatcher
Using AI Code Generation
1import Mockingbird2import XCTest3@testable import MockingbirdTestsHost4class Mock1: 1, Mockingbird.Mock {5  init() {}6  init(a: Int) {7  }8}9struct __StubbingProxy_1: Mockingbird.StubbingProxy {10  func doSomething() -> Mockingbird.StubFunction<Void, Void> {11    return Mockingbird.StubFunction(identifier: "doSomething()", proxy: __handler)12  }13  func doSomething(a: ParameterMatcher<Int>) -> Mockingbird.StubFunction<Int, Void> {14    return Mockingbird.StubFunction(identifier: "doSomething(a: ParameterMatcher<Int>)", proxy: __handler)15  }16}17struct __VerificationProxy_1: Mockingbird.VerificationProxy {18  func doSomething() -> Mockingbird.VerificationFunction<Void> {19    return Mockingbird.VerificationFunction(identifier: "doSomething()", proxy: __handler)20  }21  func doSomething(a: ParameterMatcher<Int>) -> Mockingbird.VerificationFunction<Int> {22    return Mockingbird.VerificationFunction(identifier: "doSomething(a: ParameterMatcher<Int>)", proxy: __handler)23  }24}25extension Mock1: 1 {26  func doSomething() {27    return __handler.handle(self, "doSomething()", parameters: ())28  }29  func doSomething(a: Int) {30    return __handler.handle(self, "doSomething(a: ParameterMatcher<Int>)", parameters: (a))31  }32}33import Mockingbird34import XCTest35@testable import MockingbirdTestsHost36class Mock2: 2, Mockingbird.Mock {ArgumentMatcher
Using AI Code Generation
1import Mockingbird2import XCTest3class ArgumentMatcherTests: XCTestCase {4    func testArgumentMatcher() {5        let mock = mock(ArgumentMatcher.self)6        given(mock.method(argument: any())) ~> "matched"7        XCTAssertEqual(mock.method(argument: argument), "matched")8    }9}10class ArgumentMatcher {11    func method(argument: String) -> String {12    }13}14import Mockingbird15import XCTest16class ArgumentMatcherTests: XCTestCase {17    func testArgumentMatcher() {18        let mock = mock(ArgumentMatcher.self)19        given(mock.method(argument: any())) ~> "matched"20        XCTAssertEqual(mock.method(argument: argument), "matched")21    }22}23class ArgumentMatcher {24    func method(argument: String) -> String {25    }26}27import Mockingbird28import XCTest29class ArgumentMatcherTests: XCTestCase {30    func testArgumentMatcher() {31        let mock = mock(ArgumentMatcher.self)32        given(mock.method(argument: any())) ~> "matched"33        XCTAssertEqual(mock.method(argument: argument), "matched")34    }35}36class ArgumentMatcher {37    func method(argument: String) -> String {38    }39}40import Mockingbird41import XCTest42class ArgumentMatcherTests: XCTestCase {43    func testArgumentMatcher() {44        let mock = mock(ArgumentMatcher.self)45        given(mock.method(argument: any())) ~> "matched"46        XCTAssertEqual(mock.method(argument: argument), "matched")47    }48}49class ArgumentMatcher {50    func method(argument: String) -> String {51    }52}53import Mockingbird54import XCTest55class ArgumentMatcherTests: XCTestCase {56    func testArgumentMatcher() {57        let mock = mock(ArgumentMatcher.self)58        given(mock.method(argument: any())) ~> "matched"59        XCTAssertEqual(mock.method(argument: argument), "matched")60    }61}62class ArgumentMatcher {ArgumentMatcher
Using AI Code Generation
1import Mockingbird2import XCTest3class ArgumentMatcher {4    func test() {5        let matcher = ArgumentMatcher<Bool, Bool>(matcher: { (arg) -> Bool in6        })7        let mock = MockClass()8        given(mock.someMethod(arg: matcher)) ~> true9        XCTAssertTrue(mock.someMethod(arg: true))10    }11}12class MockClass: Mock {13}14extension MockClass {15    func someMethod(arg: Bool) -> Bool {16        return givenFunction(mock: self, functionIdentifier: "someMethod(arg: Bool) -> Bool", input: getOrCreateCallIdentifier("someMethod(arg: Bool) -> Bool#1"), willReturn:  defaultReturnValue(for: "someMethod(arg: Bool) -> Bool"), defaultCallRealImplementation: { (arg) -> Bool in17            return self.callRealImplementation()18        })19    }20}21        let matcher = ArgumentMatcher<Bool, Bool>(matcher: { (arg) -> Bool inArgumentMatcher
Using AI Code Generation
1import XCTest2import Mockingbird3@testable import MockingbirdExample4class ArgumentMatcherTests: XCTestCase {5    override func setUp() {6        mock = mock(SomeProtocol.self)7    }8    func testArgumentMatcher() {9        let argumentMatcher = ArgumentMatcher<String>()10        given(mock.doSomething(with: argumentMatcher.match("Hello"))) ~> "Hello World"11        let result = mock.doSomething(with: "Hello")12        XCTAssertEqual(result, "Hello World")13    }14}15import XCTest16import Mockingbird17@testable import MockingbirdExample18class ArgumentMatcherTests: XCTestCase {19    override func setUp() {20        mock = mock(SomeProtocol.self)21    }22    func testArgumentMatcher() {23        let argumentMatcher = ArgumentMatcher<String>()24        given(mock.doSomething(with: argumentMatcher.match("Hello"))) ~> "Hello World"25        let result = mock.doSomething(with: "Hello")26        XCTAssertEqual(result, "Hello World")27    }28}29import XCTest30import Mockingbird31@testable import MockingbirdExample32class ArgumentMatcherTests: XCTestCase {33    override func setUp() {34        mock = mock(SomeProtocol.self)ArgumentMatcher
Using AI Code Generation
1let mock = MockClass()2let matcher = ArgumentMatcher<Int>()3let matcher2 = ArgumentMatcher<String>()4mock.methodWithArgs(matcher, matcher2)5matcher.compare(with: 1)6matcher2.compare(with: "test")7let mock = MockClass()8let matcher = ArgumentMatcher<Int>()9let matcher2 = ArgumentMatcher<String>()10mock.methodWithArgs(matcher, matcher2)11matcher.compare(with: 1)12matcher2.compare(with: "test")ArgumentMatcher
Using AI Code Generation
1let mock = MockingbirdTests.MockTestProtocol()2let matcher = ArgumentMatcher<String>(matching: { $0 == "test" })3MockingbirdTests.TestProtocolMock.stub(mock, .testString(matcher)) { "test" }4let mock = MockTestProtocol()5let matcher = ArgumentMatcher<String>(matching: { $0 == "test" })6MockTestProtocol.stub(mock, .testString(matcher)) { "test" }7let mock = MockTestProtocol()8let matcher = ArgumentMatcher<String>(matching: { $0 == "test" })9MockTestProtocol.stub(mock, .testString(matcher)) { "test" }10let mock = MockTestProtocol()11let matcher = ArgumentMatcher<String>(matching: { $0 == "test" })12MockTestProtocol.stub(mock, .testString(matcher)) { "test" }13let mock = MockTestProtocol()14let matcher = ArgumentMatcher<String>(matching: { $0 == "test" })15MockTestProtocol.stub(mock, .testString(matcher)) { "test" }16let mock = MockTestProtocol()17let matcher = ArgumentMatcher<String>(matching: { $0 == "test" })18MockTestProtocol.stub(mock, .testString(matcher)) { "test" }19let mock = MockTestProtocol()20let matcher = ArgumentMatcher<String>(matching: { $0 == "test" })21MockTestProtocol.stub(mock, .testString(matcher)) { "test" }ArgumentMatcher
Using AI Code Generation
1let mock = MockSomeClass()2let matcher = ArgumentMatcher<SomeStruct> { $0.x == 1 }3when(mock).someMethod(matcher).then { _ in4}5let result = mock.someMethod(SomeStruct(x: 1))6XCTAssertEqual(result, "a")7let mock = MockSomeClass()8let matcher = ArgumentMatcher<SomeStruct> { $0.x == 1 }9when(mock).someMethod(matcher).then { _ in10}11let result = mock.someMethod(SomeStruct(x: 2))12XCTAssertEqual(result, "a")13let mock = MockSomeClass()14let matcher = ArgumentMatcher<SomeStruct> { $0.x == 1 }15when(mock).someMethod(matcher).then { _ in16}17let result = mock.someMethod(SomeStruct(x: 3))18XCTAssertEqual(result, "a")19let mock = MockSomeClass()20let matcher = ArgumentMatcher<SomeStruct> { $0.x == 1 }21when(mock).someMethod(matcher).then { _ in22}23let result = mock.someMethod(SomeStruct(x: 4))24XCTAssertEqual(result, "a")25let mock = MockSomeClass()26let matcher = ArgumentMatcher<SomeStruct> { $0.x == 1 }27when(mock).someMethod(matcher).then { _ in28}29let result = mock.someMethod(SomeStruct(x: 5))30XCTAssertEqual(result, "a")31let mock = MockSomeClass()32let matcher = ArgumentMatcher<SomeStruct> { $0.x == 1 }33when(mock).someMethod(matcher).then { _ in34}35let result = mock.someMethod(SomeStruct(x: 6))36XCTAssertEqual(result, "a")Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
