Skip to content

Commit

Permalink
Fixed bug that cause "test_definition_with_circular_dependency" test …
Browse files Browse the repository at this point in the history
…to fail
  • Loading branch information
alexgarbarev committed Sep 4, 2014
1 parent a595be4 commit 36f4524
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 7 deletions.
1 change: 1 addition & 0 deletions Source/Definition/Injections/TyphoonAbstractInjection.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef NS_ENUM(NSInteger, TyphoonInjectionType) {
/* TyphoonInjectionTypeParameter properties */
@property(nonatomic, readonly) NSUInteger parameterIndex;

- (BOOL)isEqualToCustom:(id)injection;

@end

Expand Down
8 changes: 7 additions & 1 deletion Source/Definition/Injections/TyphoonAbstractInjection.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ - (BOOL)isEqual:(id)other
return NO;
}

return [self isEqualToBase:other];
return [self isEqualToBase:other] && [self isEqualToCustom:other];
}

- (BOOL)isEqualToBase:(TyphoonAbstractInjection *)base
Expand Down Expand Up @@ -89,6 +89,12 @@ - (BOOL)isEqualToBase:(TyphoonAbstractInjection *)base

#pragma mark - Methods to override

- (BOOL)isEqualToCustom:(id)injection
{
[NSException raise:NSInternalInconsistencyException format:@"%@ is abstract", NSStringFromSelector(_cmd)];
return NO;
}

- (id)copyWithZone:(NSZone *)zone
{
[NSException raise:NSInternalInconsistencyException format:@"%@ is abstract", NSStringFromSelector(_cmd)];
Expand Down
5 changes: 5 additions & 0 deletions Source/Definition/Injections/TyphoonInjectionByCollection.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ - (id)copyWithZone:(NSZone *)zone
return copied;
}

- (BOOL)isEqualToCustom:(TyphoonInjectionByCollection *)injection
{
return [self.injections isEqualToArray:injection.injections] && self.requiredClass == injection.requiredClass;
}

- (void)valueToInjectWithContext:(TyphoonInjectionContext *)context completion:(TyphoonInjectionValueBlock)result
{
Class collectionClass = [self collectionClassForContext:context];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ - (id)copyWithZone:(NSZone *)zone
return copied;
}

- (BOOL)isEqualToCustom:(TyphoonInjectionByComponentFactory *)injection
{
return YES;
}

@end
5 changes: 5 additions & 0 deletions Source/Definition/Injections/TyphoonInjectionByConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ - (id)copyWithZone:(NSZone *)zone
return copied;
}

- (BOOL)isEqualToCustom:(TyphoonInjectionByConfig *)injection
{
return [self.configKey isEqualToString:injection.configKey];
}

- (void)valueToInjectWithContext:(TyphoonInjectionContext *)context completion:(TyphoonInjectionValueBlock)result
{
if (!self.configuredInjection) {
Expand Down
5 changes: 5 additions & 0 deletions Source/Definition/Injections/TyphoonInjectionByDictionary.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ - (id)copyWithZone:(NSZone *)zone
return copied;
}

- (BOOL)isEqualToCustom:(TyphoonInjectionByDictionary *)injection
{
return [self.injections isEqualToDictionary:injection.injections] && self.requiredClass == injection.requiredClass;
}

- (void)valueToInjectWithContext:(TyphoonInjectionContext *)context completion:(TyphoonInjectionValueBlock)result
{
Class dictionaryClass = [self dictionaryClassForContext:context];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ - (id)copyWithZone:(NSZone *)zone
return copied;
}

- (BOOL)isEqualToCustom:(TyphoonInjectionByFactoryReference *)injection
{
return [super isEqualToCustom:injection] && [self.keyPath isEqualToString:injection.keyPath];
}

- (id)resolveReferenceWithContext:(TyphoonInjectionContext *)context
{
id referenceInstance = [super resolveReferenceWithContext:context];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ - (id)copyWithZone:(NSZone *)zone
return copied;
}

- (BOOL)isEqualToCustom:(TyphoonInjectionByObjectFromString *)injection
{
return [self.textValue isEqualToString:injection.textValue];
}

- (void)valueToInjectWithContext:(TyphoonInjectionContext *)context completion:(TyphoonInjectionValueBlock)result
{
TyphoonTypeDescriptor *type = context.destinationType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ - (id)copyWithZone:(NSZone *)zone
return copied;
}

- (BOOL)isEqualToCustom:(TyphoonInjectionByObjectInstance *)injection
{
return [self.objectInstance isEqualTo:injection.objectInstance];
}

- (void)valueToInjectWithContext:(TyphoonInjectionContext *)context completion:(TyphoonInjectionValueBlock)result
{
result(_objectInstance);
Expand Down
5 changes: 5 additions & 0 deletions Source/Definition/Injections/TyphoonInjectionByReference.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ - (id)copyWithZone:(NSZone *)zone
return copied;
}

- (BOOL)isEqualToCustom:(TyphoonInjectionByReference *)injection
{
return [self.reference isEqualTo:injection.reference] && [self.referenceArguments isEqualTo:injection.referenceArguments];
}

- (void)valueToInjectWithContext:(TyphoonInjectionContext *)context completion:(TyphoonInjectionValueBlock)result
{
if (context.raiseExceptionIfCircular) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@ - (id)copyWithZone:(NSZone *)zone
return copied;
}

- (BOOL)isEqualToCustom:(TyphoonInjectionByRuntimeArgument *)injection
{
return self.runtimeArgumentIndex == injection.runtimeArgumentIndex;
}

@end

6 changes: 5 additions & 1 deletion Source/Definition/Injections/TyphoonInjectionByType.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ - (id)copyWithZone:(NSZone *)zone
return copied;
}

