Typhoon: How to get an instance that matches the protocol for production and the other for tests?

I defined ApplicationAssembly in Typhoon.

So what I want to do is say: “In this class X, you need to enter something that conforms to the Foo protocol. This is RealFoo, this is TestFoo. When I run X in real life, I want it to get RealFoo, but when I running my integration tests, I want him to get TestFoo. "

How can i do this?

+4
source share
1 answer

There are several recommended methods:

Use Patcher Typhoon

Typhoon-patcher , , . :

MiddleAgesAssembly* assembly = [MiddleAgesAssembly assembly];
TyphoonComponentFactory* factory = [TyphoonBlockComponentFactory factoryWithAssembly:assembly];

TyphoonPatcher* patcher = [[TyphoonPatcher alloc] init];
[patcher patchDefinition:[assembly knight] withObject:^id
{
    Knight* mockKnight = mock([Knight class]);
    [given([mockKnight favoriteDamsels]) willReturn:@[
        @"Mary",
        @"Janezzz"
    ]];

    return mockKnight;
}];

[factory attachPostProcessor:patcher];

Knight* knight = [factory componentForKey:@"knight"];


,

, . XML-, , , .

, :

TyphoonComponentFactory* factory = [[TyphoonBlockComponentFactory alloc] initWithAssemblies:@[
    [MiddleAgesAssembly assembly],
    [StarWarsAssembly assembly]
]];

Knight* cavalryMan = [(MiddleAgesAssembly*) factory cavalryMan];
Knight* stormTrooper = [(StarWarsAssembly*) factory stormTrooper];

Typhoon , .


TyphoonConfig

- TyphoonConfig. .


Edit:

Typhoon 2.0. Typhoon 3.0, :

MiddleAgesAssembly *assembly = [[MiddleAgesAssembly new] activate]; 
Knight *knight = [assembly knight];
  • Typhoon 3.0 , , , .
  • , , [assembly.colloaboratingAssembly stormTrooper]
+6

All Articles