-
Notifications
You must be signed in to change notification settings - Fork 608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiprotocols mocking and class+protocols combination mocking #309
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,32 +44,79 @@ + (void)initialize | |
|
||
#pragma mark Factory methods | ||
|
||
+ (id)mockForClass:(Class)aClass | ||
+ (id)mockForClass:(Class)aClass protocols:(Protocol *)aProtocol, ... | ||
{ | ||
return [[[OCClassMockObject alloc] initWithClass:aClass] autorelease]; | ||
va_list protocolsList; | ||
va_start(protocolsList, aProtocol); | ||
|
||
NSArray *protocols = [self _arrayOfProtocol:aProtocol otherProtocols:protocolsList]; | ||
|
||
va_end(protocolsList); | ||
|
||
return [[[OCClassMockObject alloc] initWithClass:aClass protocols:protocols] autorelease]; | ||
} | ||
|
||
+ (id)mockForProtocol:(Protocol *)aProtocol | ||
+ (id)mockForProtocols:(Protocol *)aProtocol, ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above. This change is way too invasive. At an absolute minimum we'd have to keep the original |
||
{ | ||
return [[[OCProtocolMockObject alloc] initWithProtocol:aProtocol] autorelease]; | ||
va_list protocolsList; | ||
va_start(protocolsList, aProtocol); | ||
|
||
NSArray *protocols = [self _arrayOfProtocol:aProtocol otherProtocols:protocolsList]; | ||
|
||
va_end(protocolsList); | ||
|
||
return [[[OCProtocolMockObject alloc] initWithProtocols:protocols] autorelease]; | ||
} | ||
|
||
+ (id)partialMockForObject:(NSObject *)anObject | ||
{ | ||
return [[[OCPartialMockObject alloc] initWithObject:anObject] autorelease]; | ||
} | ||
|
||
|
||
+ (id)niceMockForClass:(Class)aClass | ||
+ (id)niceMockForClass:(Class)aClass protocols:(Protocol *)aProtocol, ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above. |
||
{ | ||
return [self _makeNice:[self mockForClass:aClass]]; | ||
va_list protocolsList; | ||
va_start(protocolsList, aProtocol); | ||
|
||
NSArray *protocols = [self _arrayOfProtocol:aProtocol otherProtocols:protocolsList]; | ||
|
||
va_end(protocolsList); | ||
|
||
id mock = [[[OCClassMockObject alloc] initWithClass:aClass protocols:protocols] autorelease]; | ||
return [self _makeNice:mock]; | ||
} | ||
|
||
+ (id)niceMockForProtocol:(Protocol *)aProtocol | ||
+ (id)niceMockForProtocols:(Protocol *)aProtocol, ... | ||
{ | ||
return [self _makeNice:[self mockForProtocol:aProtocol]]; | ||
va_list protocolsList; | ||
va_start(protocolsList, aProtocol); | ||
|
||
NSArray *protocols = [self _arrayOfProtocol:aProtocol otherProtocols:protocolsList]; | ||
|
||
va_end(protocolsList); | ||
|
||
id mock = [[[OCProtocolMockObject alloc] initWithProtocols:protocols] autorelease]; | ||
|
||
return [self _makeNice:mock]; | ||
} | ||
|
||
+ (NSArray *)_arrayOfProtocol:(Protocol *)aProtocol otherProtocols:(va_list)protocolsList | ||
{ | ||
if (!aProtocol) | ||
{ | ||
return nil; | ||
} | ||
|
||
NSMutableArray *protocols = [NSMutableArray new]; | ||
|
||
while(aProtocol) | ||
{ | ||
[protocols addObject:aProtocol]; | ||
aProtocol = va_arg(protocolsList, typeof(aProtocol)); | ||
} | ||
|
||
return [protocols autorelease]; | ||
} | ||
|
||
+ (id)_makeNice:(OCMockObject *)mock | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is way too invasive. At an absolute minimum we'd have to keep the original
initWithClass:
method, and make it forward to the proposed newinitWithClass:protocols:
method. That way, the number of changes in the PR would be greatly reduced.