uber / mockolo

Efficient Mock Generator for Swift
Apache License 2.0
813 stars 86 forks source link

Cont. on #146 Fail to generate mock with protocol inheritance #167

Closed keithcml closed 1 year ago

keithcml commented 2 years ago

146

@EspressoCup Sorry for disturbing you again.

EspressoCup commented 2 years ago

You'll need to pass a --mockfiles input option with paths to files that contain mocks of protocols that you inherit (which live in different modules). Please see test examples at https://github.com/uber/mockolo/blob/master/Tests/TestOverloads/OverloadTests.swift - testOverloadInParent, testOverloadInParentAndChild, or any tests that have the mockContent: parameter; this is used to pass in the file content for the --mockfiles option, and you should be able to see how it's used by stepping through the implementation with a debugger.

keithcml commented 2 years ago

thanks @EspressoCup . let me have a try first

RoryKelly commented 2 years ago

For anyone else looking for a solution you have to mock the parent in a separate call to mockolo, then pass the resulting mock into its subclass/implementor via --mockfiles

/// @mockable
protocol ProtocolB {
  func thisIsB()
}

/// @mockable
protocol ProtocolA: ProtocolB {

}
mockolo -srcs "ProtocolB.swift"  -d "MockProtocolB.swift" 
mockolo -srcs "ProtocolA.swift" --mockfiles "MockProtocolB.swift"  -d "Mock ProtocolB.swift"
keithcml commented 2 years ago

It works !

uhooi commented 1 year ago

It looks fine, so I will close it.