-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix wildcard arg matching for Obj-C param types
Dynamic mocking (introduced in 0.18) changed how Objective-C parameter types are faked for wildcard argument matching. To support Objective-C mocking, argument matchers for `NSObjectProtocol` parameters no longer create type facades that go through the resolution context thread, but instead create dynamic `NSProxy` doubles. Dynamic type facades weren’t set up to be used from Swift; this change enables Swift to properly resolve the type facades.
- Loading branch information
1 parent
40134ad
commit 8b03fb6
Showing
7 changed files
with
186 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// ObjCParameters.swift | ||
// MockingbirdTestsHost | ||
// | ||
// Created by typealias on 12/22/21. | ||
// | ||
|
||
import AppKit | ||
import Foundation | ||
|
||
protocol ObjCParameters { | ||
func method(value: NSViewController) -> Bool | ||
func method(optionalValue: NSViewController?) -> Bool | ||
} |
114 changes: 114 additions & 0 deletions
114
Tests/MockingbirdTests/Framework/ObjectiveCParameterTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// | ||
// ObjectiveCParameterTests.swift | ||
// MockingbirdTestsHost | ||
// | ||
// Created by typealias on 12/22/21. | ||
// | ||
|
||
import Mockingbird | ||
@testable import MockingbirdTestsHost | ||
import XCTest | ||
|
||
class ObjectiveCParameterTests: BaseTestCase { | ||
|
||
var parametersMock: ObjCParametersMock! | ||
var parametersInstance: ObjCParameters { parametersMock } | ||
|
||
override func setUpWithError() throws { | ||
self.parametersMock = mock(ObjCParameters.self) | ||
} | ||
|
||
func testExactParameterMatching() { | ||
let instance = NSViewController() | ||
given(parametersMock.method(value: instance)).willReturn(true) | ||
XCTAssertTrue(parametersInstance.method(value: instance)) | ||
verify(parametersMock.method(value: instance)).wasCalled() | ||
} | ||
func testExactParameterMatching_stubbingOperator() { | ||
let instance = NSViewController() | ||
given(parametersMock.method(value: instance)) ~> true | ||
XCTAssertTrue(parametersInstance.method(value: instance)) | ||
verify(parametersMock.method(value: instance)).wasCalled() | ||
} | ||
|
||
func testExactNilParameterMatching() { | ||
given(parametersMock.method(optionalValue: nil)).willReturn(true) | ||
XCTAssertTrue(parametersInstance.method(optionalValue: nil)) | ||
verify(parametersMock.method(optionalValue: nil)).wasCalled() | ||
} | ||
func testExactNilParameterMatching_stubbingOperator() { | ||
given(parametersMock.method(optionalValue: nil)) ~> true | ||
XCTAssertTrue(parametersInstance.method(optionalValue: nil)) | ||
verify(parametersMock.method(optionalValue: nil)).wasCalled() | ||
} | ||
|
||
func testWildcardParameterMatchingAny() { | ||
given(parametersMock.method(value: any())).willReturn(true) | ||
XCTAssertTrue(parametersInstance.method(value: NSViewController())) | ||
verify(parametersMock.method(value: any())).wasCalled() | ||
} | ||
func testWildcardParameterMatchingAny_stubbingOperator() { | ||
given(parametersMock.method(value: any())) ~> true | ||
XCTAssertTrue(parametersInstance.method(value: NSViewController())) | ||
verify(parametersMock.method(value: any())).wasCalled() | ||
} | ||
|
||
func testWildcardOptionalParameterMatchingAny() { | ||
given(parametersMock.method(optionalValue: any())).willReturn(true) | ||
XCTAssertTrue(parametersInstance.method(optionalValue: nil)) | ||
verify(parametersMock.method(optionalValue: any())).wasCalled() | ||
} | ||
func testWildcardOptionalParameterMatchingAny_stubbingOperator() { | ||
given(parametersMock.method(optionalValue: any())) ~> true | ||
XCTAssertTrue(parametersInstance.method(optionalValue: nil)) | ||
verify(parametersMock.method(optionalValue: any())).wasCalled() | ||
} | ||
|
||
func testWildcardParameterMatchingAnyWhere() { | ||
let instance = NSViewController() | ||
given(parametersMock.method(value: any(where: { $0 === instance }))).willReturn(true) | ||
XCTAssertTrue(parametersInstance.method(value: instance)) | ||
verify(parametersMock.method(value: any(where: { $0 === instance }))).wasCalled() | ||
} | ||
func testWildcardParameterMatchingAnyWhere_stubbingOperator() { | ||
let instance = NSViewController() | ||
given(parametersMock.method(value: any(where: { $0 === instance }))) ~> true | ||
XCTAssertTrue(parametersInstance.method(value: instance)) | ||
verify(parametersMock.method(value: any(where: { $0 === instance }))).wasCalled() | ||
} | ||
|
||
func testWildcardParameterMatchingNotNil() { | ||
given(parametersMock.method(value: notNil())).willReturn(true) | ||
XCTAssertTrue(parametersInstance.method(value: NSViewController())) | ||
verify(parametersMock.method(value: notNil())).wasCalled() | ||
} | ||
func testWildcardParameterMatchingNotNil_stubbingOperator() { | ||
given(parametersMock.method(value: notNil())) ~> true | ||
XCTAssertTrue(parametersInstance.method(value: NSViewController())) | ||
verify(parametersMock.method(value: notNil())).wasCalled() | ||
} | ||
|
||
func testWildcardOptionalParameterMatchingNotNil() { | ||
given(parametersMock.method(optionalValue: notNil())).willReturn(true) | ||
XCTAssertTrue(parametersInstance.method(optionalValue: NSViewController())) | ||
verify(parametersMock.method(optionalValue: notNil())).wasCalled() | ||
} | ||
func testWildcardOptionalParameterMatchingNotNil_stubbingOperator() { | ||
given(parametersMock.method(optionalValue: notNil())) ~> true | ||
XCTAssertTrue(parametersInstance.method(optionalValue: NSViewController())) | ||
verify(parametersMock.method(optionalValue: notNil())).wasCalled() | ||
} | ||
|
||
func testWildcardOptionalParameterDoesNotMatchNil() { | ||
shouldFail { | ||
given(self.parametersMock.method(optionalValue: notNil())).willReturn(true) | ||
XCTAssertTrue(self.parametersInstance.method(optionalValue: nil)) | ||
} | ||
} | ||
func testWildcardOptionalParameterDoesNotMatchNil_stubbingOperator() { | ||
shouldFail { | ||
given(self.parametersMock.method(optionalValue: notNil())) ~> true | ||
XCTAssertTrue(self.parametersInstance.method(optionalValue: nil)) | ||
} | ||
} | ||
} |