Search code examples
iosobjective-ctyphoon

Typhoon patcher example causes type error — was this intentional?


In the Typhoon documentation, it shows you how to patch out a component for the purposes of executing integration tests.

The example goes:

TyphoonPatcher* patcher = [[TyphoonPatcher alloc] init];
[patcher patchDefinition:[assembly knight] withObject:...];

The line [patcher patchDefinition:[assembly knight] withObject:...]; doesn't type check for me:

Parameter type mismatch: Interface 'Knight' is not a successor of 'TyphoonDefinition'

This makes a lot of sense, since knight is defined like so:

@interface MiddleAgesAssembly : TyphoonAssembly
- (Knight*)knight;   // Returns a TyphoonDefinition, actually.
... 
@end

... the return type definitely isn't TyphoonDefinition.

I'm not sure whether this is because

  1. it's the intentional design of Typhoon, and the documentation is outdated
  2. I'm doing something wrong.

p.s. who made up these examples... they're terrible!


Solution

  • This is a oversight in Typhoon's API. In fact that method for patching will be deprecated in favor of:

    [patcher patchDefinitionWithSelector:@selector(myController) withObject:^id{
       return myFakeController;
    }];
    

    The reason for deprecating that method is outlined in this answer. We'll fix the type issue, but the method will be deprecated all the same.

    As for the examples: They were borrowed from seminal 12th century text on dependency injection written by a monk named Adlard Humfridus. Its quite a poignant and touching work - I cried when the Knight had his sword patched-out with a chainsaw, and was able to rescue the damsel after all. Unfortunately some of the finer subtleties were lost in translation from the original Latin.