Brightify / Cuckoo

Boilerplate-free mocking framework for Swift!
MIT License
1.67k stars 174 forks source link

Protocol Composition Mock #379

Closed SeamusY closed 6 months ago

SeamusY commented 3 years ago

I was writing a piece of code that requires a "Protocol Composition" InteractionServiceHandler & NavigationContentCaller

But it seems that the Cuckoo only support single Protocol, is the feature supported for the composition ?

Information provide from: https://docs.swift.org/swift-book/LanguageGuide/Protocols.html#//apple_ref/doc/uid/TP40014097-CH25-ID282

MatyasKriz commented 3 years ago

Hey, it's possible that this case has been overlooked, can you work around it using generics?

Using your protocols, declaring <T: InteractionServiceHandler & NavigationContentCaller> to see if that works and if not, using the where clause, so func gg<T>() where T: InteractionServiceHandler, T: NavigationContentCaller.

SeamusY commented 3 years ago

I just ended up building a class inheriting the two types class Mocker: InteractionServiceHandler, NavigationContentCaller which doesn't use Cuckoo in my test case.

Ideally we should support composition.

MatyasKriz commented 3 years ago

We should add support for this. Not very common but definitely a good thing to have.

MatyasKriz commented 6 months ago

Fixed in 2.0.3. Thanks for the issue!