forked from twobitlabs/AnalyticsKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalyticsKitUnitTestProvider.m
108 lines (82 loc) · 3.12 KB
/
AnalyticsKitUnitTestProvider.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// AnalyticsKitUnitTestProvider.m
// TeamStream
//
// Created by Todd Huss on 11/14/12.
// Copyright (c) 2012 Two Bit Labs. All rights reserved.
//
#import "AnalyticsKitUnitTestProvider.h"
@implementation AnalyticsKitUnitTestProvider
+ (AnalyticsKitUnitTestProvider *)setUp {
AnalyticsKitUnitTestProvider *provider = [[AnalyticsKitUnitTestProvider alloc] init];
provider.events = [NSMutableArray arrayWithCapacity:20];
[AnalyticsKit initializeLoggers:@[provider]];
return provider;
}
+ (AnalyticsKitUnitTestProvider *)unitTestProvider {
AnalyticsKitUnitTestProvider *unitProvider = nil;
NSArray *loggers = [AnalyticsKit loggers];
for (AnalyticsKitUnitTestProvider *provider in loggers) {
if ([provider isKindOfClass:[AnalyticsKitUnitTestProvider class]]) unitProvider = provider;
}
return unitProvider;
}
+ (void)clearEvents {
// Remove the events stored in the unit test provider
[[self unitTestProvider] clearEvents];
}
+ (void)tearDown {
[self clearEvents];
// Wipe out any loggers
[AnalyticsKit initialize];
}
- (void)clearEvents {
[self setEvents:[NSMutableArray arrayWithCapacity:20]];
}
- (BOOL)hasEventLoggedWithName:(NSString *)eventName {
return [self firstEventLoggedWithName:eventName] != nil;
}
- (AnalyticsKitEvent *)firstEventLoggedWithName:(NSString *)eventName {
AnalyticsKitEvent *event = nil;
NSArray *matchingEvents = [self eventsLoggedWithName:eventName];
if ([matchingEvents count] > 0) event = matchingEvents[0];
return event;
}
- (NSArray *)eventsLoggedWithName:(NSString *)eventName {
NSMutableArray *matchingEvents = [NSMutableArray arrayWithCapacity:5];
for (AnalyticsKitEvent *event in self.events) {
if ([eventName isEqualToString:event.name]) [matchingEvents addObject:event];
}
return matchingEvents;
}
#pragma mark -
#pragma mark Lifecycle
-(void)applicationWillEnterForeground{}
-(void)applicationDidEnterBackground{}
-(void)applicationWillTerminate{}
-(void)uncaughtException:(NSException *)exception{}
#pragma mark -
#pragma mark Event Logging
-(void)logScreen:(NSString *)screenName{
NSString *event = [@"Screen - " stringByAppendingString:screenName];
[self logEvent:event withProperties:nil];
}
-(void)logEvent:(NSString *)event {
[self logEvent:event withProperties:nil];
}
-(void)logEvent:(NSString *)event withProperty:(NSString *)key andValue:(NSString *)value {
[self logEvent:event withProperties:@{key:value}];
}
-(void)logEvent:(NSString *)event withProperties:(NSDictionary *)dict {
[self.events addObject:[[AnalyticsKitEvent alloc] initEvent:event withProperties:dict]];
}
-(void)logEvent:(NSString *)event timed:(BOOL)timed{
[self logEvent:event withProperties:nil];
}
-(void)logEvent:(NSString *)event withProperties:(NSDictionary *)dict timed:(BOOL)timed{
[self logEvent:event withProperties:dict];
}
-(void)endTimedEvent:(NSString *)event withProperties:(NSDictionary *)dict{}
-(void)logError:(NSString *)name message:(NSString *)message exception:(NSException *)exception{}
-(void)logError:(NSString *)name message:(NSString *)message error:(NSError *)error{}
@end