Skip to content

Commit eb8b220

Browse files
committed
Fixed typo, fixed access modifier for SwityMocky.
1 parent 7749b18 commit eb8b220

File tree

18 files changed

+145
-52
lines changed

18 files changed

+145
-52
lines changed

Mintfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
MakeAWishFoundation/SwiftyMocky-CLI@4.0.0
2+
krzysztofzablocki/Sourcery@1.0.0

Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- Sourcery (0.18.0)
2+
- Sourcery (1.0.0)
33
- SwiftyMocky (4.0.0):
44
- Sourcery (>= 0.18)
55

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Current version has several significant changes. It removes deprecated methods (
6161

6262
**SwiftyPrototype** was also extracted to separate library. There are no more compilation flags, so if you were relying on **SwiftyMocky** with `-DMockyCustom`, you will have to switch to `SwiftyPrototype`.
6363

64-
We consider current version as stable. We are moving toward using the new [Mockfile][link-guides-mockfile] but the previous configuration format would be still supported. Library works with Swift **4.1, 4.2, 5.0, 5.1.2** and Sourcery 0.17-0.18.
64+
We consider current version as stable. We are moving toward using the new [Mockfile][link-guides-mockfile] but the previous configuration format would be still supported. Library works with Swift **4.1, 4.2, 5.0, 5.1.2** and Sourcery 1.0.x.
6565

6666
While it is technically possible to integrate SwiftyMocky on Linux targets, there is no Mock generation feature there yet. You can use SwiftyMokcy runtime via SwiftPM though, as long as your are fine with generating mocks on mac machine.
6767

Sources/SwiftyMocky/Mock.swifttemplate

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import XCTest
5454
<%_
5555
class Current {
5656
static var selfType: String = "Self"
57+
static var accessModifier: String = "open"
5758
}
5859
// Collision management
5960
func areThereCollisions(between methods: [MethodWrapper]) -> Bool {
@@ -514,7 +515,7 @@ class MethodWrapper {
514515
guard !method.isStatic else { return "public static" }
515516
guard !returnsGenericConstrainedToSelf else { return "public" }
516517
guard !parametersContainsSelf else { return "public" }
517-
return "open"
518+
return Current.accessModifier
518519
}
519520

520521
private var registrationName: String {
@@ -1405,7 +1406,8 @@ class VariableWrapper {
14051406
var casesCount: Int { return readonly ? 1 : 2 }
14061407

14071408
var accessModifier: String {
1408-
guard variable.type?.accessLevel != "internal" else { return "" }
1409+
// TODO: Fix access levels for SwiftyPrototype
1410+
// guard variable.type?.accessLevel != "internal" else { return "" }
14091411
return "public "
14101412
}
14111413
var attributes: String {
@@ -1520,6 +1522,7 @@ _%>
15201522
let inlineMockable = protocolToDecorate != nil
15211523
guard let aProtocol = autoMockable ? type : protocolToDecorate else { continue }
15221524
mockedCount += 1
1525+
15231526
let associatedTypes: [String]? = Helpers.extractAssociatedTypes(from: aProtocol)
15241527
let attributes: String = Helpers.extractAttributes(from: type.attributes)
15251528
let typeAliases: [String] = Helpers.extractTypealiases(from: aProtocol)
@@ -1533,6 +1536,7 @@ _%>
15331536
let allMethods = uniques(methods: aProtocol.allMethods.filter({ !$0.isStatic }))
15341537
let selfConstrained = allMethods.map(wrapMethod).contains(where: { $0.returnsGenericConstrainedToSelf || $0.parametersContainsSelf })
15351538
let accessModifier: String = selfConstrained ? "public final" : "open"
1539+
Current.accessModifier = accessModifier // TODO: Temporary workaround for access modifiers
15361540
let inheritFromNSObject = type.annotations["ObjcProtocol"] != nil || attributes.contains("@objc")
15371541
let allMethodsForMethodType = uniquesWithoutGenericConstraints(methods: aProtocol.allMethods.filter({ !$0.isStatic }))
15381542
let allStaticMethods = uniques(methods: aProtocol.allMethods.filter({ $0.isStatic }))

Sources/SwiftyPrototype/Prototype.swifttemplate

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import SwiftyPrototype
5353
<%_
5454
class Current {
5555
static var selfType: String = "Self"
56+
static var accessModifier: String = "open"
5657
}
5758
// Collision management
5859
func areThereCollisions(between methods: [MethodWrapper]) -> Bool {
@@ -513,7 +514,7 @@ class MethodWrapper {
513514
guard !method.isStatic else { return "public static" }
514515
guard !returnsGenericConstrainedToSelf else { return "public" }
515516
guard !parametersContainsSelf else { return "public" }
516-
return "open"
517+
return Current.accessModifier
517518
}
518519

519520
private var registrationName: String {
@@ -1404,7 +1405,8 @@ class VariableWrapper {
14041405
var casesCount: Int { return readonly ? 1 : 2 }
14051406

14061407
var accessModifier: String {
1407-
guard variable.type?.accessLevel != "internal" else { return "" }
1408+
// TODO: Fix access levels for SwiftyPrototype
1409+
// guard variable.type?.accessLevel != "internal" else { return "" }
14081410
return "public "
14091411
}
14101412
var attributes: String {
@@ -1519,6 +1521,7 @@ _%>
15191521
let inlineMockable = protocolToDecorate != nil
15201522
guard let aProtocol = autoMockable ? type : protocolToDecorate else { continue }
15211523
mockedCount += 1
1524+
15221525
let associatedTypes: [String]? = Helpers.extractAssociatedTypes(from: aProtocol)
15231526
let attributes: String = Helpers.extractAttributes(from: type.attributes)
15241527
let typeAliases: [String] = Helpers.extractTypealiases(from: aProtocol)
@@ -1532,6 +1535,7 @@ _%>
15321535
let allMethods = uniques(methods: aProtocol.allMethods.filter({ !$0.isStatic }))
15331536
let selfConstrained = allMethods.map(wrapMethod).contains(where: { $0.returnsGenericConstrainedToSelf || $0.parametersContainsSelf })
15341537
let accessModifier: String = selfConstrained ? "public final" : "open"
1538+
Current.accessModifier = accessModifier // TODO: Temporary workaround for access modifiers
15351539
let inheritFromNSObject = type.annotations["ObjcProtocol"] != nil || attributes.contains("@objc")
15361540
let allMethodsForMethodType = uniquesWithoutGenericConstraints(methods: aProtocol.allMethods.filter({ !$0.isStatic }))
15371541
let allStaticMethods = uniques(methods: aProtocol.allMethods.filter({ $0.isStatic }))

SwiftyMocky-Example/Shared/Example 8/ProtocolWithProperties.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
import Foundation
1010

1111
//sourcery: AutoMockable
12-
protocol ProtocolWithPropoerties {
12+
protocol ProtocolWithProperties {
1313
var name: String { get set }
1414
static var name: String { get set }
1515
var email: String? { get set }
1616
static var defaultEmail: String? { get set }
1717

18+
var internalProperty: InternalType { get set }
19+
1820
// Methods cannot have labels called "set"
1921
func name(_ newValue: String)
2022
func email(_ newValue: String!)
2123
static func defaultEmail(_ newValue: String!)
2224
}
25+
26+
internal struct InternalType { }

SwiftyMocky-Tests/Shared/Example 8/ProtocolWithPropertiesTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import SwiftyMocky
1919
class ProtocolsWithPropertiesTests: XCTestCase {
2020

2121
func test_properties_getters() {
22-
let mock = ProtocolWithPropoertiesMock()
22+
let mock = ProtocolWithPropertiesMock()
2323

2424
Verify(mock, .never, .name)
2525
Verify(mock, .never, .name(set: .any))
@@ -36,7 +36,7 @@ class ProtocolsWithPropertiesTests: XCTestCase {
3636
}
3737

3838
func test_properties_setters() {
39-
let mock = ProtocolWithPropoertiesMock()
39+
let mock = ProtocolWithPropertiesMock()
4040

4141
Verify(mock, .never, .name)
4242
Verify(mock, .never, .name(set: .any))
@@ -52,7 +52,7 @@ class ProtocolsWithPropertiesTests: XCTestCase {
5252
}
5353

5454
func test_static_properties_getters() {
55-
let mock = ProtocolWithPropoertiesMock.self
55+
let mock = ProtocolWithPropertiesMock.self
5656
mock.resetMock()
5757

5858
Verify(mock, .never, .name)
@@ -70,7 +70,7 @@ class ProtocolsWithPropertiesTests: XCTestCase {
7070
}
7171

7272
func test_static_properties_setters() {
73-
let mock = ProtocolWithPropoertiesMock.self
73+
let mock = ProtocolWithPropertiesMock.self
7474
mock.resetMock()
7575

7676
Verify(mock, .never, .name)

SwiftyMocky-Tests/Shared/Other/VerifyMessagesTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class VerifyMessagesTests: XCTestCase {
5757
}
5858

5959
func testMessagesForProperties() {
60-
let mock = ProtocolWithPropoertiesMock()
60+
let mock = ProtocolWithPropertiesMock()
6161

6262
Given(mock, .email(getter: "john@mail.com"))
6363
Given(mock, .name(getter: "john"))

SwiftyMocky-Tests/iOS/Mocks/Mock.generated.swift

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3580,7 +3580,7 @@ public final class FailsWithReturnedTypeBeingGenericOfSelfMock: FailsWithReturne
35803580
return _wrapped()
35813581
}
35823582

3583-
open func test(value: FailsWithReturnedTypeBeingGenericOfSelfMock) -> Bool {
3583+
public final func test(value: FailsWithReturnedTypeBeingGenericOfSelfMock) -> Bool {
35843584
addInvocation(.m_test__value_value(Parameter<FailsWithReturnedTypeBeingGenericOfSelfMock>.value(`value`)))
35853585
let perform = methodPerformValue(.m_test__value_value(Parameter<FailsWithReturnedTypeBeingGenericOfSelfMock>.value(`value`))) as? (FailsWithReturnedTypeBeingGenericOfSelfMock) -> Void
35863586
perform?(`value`)
@@ -8524,9 +8524,9 @@ open class ProtocolWithMethodsWithGenericReturnTypeThatThrowsMock: ProtocolWithM
85248524
}
85258525
}
85268526

8527-
// MARK: - ProtocolWithPropoerties
8527+
// MARK: - ProtocolWithProperties
85288528

8529-
open class ProtocolWithPropoertiesMock: ProtocolWithPropoerties, Mock, StaticMock {
8529+
open class ProtocolWithPropertiesMock: ProtocolWithProperties, Mock, StaticMock {
85308530
public init(sequencing sequencingPolicy: SequencingPolicy = .lastWrittenResolvedFirst, stubbing stubbingPolicy: StubbingPolicy = .wrap, file: StaticString = #file, line: UInt = #line) {
85318531
SwiftyMockyTestObserver.setup()
85328532
self.sequencingPolicy = sequencingPolicy
@@ -8579,27 +8579,33 @@ open class ProtocolWithPropoertiesMock: ProtocolWithPropoerties, Mock, StaticMoc
85798579
}
85808580

85818581
public var name: String {
8582-
get { invocations.append(.p_name_get); return __p_name ?? givenGetterValue(.p_name_get, "ProtocolWithPropoertiesMock - stub value for name was not defined") }
8582+
get { invocations.append(.p_name_get); return __p_name ?? givenGetterValue(.p_name_get, "ProtocolWithPropertiesMock - stub value for name was not defined") }
85838583
set { invocations.append(.p_name_set(.value(newValue))); __p_name = newValue }
85848584
}
85858585
private var __p_name: (String)?
85868586

85878587
public var email: String? {
8588-
get { invocations.append(.p_email_get); return __p_email ?? optionalGivenGetterValue(.p_email_get, "ProtocolWithPropoertiesMock - stub value for email was not defined") }
8588+
get { invocations.append(.p_email_get); return __p_email ?? optionalGivenGetterValue(.p_email_get, "ProtocolWithPropertiesMock - stub value for email was not defined") }
85898589
set { invocations.append(.p_email_set(.value(newValue))); __p_email = newValue }
85908590
}
85918591
private var __p_email: (String)?
85928592

8593+
public var internalProperty: InternalType {
8594+
get { invocations.append(.p_internalProperty_get); return __p_internalProperty ?? givenGetterValue(.p_internalProperty_get, "ProtocolWithPropertiesMock - stub value for internalProperty was not defined") }
8595+
set { invocations.append(.p_internalProperty_set(.value(newValue))); __p_internalProperty = newValue }
8596+
}
8597+
private var __p_internalProperty: (InternalType)?
8598+
85938599

85948600
public static var name: String {
8595-
get { ProtocolWithPropoertiesMock.invocations.append(.p_name_get); return ProtocolWithPropoertiesMock.__p_name ?? givenGetterValue(.p_name_get, "ProtocolWithPropoertiesMock - stub value for name was not defined") }
8596-
set { ProtocolWithPropoertiesMock.invocations.append(.p_name_set(.value(newValue))); ProtocolWithPropoertiesMock.__p_name = newValue }
8601+
get { ProtocolWithPropertiesMock.invocations.append(.p_name_get); return ProtocolWithPropertiesMock.__p_name ?? givenGetterValue(.p_name_get, "ProtocolWithPropertiesMock - stub value for name was not defined") }
8602+
set { ProtocolWithPropertiesMock.invocations.append(.p_name_set(.value(newValue))); ProtocolWithPropertiesMock.__p_name = newValue }
85978603
}
85988604
private static var __p_name: (String)?
85998605

86008606
public static var defaultEmail: String? {
8601-
get { ProtocolWithPropoertiesMock.invocations.append(.p_defaultEmail_get); return ProtocolWithPropoertiesMock.__p_defaultEmail ?? optionalGivenGetterValue(.p_defaultEmail_get, "ProtocolWithPropoertiesMock - stub value for defaultEmail was not defined") }
8602-
set { ProtocolWithPropoertiesMock.invocations.append(.p_defaultEmail_set(.value(newValue))); ProtocolWithPropoertiesMock.__p_defaultEmail = newValue }
8607+
get { ProtocolWithPropertiesMock.invocations.append(.p_defaultEmail_get); return ProtocolWithPropertiesMock.__p_defaultEmail ?? optionalGivenGetterValue(.p_defaultEmail_get, "ProtocolWithPropertiesMock - stub value for defaultEmail was not defined") }
8608+
set { ProtocolWithPropertiesMock.invocations.append(.p_defaultEmail_set(.value(newValue))); ProtocolWithPropertiesMock.__p_defaultEmail = newValue }
86038609
}
86048610
private static var __p_defaultEmail: (String)?
86058611

@@ -8710,6 +8716,8 @@ open class ProtocolWithPropoertiesMock: ProtocolWithPropoerties, Mock, StaticMoc
87108716
case p_name_set(Parameter<String>)
87118717
case p_email_get
87128718
case p_email_set(Parameter<String?>)
8719+
case p_internalProperty_get
8720+
case p_internalProperty_set(Parameter<InternalType>)
87138721

87148722
static func compareParameters(lhs: MethodType, rhs: MethodType, matcher: Matcher) -> Matcher.ComparisonResult {
87158723
switch (lhs, rhs) {
@@ -8726,6 +8734,8 @@ open class ProtocolWithPropoertiesMock: ProtocolWithPropoerties, Mock, StaticMoc
87268734
case (.p_name_set(let left),.p_name_set(let right)): return Matcher.ComparisonResult([Matcher.ParameterComparisonResult(Parameter<String>.compare(lhs: left, rhs: right, with: matcher), left, right, "newValue")])
87278735
case (.p_email_get,.p_email_get): return Matcher.ComparisonResult.match
87288736
case (.p_email_set(let left),.p_email_set(let right)): return Matcher.ComparisonResult([Matcher.ParameterComparisonResult(Parameter<String?>.compare(lhs: left, rhs: right, with: matcher), left, right, "newValue")])
8737+
case (.p_internalProperty_get,.p_internalProperty_get): return Matcher.ComparisonResult.match
8738+
case (.p_internalProperty_set(let left),.p_internalProperty_set(let right)): return Matcher.ComparisonResult([Matcher.ParameterComparisonResult(Parameter<InternalType>.compare(lhs: left, rhs: right, with: matcher), left, right, "newValue")])
87298739
default: return .none
87308740
}
87318741
}
@@ -8738,6 +8748,8 @@ open class ProtocolWithPropoertiesMock: ProtocolWithPropoerties, Mock, StaticMoc
87388748
case .p_name_set(let newValue): return newValue.intValue
87398749
case .p_email_get: return 0
87408750
case .p_email_set(let newValue): return newValue.intValue
8751+
case .p_internalProperty_get: return 0
8752+
case .p_internalProperty_set(let newValue): return newValue.intValue
87418753
}
87428754
}
87438755
func assertionName() -> String {
@@ -8748,6 +8760,8 @@ open class ProtocolWithPropoertiesMock: ProtocolWithPropoerties, Mock, StaticMoc
87488760
case .p_name_set: return "[set] .name"
87498761
case .p_email_get: return "[get] .email"
87508762
case .p_email_set: return "[set] .email"
8763+
case .p_internalProperty_get: return "[get] .internalProperty"
8764+
case .p_internalProperty_set: return "[set] .internalProperty"
87518765
}
87528766
}
87538767
}
@@ -8766,6 +8780,9 @@ open class ProtocolWithPropoertiesMock: ProtocolWithPropoerties, Mock, StaticMoc
87668780
public static func email(getter defaultValue: String?...) -> PropertyStub {
87678781
return Given(method: .p_email_get, products: defaultValue.map({ StubProduct.return($0 as Any) }))
87688782
}
8783+
public static func internalProperty(getter defaultValue: InternalType...) -> PropertyStub {
8784+
return Given(method: .p_internalProperty_get, products: defaultValue.map({ StubProduct.return($0 as Any) }))
8785+
}
87698786

87708787
}
87718788

@@ -8778,6 +8795,8 @@ open class ProtocolWithPropoertiesMock: ProtocolWithPropoerties, Mock, StaticMoc
87788795
public static func name(set newValue: Parameter<String>) -> Verify { return Verify(method: .p_name_set(newValue)) }
87798796
public static var email: Verify { return Verify(method: .p_email_get) }
87808797
public static func email(set newValue: Parameter<String?>) -> Verify { return Verify(method: .p_email_set(newValue)) }
8798+
public static var internalProperty: Verify { return Verify(method: .p_internalProperty_get) }
8799+
public static func internalProperty(set newValue: Parameter<InternalType>) -> Verify { return Verify(method: .p_internalProperty_set(newValue)) }
87818800
}
87828801

87838802
public struct Perform {

0 commit comments

Comments
 (0)