Cuckoo icon indicating copy to clipboard operation
Cuckoo copied to clipboard

Protocol Composition Mock

Open SeamusY opened this issue 3 years ago • 3 comments

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

SeamusY avatar Feb 01 '21 06:02 SeamusY

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.

MatyasKriz avatar Feb 02 '21 17:02 MatyasKriz

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.

SeamusY avatar Feb 03 '21 00:02 SeamusY

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

MatyasKriz avatar Jul 22 '21 10:07 MatyasKriz