- (BOOL)isEqualToCustom:(id)injection
{
return YES;
}

- (void)valueToInjectWithContext:(TyphoonInjectionContext *)context completion:(TyphoonInjectionValueBlock)result
{
id classOrProtocol = context.destinationType.classOrProtocol;
Expand All @@ -36,7 +41,6 @@ - (void)valueToInjectWithContext:(TyphoonInjectionContext *)context completion:(
}
}


TyphoonDefinition *definition = [context.factory definitionForType:classOrProtocol];

[context.factory resolveCircularDependency:definition.key args:context.args resolvedBlock:^(BOOL isCircular) {
Expand Down
10 changes: 5 additions & 5 deletions Typhoon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -998,9 +998,11 @@
6B076EB91936F63A0083714E /* Injections */ = {
isa = PBXGroup;
children = (
6B076EBC1936F63A0083714E /* TyphoonInjection.h */,
6B076ED51936F63A0083714E /* TyphoonPropertyInjection.h */,
6B076ED41936F63A0083714E /* TyphoonParameterInjection.h */,
6B076EBA1936F63A0083714E /* TyphoonAbstractInjection.h */,
6B076EBB1936F63A0083714E /* TyphoonAbstractInjection.m */,
6B076EBC1936F63A0083714E /* TyphoonInjection.h */,
6B076EBD1936F63A0083714E /* TyphoonInjectionByCollection.h */,
6B076EBE1936F63A0083714E /* TyphoonInjectionByCollection.m */,
6B076EBF1936F63A0083714E /* TyphoonInjectionByComponentFactory.h */,
Expand All @@ -1023,12 +1025,10 @@
6B076ED01936F63A0083714E /* TyphoonInjectionByType.m */,
6B076ED11936F63A0083714E /* TyphoonInjectionContext.h */,
6B076ED21936F63A0083714E /* TyphoonInjectionContext.m */,
C949766E39C445A43A7517B8 /* TyphoonInjectionByCurrentRuntimeArguments.h */,
C94972BE857448DEBA12C1CE /* TyphoonInjectionByCurrentRuntimeArguments.m */,
6B076ED31936F63A0083714E /* TyphoonInjections.h */,
6B076ED41936F63A0083714E /* TyphoonParameterInjection.h */,
6B076ED51936F63A0083714E /* TyphoonPropertyInjection.h */,
2DBA1FC6F594C49C7D8261A6 /* TyphoonInjections.m */,
C94972BE857448DEBA12C1CE /* TyphoonInjectionByCurrentRuntimeArguments.m */,
C949766E39C445A43A7517B8 /* TyphoonInjectionByCurrentRuntimeArguments.h */,
);
path = Injections;
sourceTree = "<group>";
Expand Down

0 comments on commit 36f4524

Please sign in to comment.