Commit ec8ac7b0 authored by 井庆林's avatar 井庆林

pull

parents d3ac29ab 0495bdd9
...@@ -42,32 +42,32 @@ NSString *const MockCityId = @"beijing"; ...@@ -42,32 +42,32 @@ NSString *const MockCityId = @"beijing";
Phobos.sharedClient.signingType = PhobosSigningTypeDebug; Phobos.sharedClient.signingType = PhobosSigningTypeDebug;
Phobos.sharedClient.userId = @""; Phobos.sharedClient.userId = @"";
NSString *inDate = [PhobosUtil currentTime]; // NSString *inDate = [PhobosUtil currentTime];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; // NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:[PhobosUtil currentTime] forKey:@"out"]; // [dict setObject:[PhobosUtil currentTime] forKey:@"out"];
[dict setObject:inDate forKey:@"in"]; // [dict setObject:inDate forKey:@"in"];
[dict setObject:@"test" forKey:@"page_name"]; // [dict setObject:@"test" forKey:@"page_name"];
[dict setObject:@"" forKey:@"business_id"]; // [dict setObject:@"" forKey:@"business_id"];
[dict setObject:@"" forKey:@"referrer"]; // [dict setObject:@"" forKey:@"referrer"];
[dict setObject:@(0) forKey:@"fake"]; // [dict setObject:@(0) forKey:@"fake"];
[dict setObject:@"" forKey:@"referrer_id"]; // [dict setObject:@"" forKey:@"referrer_id"];
[dict setObject:@"" forKey:@"extra_param"]; // [dict setObject:@"" forKey:@"extra_param"];
[dict setObject:@"" forKey:@"referrer_tab_name"]; // [dict setObject:@"" forKey:@"referrer_tab_name"];
[dict setObject:@(0) forKey:@"is_push"]; // [dict setObject:@(0) forKey:@"is_push"];
[Phobos track:@"page_view" attributes:dict]; // [Phobos track:@"page_view" attributes:dict];
NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey]; // NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
//
[Phobos track:@"page_view" attributes:dict]; // [Phobos track:@"page_view" attributes:dict];
array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey]; // array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
//
[dict setObject:[PhobosUtil currentTime] forKey:@"in"]; // [dict setObject:[PhobosUtil currentTime] forKey:@"in"];
[dict setObject:[PhobosUtil currentTime] forKey:@"out"]; // [dict setObject:[PhobosUtil currentTime] forKey:@"out"];
[Phobos track:@"page_view" attributes:dict]; // [Phobos track:@"page_view" attributes:dict];
array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey]; // array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
//
[Phobos track:@"test" attributes:dict]; // [Phobos track:@"test" attributes:dict];
array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey]; // array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
//
} }
- (void)didReceiveMemoryWarning - (void)didReceiveMemoryWarning
......
...@@ -35,7 +35,11 @@ PODS: ...@@ -35,7 +35,11 @@ PODS:
- GMKit/Protocol (1.1.3): - GMKit/Protocol (1.1.3):
- Masonry (= 1.1.0) - Masonry (= 1.1.0)
- SDWebImage (= 3.7.6) - SDWebImage (= 3.7.6)
<<<<<<< HEAD
- GMPhobos (1.3.4): - GMPhobos (1.3.4):
=======
- GMPhobos (1.3.6):
>>>>>>> 0495bdd9cf7d4652f1252b323950a64abc9f17ca
- GMCache - GMCache
- GMKit - GMKit
- Masonry (1.1.0) - Masonry (1.1.0)
...@@ -51,7 +55,7 @@ SPEC REPOS: ...@@ -51,7 +55,7 @@ SPEC REPOS:
"git@git.wanmeizhensuo.com:gengmeiios/GMSpecs.git": "git@git.wanmeizhensuo.com:gengmeiios/GMSpecs.git":
- GMCache - GMCache
- GMKit - GMKit
https://github.com/cocoapods/specs.git: https://github.com/CocoaPods/Specs.git:
- Masonry - Masonry
- SDWebImage - SDWebImage
- TMCache - TMCache
...@@ -63,11 +67,15 @@ EXTERNAL SOURCES: ...@@ -63,11 +67,15 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS: SPEC CHECKSUMS:
GMCache: 09a3029c96fe130e3a21faef70b3d9d2ce92d639 GMCache: 09a3029c96fe130e3a21faef70b3d9d2ce92d639
GMKit: 35f788243cceeddf3e13c5226b3ea0b5e08e2117 GMKit: 35f788243cceeddf3e13c5226b3ea0b5e08e2117
<<<<<<< HEAD
GMPhobos: 1ee4b12cccd1df054bf9539357c5fc60a2d64a68 GMPhobos: 1ee4b12cccd1df054bf9539357c5fc60a2d64a68
=======
GMPhobos: 6623102d634ce5485e8d3e474da8bdce5891f419
>>>>>>> 0495bdd9cf7d4652f1252b323950a64abc9f17ca
Masonry: 678fab65091a9290e40e2832a55e7ab731aad201 Masonry: 678fab65091a9290e40e2832a55e7ab731aad201
SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9 SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9
TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed
PODFILE CHECKSUM: ea0fac2144ac80baf8f21576cde49526c19991ad PODFILE CHECKSUM: ea0fac2144ac80baf8f21576cde49526c19991ad
COCOAPODS: 1.7.4 COCOAPODS: 1.9.0
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#import <GMPhobos/Phobos.h> #import <GMPhobos/Phobos.h>
#import "GMPhobosController.h" #import "GMPhobosController.h"
#import <GMCache/GMCache.h> #define PhobosCacheKey @"PhobosCacheKey"
@import GMCache;
NSString *const MockAppName = @"gengmei_test"; NSString *const MockAppName = @"gengmei_test";
NSString *const MockChannelId = @"AppStore"; NSString *const MockChannelId = @"AppStore";
...@@ -18,25 +19,26 @@ NSString *const MockUserId = @"1"; ...@@ -18,25 +19,26 @@ NSString *const MockUserId = @"1";
NSString *const MockCityId = @"beijing"; NSString *const MockCityId = @"beijing";
@interface GMPhotoTest : XCTestCase @interface GMPhotoTest : XCTestCase
@property Phobos *client;
@end @end
///[NSThread sleepForTimeInterval:0.2]; 因为是异步处理数据,所以需要延迟获取,进行单元测试
@implementation GMPhotoTest @implementation GMPhotoTest
- (void)setUp { - (void)setUp {
[super setUp]; [super setUp];
[Phobos clientWithAppName:MockAppName channelId:MockChannelId]; _client = [Phobos clientWithAppName:MockAppName channelId:MockChannelId];
Phobos.sharedClient.serverAPI = @"http://log.test.igengmei.com/log/collect"; _client.serverAPI = @"http://log.test.igengmei.com/log/collect";
Phobos.sharedClient.logEnabled = NO; // 调试打Log模式,看情况开启 [_client setLogEnabled:NO]; // 调试打Log模式,看情况开启
Phobos.sharedClient.signingType = PhobosSigningTypeDebug; _client.signingType = PhobosSigningTypeDebug;
Phobos.sharedClient.userId = @""; _client.userId = @"";
[Phobos setSharedClient:_client];
} }
- (void)tearDown { - (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class. // Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown]; [super tearDown];
[Phobos removeAllNormalPhobosData]; [GMCache removeObjectAtDocumentPathWithkey:PhobosCacheKey];
[Phobos removeAllImmediatelyPhobosData]; [GMCache removeObjectAtDocumentPathWithkey:PhobosTempCacheKey];
} }
/** /**
...@@ -45,12 +47,10 @@ NSString *const MockCityId = @"beijing"; ...@@ -45,12 +47,10 @@ NSString *const MockCityId = @"beijing";
* @since <#version number#> * @since <#version number#>
*/ */
- (void)testClientWithUserId{ - (void)testClientWithUserId{
[Phobos removeAllNormalPhobosData]; [_client setUserId:MockUserId];
[Phobos.sharedClient setUserId:MockUserId]; [_client setCurrentCityId:MockCityId];
[Phobos.sharedClient setCurrentCityId:MockCityId];
[Phobos track:MockEventId]; [Phobos track:MockEventId];
[NSThread sleepForTimeInterval:0.2]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
NSArray *array = [Phobos normalPhobosDataForServerAPI];
XCTAssertTrue(array.count == 1, @"array is empty"); XCTAssertTrue(array.count == 1, @"array is empty");
NSDictionary *dict = [array objectAtIndex:0]; NSDictionary *dict = [array objectAtIndex:0];
[self verfiyDict:dict]; [self verfiyDict:dict];
...@@ -64,8 +64,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -64,8 +64,7 @@ NSString *const MockCityId = @"beijing";
*/ */
- (void)testTrackEventWithoutAttr{ - (void)testTrackEventWithoutAttr{
[Phobos track:MockEventId]; [Phobos track:MockEventId];
[NSThread sleepForTimeInterval:0.2]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
NSArray *array = [Phobos normalPhobosDataForServerAPI];
XCTAssertTrue(array.count == 1, @"array is empty"); XCTAssertTrue(array.count == 1, @"array is empty");
NSDictionary *dict = [array objectAtIndex:0]; NSDictionary *dict = [array objectAtIndex:0];
[self verfiyDict:dict]; [self verfiyDict:dict];
...@@ -80,8 +79,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -80,8 +79,7 @@ NSString *const MockCityId = @"beijing";
- (void)testTrackEventWithAttr{ - (void)testTrackEventWithAttr{
NSDictionary *attr = @{@"attr":@"track_attr"}; NSDictionary *attr = @{@"attr":@"track_attr"};
[Phobos track:MockEventId attributes:attr]; [Phobos track:MockEventId attributes:attr];
[NSThread sleepForTimeInterval:0.2]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
NSArray *array = [Phobos normalPhobosDataForServerAPI];
XCTAssertTrue(array.count == 1, @"array is empty"); XCTAssertTrue(array.count == 1, @"array is empty");
NSDictionary *dict = [array objectAtIndex:0]; NSDictionary *dict = [array objectAtIndex:0];
[self verfiyDict:dict]; [self verfiyDict:dict];
...@@ -97,13 +95,13 @@ NSString *const MockCityId = @"beijing"; ...@@ -97,13 +95,13 @@ NSString *const MockCityId = @"beijing";
* @since <#version number#> * @since <#version number#>
*/ */
- (void)testTrackEventWithAttrAndSendNow{ - (void)testTrackEventWithAttrAndSendNow{
[Phobos removeAllNormalPhobosData];
// Given // Given
NSDictionary *attr = @{@"attr":@"track_attr"}; NSDictionary *attr = @{@"attr":@"track_attr"};
// When // When
[Phobos track:MockEventId attributes:attr sendNow:YES]; [Phobos track:MockEventId attributes:attr sendNow:YES];
// Then // Then
XCTAssertTrue([Phobos normalPhobosCount] == 0, @"array should be empty"); NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count == 0, @"array should be empty");
} }
/** /**
...@@ -120,7 +118,8 @@ NSString *const MockCityId = @"beijing"; ...@@ -120,7 +118,8 @@ NSString *const MockCityId = @"beijing";
// When // When
[Phobos track:MockEventId attributes:sendNowAttr sendNow:YES]; [Phobos track:MockEventId attributes:sendNowAttr sendNow:YES];
XCTAssertTrue([Phobos normalPhobosCount] != 0, @"array shouldn't be empty"); NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count != 0, @"array shouldn't be empty");
} }
/** /**
...@@ -134,16 +133,16 @@ NSString *const MockCityId = @"beijing"; ...@@ -134,16 +133,16 @@ NSString *const MockCityId = @"beijing";
// 因为实时埋点是异步删除,所以这个位置暂时延时取数据,待优化 TODO // 因为实时埋点是异步删除,所以这个位置暂时延时取数据,待优化 TODO
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSArray *array = [Phobos immediatelyPhobosForServerAPI]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosTempCacheKey];
XCTAssertTrue(array.count == 0, @"array shouldn't be empty"); XCTAssertTrue(array.count == 0, @"array shouldn't be empty");
[Phobos track:MockEventId attributes:attr sendNow:YES]; [Phobos track:MockEventId attributes:attr sendNow:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSArray *array = [Phobos immediatelyPhobosForServerAPI]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosTempCacheKey];
XCTAssertTrue(array.count == 0, @"array shouldn't be empty"); XCTAssertTrue(array.count == 0, @"array shouldn't be empty");
[Phobos track:MockEventId attributes:attr sendNow:YES]; [Phobos track:MockEventId attributes:attr sendNow:YES];
array = [Phobos normalPhobosDataForServerAPI]; array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 0, @"array shouldn't be empty"); XCTAssertTrue(array.count == 0, @"array shouldn't be empty");
}); });
}); });
} }
...@@ -154,27 +153,23 @@ NSString *const MockCityId = @"beijing"; ...@@ -154,27 +153,23 @@ NSString *const MockCityId = @"beijing";
* @since 1.1.4 * @since 1.1.4
*/ */
- (void)testTrackEventWithDoubleAttrAndNoSendNow { - (void)testTrackEventWithDoubleAttrAndNoSendNow {
[Phobos removeAllNormalPhobosData];
NSDictionary *attr = @{@"attr":@"track_attr"}; NSDictionary *attr = @{@"attr":@"track_attr"};
// //
[NSThread sleepForTimeInterval:0.2];
[Phobos track:MockEventId attributes:attr]; [Phobos track:MockEventId attributes:attr];
[NSThread sleepForTimeInterval:0.2]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 1, @"array shouldn't be empty"); XCTAssertTrue(array.count == 1, @"array shouldn't be empty");
// PhobosCacheKey超过50条数据会自动上报,模拟此情况 // PhobosCacheKey超过50条数据会自动上报,模拟此情况
for (int i = 0; i < 50; i++) { for (int i = 0; i < 50; i++) {
[Phobos track:MockEventId attributes:attr]; [Phobos track:MockEventId attributes:attr];
} }
array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
[NSThread sleepForTimeInterval:0.2]; XCTAssertTrue(array.count == 0, @"array shouldn't be empty");
XCTAssertTrue([Phobos normalPhobosCount] == 1, @"array shouldn't be empty");
[NSThread sleepForTimeInterval:0.2];
[Phobos track:MockEventId attributes:attr]; [Phobos track:MockEventId attributes:attr];
[NSThread sleepForTimeInterval:0.2]; array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 2, @"array shouldn't be empty"); XCTAssertTrue(array.count == 1, @"array shouldn't be empty");
} }
/** /**
...@@ -183,36 +178,35 @@ NSString *const MockCityId = @"beijing"; ...@@ -183,36 +178,35 @@ NSString *const MockCityId = @"beijing";
* @since 1.1.4 * @since 1.1.4
*/ */
- (void)testTrackEventWithSendNowAndNoSendNowOne { - (void)testTrackEventWithSendNowAndNoSendNowOne {
[Phobos removeAllNormalPhobosData];
NSDictionary *attr = @{@"attr":@"track_attr"}; NSDictionary *attr = @{@"attr":@"track_attr"};
NSDictionary *sendNowAttr = @{@"attr":@"track_attr_send_now"}; NSDictionary *sendNowAttr = @{@"attr":@"track_attr_send_now"};
for (int i = 0; i < 30; i++) { for (int i = 0; i < 30; i++) {
[Phobos track:MockEventId attributes:attr]; [Phobos track:MockEventId attributes:attr];
} }
[NSThread sleepForTimeInterval:0.2]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 30, @"array shouldn't be empty"); XCTAssertTrue(array.count == 30, @"array shouldn't be empty");
// PhobosCacheKey超过50条数据会自动上报,模拟此情况 // PhobosCacheKey超过50条数据会自动上报,模拟此情况
[Phobos track:MockEventId attributes:sendNowAttr sendNow:YES]; [Phobos track:MockEventId attributes:sendNowAttr sendNow:YES];
[NSThread sleepForTimeInterval:0.2]; array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 30, @"array shouldn't be empty"); XCTAssertTrue(array.count == 30, @"array shouldn't be empty");
[Phobos track:MockEventId attributes:sendNowAttr sendNow:YES]; [Phobos track:MockEventId attributes:sendNowAttr sendNow:YES];
[NSThread sleepForTimeInterval:0.2]; array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 30, @"array shouldn't be empty"); XCTAssertTrue(array.count == 30, @"array shouldn't be empty");
[Phobos track:MockEventId attributes:sendNowAttr sendNow:YES]; [Phobos track:MockEventId attributes:sendNowAttr sendNow:YES];
[NSThread sleepForTimeInterval:0.2]; array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 30, @"array shouldn't be empty"); XCTAssertTrue(array.count == 30, @"array shouldn't be empty");
[Phobos track:MockEventId attributes:attr]; [Phobos track:MockEventId attributes:attr];
[NSThread sleepForTimeInterval:0.2]; array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 31, @"array shouldn't be empty"); XCTAssertTrue(array.count == 31, @"array shouldn't be empty");
} }
/** /**
...@@ -221,34 +215,33 @@ NSString *const MockCityId = @"beijing"; ...@@ -221,34 +215,33 @@ NSString *const MockCityId = @"beijing";
* @since 1.1.4 * @since 1.1.4
*/ */
- (void)testTrackEventWithSendNowAndNoSendNowTwo { - (void)testTrackEventWithSendNowAndNoSendNowTwo {
[Phobos removeAllNormalPhobosData];
NSDictionary *attr = @{@"attr":@"track_attr"}; NSDictionary *attr = @{@"attr":@"track_attr"};
NSDictionary *sendNowAttr = @{@"attr":@"track_attr_send_now"}; NSDictionary *sendNowAttr = @{@"attr":@"track_attr_send_now"};
[Phobos track:MockEventId attributes:sendNowAttr sendNow:YES]; [Phobos track:MockEventId attributes:sendNowAttr sendNow:YES];
[NSThread sleepForTimeInterval:0.2]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 0, @"array shouldn't be empty"); XCTAssertTrue(array.count == 0, @"array shouldn't be empty");
[Phobos track:MockEventId attributes:attr]; [Phobos track:MockEventId attributes:attr];
[NSThread sleepForTimeInterval:0.2]; array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 1, @"array shouldn't be empty"); XCTAssertTrue(array.count == 1, @"array shouldn't be empty");
[Phobos track:MockEventId attributes:attr]; [Phobos track:MockEventId attributes:attr];
[Phobos track:MockEventId attributes:sendNowAttr sendNow:YES]; [Phobos track:MockEventId attributes:sendNowAttr sendNow:YES];
[NSThread sleepForTimeInterval:0.2]; array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 2, @"array shouldn't be empty"); XCTAssertTrue(array.count == 2, @"array shouldn't be empty");
[Phobos track:MockEventId attributes:sendNowAttr sendNow:YES]; [Phobos track:MockEventId attributes:sendNowAttr sendNow:YES];
[NSThread sleepForTimeInterval:0.2]; array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 2, @"array shouldn't be empty"); XCTAssertTrue(array.count == 2, @"array shouldn't be empty");
[Phobos track:MockEventId attributes:attr]; [Phobos track:MockEventId attributes:attr];
[NSThread sleepForTimeInterval:0.2]; array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 3, @"array shouldn't be empty"); XCTAssertTrue(array.count == 3, @"array shouldn't be empty");
} }
/** /**
...@@ -257,24 +250,23 @@ NSString *const MockCityId = @"beijing"; ...@@ -257,24 +250,23 @@ NSString *const MockCityId = @"beijing";
* @since 1.1.4 * @since 1.1.4
*/ */
- (void)testTrackEventWithSendNowAndNoSendNowThree { - (void)testTrackEventWithSendNowAndNoSendNowThree {
[Phobos removeAllNormalPhobosData];
NSDictionary *attr = @{@"attr":@"track_attr"}; NSDictionary *attr = @{@"attr":@"track_attr"};
// //
[Phobos track:MockEventId attributes:attr]; [Phobos track:MockEventId attributes:attr];
[NSThread sleepForTimeInterval:0.2]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 1, @"array shouldn't be empty"); XCTAssertTrue(array.count == 1, @"array shouldn't be empty");
// PhobosCacheKey超过50条数据会自动上报,模拟此情况 // PhobosCacheKey超过50条数据会自动上报,模拟此情况
for (int i = 0; i < 50; i++) { for (int i = 0; i < 50; i++) {
[Phobos track:MockEventId attributes:attr]; [Phobos track:MockEventId attributes:attr];
} }
[NSThread sleepForTimeInterval:0.2]; array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 1, @"array shouldn't be empty"); XCTAssertTrue(array.count == 0, @"array shouldn't be empty");
[Phobos track:MockEventId attributes:attr]; [Phobos track:MockEventId attributes:attr];
[NSThread sleepForTimeInterval:0.2]; array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 2, @"array shouldn't be empty"); XCTAssertTrue(array.count == 1, @"array shouldn't be empty");
} }
- (void)verfiyDict:(NSDictionary *)dict{ - (void)verfiyDict:(NSDictionary *)dict{
...@@ -286,10 +278,16 @@ NSString *const MockCityId = @"beijing"; ...@@ -286,10 +278,16 @@ NSString *const MockCityId = @"beijing";
XCTAssertTrue([keys containsObject:@"user_id"], @"Missing user_id"); XCTAssertTrue([keys containsObject:@"user_id"], @"Missing user_id");
XCTAssertTrue([keys containsObject:@"create_at"], @"Missing create_at"); XCTAssertTrue([keys containsObject:@"create_at"], @"Missing create_at");
XCTAssertTrue([keys containsObject:@"params"], @"Missing params"); XCTAssertTrue([keys containsObject:@"params"], @"Missing params");
XCTAssertTrue([keys containsObject:@"absolute_time"], @"Missing absolute_time");
XCTAssertTrue([keys containsObject:@"create_at_millis"], @"Missing create_at_millis");
XCTAssertTrue([keys containsObject:@"nano_time"], @"Missing nano_time");
XCTAssertTrue([[dict[@"params"] allKeys] containsObject:@"referrer_link"],@"Missing referrer_link");
XCTAssertTrue((dict[@"params"][@"referrer_link"] != nil || ![dict[@"params"][@"referrer_link"] isEqual:@{}] || dict[@"params"][@"referrer_link"] != NULL), @"referrer_link至少使用默认的[]");
} }
- (void)testCatchNullInAttributes { - (void)testCatchNullInAttributes {
Phobos.sharedClient.captureNullExpection = ^(NSString *eventId, NSDictionary *att) { _client.captureNullExpection = ^(NSString *eventId, NSDictionary *att) {
NSCAssert([att[@"bussness_id"] integerValue] == 1244, @"testCatchNullInAttributes 没有捕获到有用信息"); NSCAssert([att[@"bussness_id"] integerValue] == 1244, @"testCatchNullInAttributes 没有捕获到有用信息");
}; };
NSDictionary *attributes = @{@"key": [NSNull null], NSDictionary *attributes = @{@"key": [NSNull null],
...@@ -317,8 +315,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -317,8 +315,7 @@ NSString *const MockCityId = @"beijing";
[controller viewWillAppear:true]; [controller viewWillAppear:true];
[controller viewWillDisappear:true]; [controller viewWillDisappear:true];
[self paramUnNilCheck]; [self paramUnNilCheck];
[NSThread sleepForTimeInterval:0.2]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
NSArray *array = [Phobos normalPhobosDataForServerAPI];
XCTAssertTrue(array.count != 0, @"PhobosCacheKey 下面应该有数据"); XCTAssertTrue(array.count != 0, @"PhobosCacheKey 下面应该有数据");
NSDictionary *dic = array[0][@"params"]; NSDictionary *dic = array[0][@"params"];
...@@ -327,20 +324,21 @@ NSString *const MockCityId = @"beijing"; ...@@ -327,20 +324,21 @@ NSString *const MockCityId = @"beijing";
} }
- (void)testSimulativePageViewEvent { - (void)testSimulativePageViewEvent {
[NSThread sleepForTimeInterval:0.2]; [_client simulativePV:nil businessId:nil referer:nil];
[Phobos.sharedClient simulativePV:nil businessId:nil referer:nil];
[self paramUnNilCheck]; [self paramUnNilCheck];
} }
- (void)paramUnNilCheck { - (void)paramUnNilCheck {
[NSThread sleepForTimeInterval:0.2]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
NSArray *array = [Phobos normalPhobosDataForServerAPI];
XCTAssertTrue(array.count != 0, @"PhobosCacheKey 下面应该有数据"); XCTAssertTrue(array.count != 0, @"PhobosCacheKey 下面应该有数据");
NSDictionary *dic = array[0][@"params"]; NSDictionary *dic = array[0][@"params"];
XCTAssertTrue(dic[@"page_name"] != nil, @"page_name至少使用默认的空字符串"); XCTAssertTrue(dic[@"page_name"] != nil, @"page_name至少使用默认的空字符串");
XCTAssertTrue([dic[@"referer"] integerValue] >= 0, @"referer至少使用默认的空字符串"); XCTAssertTrue([dic[@"referer"] integerValue] >= 0, @"referer至少使用默认的空字符串");
XCTAssertTrue(dic[@"business_id"] != nil, @"business_id至少使用默认的空字符串"); XCTAssertTrue(dic[@"business_id"] != nil, @"business_id至少使用默认的空字符串");
XCTAssertTrue(dic[@"in_time_millis"] != nil, @"in_time_millis至少使用默认的空字符串");
XCTAssertTrue(dic[@"out_time_millis"] != nil, @"out_time_millis至少使用默认的空字符串");
XCTAssertTrue((dic[@"referrer_link"] != nil || ![dic[@"referrer_link"] isEqual:@{}] || dic[@"referrer_link"] != NULL), @"referrer_link至少使用默认的[]");
} }
#pragma mark - 属性test #pragma mark - 属性test
...@@ -352,9 +350,8 @@ NSString *const MockCityId = @"beijing"; ...@@ -352,9 +350,8 @@ NSString *const MockCityId = @"beijing";
XCTAssertFalse(controller.needLogPV, @"needLogPV赋值为NO时应该NO"); XCTAssertFalse(controller.needLogPV, @"needLogPV赋值为NO时应该NO");
} }
// 该单元测试暂时不用,因为过滤代码暂时不用,所以不需要跑通
- (void)testCheckPVPhobos { - (void)testCheckPVPhobos {
[Phobos removeAllNormalPhobosData]; [GMCache removeObjectAtDocumentPathWithkey:PhobosCacheKey];
NSString *inDate = [PhobosUtil currentTime]; NSString *inDate = [PhobosUtil currentTime];
[NSThread sleepForTimeInterval:1];//模拟浏览页面,让out和in时间相差1s [NSThread sleepForTimeInterval:1];//模拟浏览页面,让out和in时间相差1s
...@@ -370,12 +367,12 @@ NSString *const MockCityId = @"beijing"; ...@@ -370,12 +367,12 @@ NSString *const MockCityId = @"beijing";
[dict setObject:@"" forKey:@"referrer_tab_name"]; [dict setObject:@"" forKey:@"referrer_tab_name"];
[dict setObject:@(0) forKey:@"is_push"]; [dict setObject:@(0) forKey:@"is_push"];
[Phobos track:@"page_view" attributes:dict]; [Phobos track:@"page_view" attributes:dict];
NSArray *array = [Phobos normalPhobosDataForServerAPI]; NSArray *array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
[NSThread sleepForTimeInterval:0.2];
XCTAssertTrue(array.count == 1, @"PhobosCacheKey 下面应该有数据"); XCTAssertTrue(array.count == 1, @"PhobosCacheKey 下面应该有数据");
[Phobos track:@"page_view" attributes:dict]; [Phobos track:@"page_view" attributes:dict];
XCTAssertTrue([Phobos normalPhobosCount] == 1, @"PhobosCacheKey 上条数据不应该发送"); array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count == 1, @"PhobosCacheKey 上条数据不应该发送");
[NSThread sleepForTimeInterval:2];//模拟浏览页面,让第二次浏览和上一次时间相差2s [NSThread sleepForTimeInterval:2];//模拟浏览页面,让第二次浏览和上一次时间相差2s
...@@ -383,14 +380,14 @@ NSString *const MockCityId = @"beijing"; ...@@ -383,14 +380,14 @@ NSString *const MockCityId = @"beijing";
[NSThread sleepForTimeInterval:1];//模拟浏览页面,让out和in时间相差1s [NSThread sleepForTimeInterval:1];//模拟浏览页面,让out和in时间相差1s
[dict setObject:[PhobosUtil currentTime] forKey:@"out"]; [dict setObject:[PhobosUtil currentTime] forKey:@"out"];
[Phobos track:@"page_view" attributes:dict]; [Phobos track:@"page_view" attributes:dict];
[NSThread sleepForTimeInterval:0.2]; array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount]== 2, @"PhobosCacheKey 上条数据应该发送"); XCTAssertTrue(array.count == 2, @"PhobosCacheKey 上条数据应该发送");
[Phobos track:@"page_view" attributes:dict]; [Phobos track:@"page_view" attributes:dict];
[NSThread sleepForTimeInterval:0.2]; array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 2, @"PhobosCacheKey 上条数据不应该发送"); XCTAssertTrue(array.count == 2, @"PhobosCacheKey 上条数据不应该发送");
[Phobos track:@"test" attributes:dict]; [Phobos track:@"test" attributes:dict];
[NSThread sleepForTimeInterval:0.2]; array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
XCTAssertTrue([Phobos normalPhobosCount] == 3, @"PhobosCacheKey 上条数据应该发送"); XCTAssertTrue(array.count == 3, @"PhobosCacheKey 上条数据应该发送");
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "GMPhobos" s.name = "GMPhobos"
s.version = "1.3.5" s.version = "1.3.6"
s.summary = "GM statistic data sdk" s.summary = "GM statistic data sdk"
s.description = <<-DESC s.description = <<-DESC
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#import "PhobosCustomVisibleController.h" #import "PhobosCustomVisibleController.h"
#import "UIDevice+Resolutions.h" #import "UIDevice+Resolutions.h"
#import <GMCache/GMCache.h> #import <GMCache/GMCache.h>
#import <mach/mach_time.h>
static Phobos *sharedClient = nil; static Phobos *sharedClient = nil;
static NSString *sdkVersion = @"110"; static NSString *sdkVersion = @"110";
...@@ -135,12 +136,16 @@ static NSString *sdkVersion = @"110"; ...@@ -135,12 +136,16 @@ static NSString *sdkVersion = @"110";
} }
- (UIViewController *)visibleController { - (UIViewController *)visibleController {
if (self.getTopController) {
id target = self.getTopController(); id target = self.getTopController();
if ([target conformsToProtocol:NSProtocolFromString(@"PhobosCustomVisibleController")]) { if ([target conformsToProtocol:NSProtocolFromString(@"PhobosCustomVisibleController")]) {
target = [target performSelector:@selector(phobosVisibleController)]; target = [target performSelector:@selector(phobosVisibleController)];
} }
return target; return target;
}
return nil;
} }
#pragma mark - notification handler #pragma mark - notification handler
...@@ -353,12 +358,21 @@ static NSString *sdkVersion = @"110"; ...@@ -353,12 +358,21 @@ static NSString *sdkVersion = @"110";
[page initReferrerIdIfNil]; [page initReferrerIdIfNil];
[page initReferrerTabName]; [page initReferrerTabName];
page.inTime = [PhobosUtil currentTime]; page.inTime = [PhobosUtil currentTime];
page.inTimeMillis = [PhobosUtil currentMMTime];
// 业务层更新
if (page.updatePVStartBlock) {
page.updatePVStartBlock();
}
} }
- (void)onPVEnd:(UIResponder<PhobosPVProtocol> *)page { - (void)onPVEnd:(UIResponder<PhobosPVProtocol> *)page {
if (![PhobosUtil isNonEmpty:page.pageName] || !page.needLogPV) { if (![PhobosUtil isNonEmpty:page.pageName] || !page.needLogPV) {
return; return;
} }
// 业务层更新
if (page.updatePVEndBlock) {
page.updatePVEndBlock();
}
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
@try { @try {
[dict setObject:[PhobosUtil currentTime] forKey:@"out"]; [dict setObject:[PhobosUtil currentTime] forKey:@"out"];
...@@ -366,12 +380,18 @@ static NSString *sdkVersion = @"110"; ...@@ -366,12 +380,18 @@ static NSString *sdkVersion = @"110";
[dict setObject:page.pageName forKey:@"page_name"]; [dict setObject:page.pageName forKey:@"page_name"];
[dict setObject:page.businessId?:@"" forKey:@"business_id"]; [dict setObject:page.businessId?:@"" forKey:@"business_id"];
[dict setObject:page.referer?:@"" forKey:@"referrer"]; [dict setObject:page.referer?:@"" forKey:@"referrer"];
[dict setObject:page.referrerLink ? : @[] forKey:@"referrer_link"]; if ([page.referrerLink isKindOfClass:[NSArray class]] && page.referrerLink.count) {
[dict setObject:page.referrerLink forKey:@"referrer_link"];
} else {
[dict setObject:@[] forKey:@"referrer_link"];
}
[dict setObject:@(0) forKey:@"fake"]; [dict setObject:@(0) forKey:@"fake"];
[dict setObject:page.referrerId ? : @"" forKey:@"referrer_id"]; [dict setObject:page.referrerId ? : @"" forKey:@"referrer_id"];
[dict setObject:page.extraParam ? : @"" forKey:@"extra_param"]; [dict setObject:page.extraParam ? : @"" forKey:@"extra_param"];
[dict setObject:page.referrerTabName ? : @"" forKey:@"referrer_tab_name"]; [dict setObject:page.referrerTabName ? : @"" forKey:@"referrer_tab_name"];
[dict setObject:page.isPush.intValue ? @(page.isPush.intValue) : @(0) forKey:@"is_push"]; [dict setObject:page.isPush.intValue ? @(page.isPush.intValue) : @(0) forKey:@"is_push"];
[dict setObject:page.inTimeMillis?:@"" forKey:@"in_time_millis"];
[dict setObject:[PhobosUtil currentMMTime] forKey:@"out_time_millis"];
if (page.inTime.length > 0) { if (page.inTime.length > 0) {
// 页面显示时间为空时不记录页面pv事件 // 页面显示时间为空时不记录页面pv事件
...@@ -409,11 +429,17 @@ static NSString *sdkVersion = @"110"; ...@@ -409,11 +429,17 @@ static NSString *sdkVersion = @"110";
* *
* @since 0.0.1 * @since 0.0.1
*/ */
- (NSDictionary *)prepareDictionaryForEvent:(NSString *)eventId attributes:(NSDictionary *)attributes{ - (NSDictionary *)prepareDictionaryForEvent:(NSString *)eventId attributes:(NSDictionary *)attributes {
NSArray *referrerLink = sharedClient.visibleController.referrerLink; NSArray *referrerLink = sharedClient.visibleController.referrerLink;
if (![eventId isEqualToString:@"page_view"]) {
// 对于埋点没有referrer_link的情况,在这里进行统一添加
if (![attributes.allKeys containsObject:@"referrer_link"]) {
NSMutableDictionary *attributesParams = [NSMutableDictionary dictionaryWithDictionary:attributes]; NSMutableDictionary *attributesParams = [NSMutableDictionary dictionaryWithDictionary:attributes];
[attributesParams setValue:referrerLink ? : @[] forKey:@"referrer_link"]; if ([referrerLink isKindOfClass:[NSArray class]] && referrerLink.count) {
[attributesParams setValue:referrerLink forKey:@"referrer_link"];
} else {
[attributesParams setValue:@[] forKey:@"referrer_link"];
}
attributes = attributesParams; attributes = attributesParams;
} }
[self catchNullForEvent:eventId attributes:attributes]; [self catchNullForEvent:eventId attributes:attributes];
...@@ -445,12 +471,16 @@ static NSString *sdkVersion = @"110"; ...@@ -445,12 +471,16 @@ static NSString *sdkVersion = @"110";
if (_signingType == PhobosSigningTypeDebug || _signingType == PhobosSigningTypeRelease) { if (_signingType == PhobosSigningTypeDebug || _signingType == PhobosSigningTypeRelease) {
[dict setObject:@(0) forKey:@"is_release"]; [dict setObject:@(0) forKey:@"is_release"];
} }
NSString *nano_time = [NSString stringWithFormat:@"%lld",[[NSProcessInfo processInfo] systemUptime]];
[dict setObject:eventId forKey:@"type"]; [dict setObject:eventId forKey:@"type"];
[dict setObject:appParams forKey:@"app"]; [dict setObject:appParams forKey:@"app"];
[dict setObject:sdkVersion forKey:@"version"]; [dict setObject:sdkVersion forKey:@"version"];
[dict setObject:deviceParams forKey:@"device"]; [dict setObject:deviceParams forKey:@"device"];
[dict setObject:_userId forKey:@"user_id"]; [dict setObject:_userId forKey:@"user_id"];
[dict setObject:currentTime forKey:@"create_at"]; [dict setObject:currentTime forKey:@"create_at"];// 1584513842 当前时间(秒)
[dict setObject:nano_time?:@"" forKey:@"nano_time"];// 1657008897 系统启动后时长(秒)
[dict setObject:@(mach_absolute_time()) forKey:@"absolute_time"];// 148237263697318 系统启动后的 CPU 嘀嗒数(纳秒)
[dict setObject:[PhobosUtil currentMMTime] forKey:@"create_at_millis"];// 1584513842753 当前时间戳(毫秒)
[dict setObject:attributes forKey:@"params"]; [dict setObject:attributes forKey:@"params"];
[dict setObject:_sessionId forKey:@"app_session_id"]; [dict setObject:_sessionId forKey:@"app_session_id"];
} }
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
typedef void(^PhobosUpdatePVBlock)(void);
@protocol PhobosPVProtocol <NSObject> @protocol PhobosPVProtocol <NSObject>
/** /**
...@@ -42,6 +44,9 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -42,6 +44,9 @@ NS_ASSUME_NONNULL_BEGIN
*/ */
@property (nonatomic, copy, nonnull) NSString *inTime; @property (nonatomic, copy, nonnull) NSString *inTime;
/// 当前VC.view 显示的时候的时间戳(精确到毫秒)
@property (nonatomic, copy, nonnull) NSString *inTimeMillis;
/** /**
前一个页面的businessId。该属性有可能为空字符串 前一个页面的businessId。该属性有可能为空字符串
*/ */
...@@ -80,6 +85,10 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -80,6 +85,10 @@ NS_ASSUME_NONNULL_BEGIN
*/ */
@property (nonatomic, copy) NSArray *referrerLink; @property (nonatomic, copy) NSArray *referrerLink;
/// 业务层更新PVStart信息
@property (nonatomic, copy) PhobosUpdatePVBlock updatePVStartBlock;
/// 业务层更新PVEnd信息
@property (nonatomic, copy) PhobosUpdatePVBlock updatePVEndBlock;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -428,7 +428,7 @@ ...@@ -428,7 +428,7 @@
} }
/** /**
* 获取手机运行时间,从开机到现在 * 获取手机运行时间,从开机到现在(秒)
*/ */
+ (NSString *)deviceRunTime { + (NSString *)deviceRunTime {
struct timeval boottime; struct timeval boottime;
......
...@@ -152,7 +152,6 @@ ...@@ -152,7 +152,6 @@
objc_setAssociatedObject(self, @selector(inTime), inTime, OBJC_ASSOCIATION_COPY); objc_setAssociatedObject(self, @selector(inTime), inTime, OBJC_ASSOCIATION_COPY);
} }
/** /**
这个地方inTime的值为nil的情况不做考虑,因为Phobos不会发送。inTime必须在controller viewWillAppear时赋值 这个地方inTime的值为nil的情况不做考虑,因为Phobos不会发送。inTime必须在controller viewWillAppear时赋值
*/ */
...@@ -161,6 +160,15 @@ ...@@ -161,6 +160,15 @@
return inTime; return inTime;
} }
- (void)setInTimeMillis:(NSString *)inTimeMillis {
objc_setAssociatedObject(self, @selector(inTimeMillis), inTimeMillis, OBJC_ASSOCIATION_COPY);
}
- (NSString *)inTimeMillis {
NSString *inTimeMillis = objc_getAssociatedObject(self, @selector(inTimeMillis));
return inTimeMillis;
}
- (void)initReferrerIdIfNil { - (void)initReferrerIdIfNil {
// 只有不为空,且是controller的情况下才自动获取 // 只有不为空,且是controller的情况下才自动获取
if ([self.referrerId isEqualToString:@""] && [self isKindOfClass:[UIViewController class]]) { if ([self.referrerId isEqualToString:@""] && [self isKindOfClass:[UIViewController class]]) {
...@@ -236,4 +244,23 @@ ...@@ -236,4 +244,23 @@
return isPush == nil ? @"" : isPush; return isPush == nil ? @"" : isPush;
} }
- (void)setUpdatePVStartBlock:(PhobosUpdatePVBlock)updatePVStartBlock {
objc_setAssociatedObject(self, @selector(updatePVStartBlock), updatePVStartBlock, OBJC_ASSOCIATION_COPY);
}
- (PhobosUpdatePVBlock)updatePVStartBlock {
PhobosUpdatePVBlock updatePVBlock = objc_getAssociatedObject(self, @selector(updatePVStartBlock));
return updatePVBlock;
}
- (void)setUpdatePVEndBlock:(PhobosUpdatePVBlock)updatePVEndBlock {
objc_setAssociatedObject(self, @selector(updatePVEndBlock), updatePVEndBlock, OBJC_ASSOCIATION_COPY);
}
- (PhobosUpdatePVBlock)updatePVEndBlock {
PhobosUpdatePVBlock updatePVBlock = objc_getAssociatedObject(self, @selector(updatePVEndBlock));
return updatePVBlock;
}
@end @end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment