uber / mockolo

Efficient Mock Generator for Swift
Apache License 2.0
805 stars 85 forks source link

Incorrect mock generated for composed protocol #207

Closed NumbrSeven closed 1 year ago

NumbrSeven commented 1 year ago

If I define the following protocols in the same file:

/// @mockable
protocol First {
    var first: String { get }
}

/// @mockable
protocol Second {
    var second: String { get }
}

/// @mockable
protocol Both: First & Second { }

Then the resulting generated mocks are:

class FirstMock: First {
    init() { }
    init(first: String = "") {
        self.first = first
    }

    private(set) var firstSetCallCount = 0
    var first: String = "" { didSet { firstSetCallCount += 1 } }
}

class SecondMock: Second {
    init() { }
    init(second: String = "") {
        self.second = second
    }

    private(set) var secondSetCallCount = 0
    var second: String = "" { didSet { secondSetCallCount += 1 } }
}

class BothMock: Both {
    init() { }
    init(first: String = "") {
        self.first = first
    }

    private(set) var firstSetCallCount = 0
    var first: String = "" { didSet { firstSetCallCount += 1 } }
}

Looking at the BothMock class above, it only conforms to First and doesn't include conformance to Second. This then results in a compilation error since BothMock doesn't ultimately conform to the Both protocol.

uhooi commented 1 year ago

Thanks for the report. I would be happy to create a PR for you as I can't fix it right away.

uhooi commented 1 year ago

Close as it appears to be a similar issue to #170.