Skip to content

Commit 83ed1a0

Browse files
authored
Fix PINCacheTests compiling in Xcode 12.0b4 (#276)
Fixed type checking for block parameters in tests using id with protocols. Same as commit 10b3c3c did.
1 parent aca69b9 commit 83ed1a0

File tree

1 file changed

+40
-39
lines changed

1 file changed

+40
-39
lines changed

Tests/PINCacheTests.m

+40-39
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ - (void)testObjectSet
130130
__block PINImage *image = nil;
131131
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
132132

133-
[self.cache setObjectAsync:[self image] forKey:key completion:^(PINCache *cache, NSString *key, id object) {
133+
[self.cache setObjectAsync:[self image] forKey:key completion:^(id<PINCaching> cache, NSString *key, id object) {
134134
image = (PINImage *)object;
135135
dispatch_semaphore_signal(semaphore);
136136
}];
@@ -148,7 +148,7 @@ - (void)testObjectSetWithCost
148148
PINImage *srcImage = [self image];
149149
NSUInteger cost = (NSUInteger)(srcImage.size.width * srcImage.size.height);
150150

151-
[self.cache setObjectAsync:srcImage forKey:key withCost:cost completion:^(PINCache *cache, NSString *key, id object) {
151+
[self.cache setObjectAsync:srcImage forKey:key withCost:cost completion:^(id<PINCaching> cache, NSString *key, id object) {
152152
image = (PINImage *)object;
153153
dispatch_semaphore_signal(semaphore);
154154
}];
@@ -170,7 +170,7 @@ - (void)testObjectSetWithDuplicateKey
170170
[self.cache setObject:value1 forKey:key];
171171
[self.cache setObject:value2 forKey:key];
172172

173-
[self.cache objectForKeyAsync:key completion:^(PINCache *cache, NSString *key, id object) {
173+
[self.cache objectForKeyAsync:key completion:^(id<PINCaching> cache, NSString *key, id object) {
174174
cachedValue = (NSString *)object;
175175
dispatch_semaphore_signal(semaphore);
176176
}];
@@ -233,7 +233,7 @@ - (void)testObjectGet
233233

234234
self.cache[key] = [self image];
235235

236-
[self.cache objectForKeyAsync:key completion:^(PINCache *cache, NSString *key, id object) {
236+
[self.cache objectForKeyAsync:key completion:^(id<PINCaching> cache, NSString *key, id object) {
237237
image = (PINImage *)object;
238238
dispatch_semaphore_signal(semaphore);
239239
}];
@@ -252,7 +252,7 @@ - (void)testObjectGetWithInvalidKey
252252

253253
self.cache[key] = [self image];
254254

255-
[self.cache objectForKeyAsync:invalidKey completion:^(PINCache *cache, NSString *key, id object) {
255+
[self.cache objectForKeyAsync:invalidKey completion:^(id<PINCaching> cache, NSString *key, id object) {
256256
image = (PINImage *)object;
257257
dispatch_semaphore_signal(semaphore);
258258
}];
@@ -279,7 +279,7 @@ - (void)testObjectRemove
279279
didRemoveObjectBlockCalled = YES;
280280
};
281281

282-
[self.cache removeObjectForKeyAsync:key completion:^(PINCache *cache, NSString *key, id object) {
282+
[self.cache removeObjectForKeyAsync:key completion:^(id<PINCaching> cache, NSString *key, id object) {
283283
dispatch_semaphore_signal(semaphore);
284284
}];
285285

@@ -311,7 +311,7 @@ - (void)testObjectRemoveAll
311311
didRemoveAllObjectsBlockCalled = YES;
312312
};
313313

314-
[self.cache removeAllObjectsAsync:^(PINCache *cache) {
314+
[self.cache removeAllObjectsAsync:^(id<PINCaching> cache) {
315315
dispatch_semaphore_signal(semaphore);
316316
}];
317317

@@ -505,9 +505,9 @@ - (void)testOneThousandAndOneWrites
505505
#pragma clang diagnostic push
506506
#pragma clang diagnostic ignored "-Warc-retain-cycles"
507507
dispatch_group_enter(group);
508-
[self.cache setObjectAsync:obj forKey:key completion:^(PINCache * _Nonnull cache, NSString * _Nonnull key, id _Nullable object) {
508+
[self.cache setObjectAsync:obj forKey:key completion:^(id<PINCaching> _Nonnull cache, NSString * _Nonnull key, id _Nullable object) {
509509
dispatch_async(queue, ^{
510-
[self.cache objectForKeyAsync:key completion:^(PINCache * _Nonnull cache, NSString * _Nonnull key, id _Nullable object) {
510+
[self.cache objectForKeyAsync:key completion:^(id<PINCaching> _Nonnull cache, NSString * _Nonnull key, id _Nullable object) {
511511
NSString *obj = [[NSString alloc] initWithFormat:@"obj %lu", (unsigned long)i];
512512
XCTAssertTrue([object isEqualToString:obj] == YES, @"object returned was not object set");
513513
@synchronized (self) {
@@ -535,7 +535,7 @@ - (void)testMemoryWarningBlock
535535

536536
__block BOOL blockDidExecute = NO;
537537

538-
self.cache.memoryCache.didReceiveMemoryWarningBlock = ^(PINMemoryCache *cache) {
538+
self.cache.memoryCache.didReceiveMemoryWarningBlock = ^(id<PINCaching> cache) {
539539
blockDidExecute = YES;
540540
dispatch_semaphore_signal(semaphore);
541541
};
@@ -554,7 +554,7 @@ - (void)testBackgroundBlock
554554

555555
__block BOOL blockDidExecute = NO;
556556

557-
self.cache.memoryCache.didEnterBackgroundBlock = ^(PINMemoryCache *cache) {
557+
self.cache.memoryCache.didEnterBackgroundBlock = ^(id<PINCaching> cache) {
558558
blockDidExecute = YES;
559559
dispatch_semaphore_signal(semaphore);
560560
};
@@ -591,8 +591,8 @@ - (void)testMemoryWarningProperty
591591

592592
__block id object = nil;
593593

594-
self.cache.memoryCache.didReceiveMemoryWarningBlock = ^(PINMemoryCache *cache) {
595-
object = cache[@"object"];
594+
self.cache.memoryCache.didReceiveMemoryWarningBlock = ^(id<PINCaching> cache) {
595+
object = [cache objectForKey:@"object"];
596596
dispatch_semaphore_signal(semaphore);
597597
};
598598

@@ -620,12 +620,13 @@ - (void)testMemoryCacheEnumerationWithWarning
620620

621621
__block NSUInteger enumCount = 0;
622622

623-
self.cache.memoryCache.didReceiveMemoryWarningBlock = ^(PINMemoryCache *cache) {
624-
[cache enumerateObjectsWithBlockAsync:^(PINMemoryCache *cache, NSString *key, id object, BOOL *stop) {
623+
self.cache.memoryCache.didReceiveMemoryWarningBlock = ^(id<PINCaching> cache) {
624+
PINMemoryCache *memoryCache = (PINMemoryCache *)cache;
625+
[memoryCache enumerateObjectsWithBlockAsync:^(id<PINCaching> cache, NSString *key, id object, BOOL *stop) {
625626
@synchronized (self) {
626627
enumCount++;
627628
}
628-
} completionBlock:^(PINMemoryCache *cache) {
629+
} completionBlock:^(id<PINCaching> cache) {
629630
dispatch_semaphore_signal(semaphore);
630631
}];
631632
};
@@ -665,7 +666,7 @@ - (void)testDiskCacheEnumeration
665666
@synchronized (self) {
666667
enumCount++;
667668
}
668-
} completionBlock:^(PINDiskCache *cache) {
669+
} completionBlock:^(id<PINCaching> cache) {
669670
dispatch_semaphore_signal(semaphore);
670671
}];
671672

@@ -722,25 +723,25 @@ - (void)testAgeLimit
722723
__block id diskObj2 = nil;
723724

724725
dispatch_group_enter(group);
725-
[self.cache.memoryCache objectForKeyAsync:key1 completion:^(PINMemoryCache *cache, NSString *key, id object) {
726+
[self.cache.memoryCache objectForKeyAsync:key1 completion:^(id<PINCaching> cache, NSString *key, id object) {
726727
memObj1 = object;
727728
dispatch_group_leave(group);
728729
}];
729730

730731
dispatch_group_enter(group);
731-
[self.cache.memoryCache objectForKeyAsync:key2 completion:^(PINMemoryCache *cache, NSString *key, id object) {
732+
[self.cache.memoryCache objectForKeyAsync:key2 completion:^(id<PINCaching> cache, NSString *key, id object) {
732733
memObj2 = object;
733734
dispatch_group_leave(group);
734735
}];
735736

736737
dispatch_group_enter(group);
737-
[self.cache.diskCache objectForKeyAsync:key1 completion:^(PINDiskCache *cache, NSString *key, id<NSCoding> object) {
738+
[self.cache.diskCache objectForKeyAsync:key1 completion:^(id<PINCaching> cache, NSString *key, id<NSCoding> object) {
738739
diskObj1 = object;
739740
dispatch_group_leave(group);
740741
}];
741742

742743
dispatch_group_enter(group);
743-
[self.cache.diskCache objectForKeyAsync:key2 completion:^(PINDiskCache *cache, NSString *key, id<NSCoding> object) {
744+
[self.cache.diskCache objectForKeyAsync:key2 completion:^(id<PINCaching> cache, NSString *key, id<NSCoding> object) {
744745
diskObj2 = object;
745746
dispatch_group_leave(group);
746747
}];
@@ -765,19 +766,19 @@ - (void)testAgeLimit
765766
sleep(1);
766767

767768
dispatch_group_enter(group);
768-
[self.cache.memoryCache objectForKeyAsync:key1 completion:^(PINMemoryCache *cache, NSString *key, id object) {
769+
[self.cache.memoryCache objectForKeyAsync:key1 completion:^(id<PINCaching> cache, NSString *key, id object) {
769770
memObj1 = object;
770771
dispatch_group_leave(group);
771772
}];
772773

773774
dispatch_group_enter(group);
774-
[self.cache.memoryCache objectForKeyAsync:key2 completion:^(PINMemoryCache *cache, NSString *key, id object) {
775+
[self.cache.memoryCache objectForKeyAsync:key2 completion:^(id<PINCaching> cache, NSString *key, id object) {
775776
memObj2 = object;
776777
dispatch_group_leave(group);
777778
}];
778779

779780
dispatch_group_enter(group);
780-
[self.cache.diskCache objectForKeyAsync:key1 completion:^(PINDiskCache *cache, NSString *key, id<NSCoding> object) {
781+
[self.cache.diskCache objectForKeyAsync:key1 completion:^(id<PINCaching> cache, NSString *key, id<NSCoding> object) {
781782
diskObj1 = object;
782783
dispatch_group_leave(group);
783784
}];
@@ -902,13 +903,13 @@ - (void)_testTTLCacheObjectAccess {
902903
__block id diskObj = nil;
903904

904905
dispatch_group_enter(group);
905-
[self.cache.memoryCache objectForKeyAsync:key completion:^(PINMemoryCache *cache, NSString *key, id object) {
906+
[self.cache.memoryCache objectForKeyAsync:key completion:^(id<PINCaching> cache, NSString *key, id object) {
906907
memObj = object;
907908
dispatch_group_leave(group);
908909
}];
909910

910911
dispatch_group_enter(group);
911-
[self.cache.diskCache objectForKeyAsync:key completion:^(PINDiskCache *cache, NSString *key, id<NSCoding> object) {
912+
[self.cache.diskCache objectForKeyAsync:key completion:^(id<PINCaching> cache, NSString *key, id<NSCoding> object) {
912913
diskObj = object;
913914
dispatch_group_leave(group);
914915
}];
@@ -926,13 +927,13 @@ - (void)_testTTLCacheObjectAccess {
926927
diskObj = nil;
927928

928929
dispatch_group_enter(group);
929-
[self.cache.memoryCache objectForKeyAsync:key completion:^(PINMemoryCache *cache, NSString *key, id object) {
930+
[self.cache.memoryCache objectForKeyAsync:key completion:^(id<PINCaching> cache, NSString *key, id object) {
930931
memObj = object;
931932
dispatch_group_leave(group);
932933
}];
933934

934935
dispatch_group_enter(group);
935-
[self.cache.diskCache objectForKeyAsync:key completion:^(PINDiskCache *cache, NSString *key, id<NSCoding> object) {
936+
[self.cache.diskCache objectForKeyAsync:key completion:^(id<PINCaching> cache, NSString *key, id<NSCoding> object) {
936937
diskObj = object;
937938
dispatch_group_leave(group);
938939
}];
@@ -979,7 +980,7 @@ - (void)_testTTLCacheObjectEnumeration {
979980
XCTAssertEqual(objCount, expectedObjCount, @"Expected %lu objects in the cache", (unsigned long)expectedObjCount);
980981

981982
objCount = 0;
982-
[self.cache.memoryCache enumerateObjectsWithBlock:^(PINMemoryCache *cache, NSString *key, id _Nullable object, BOOL *stop) {
983+
[self.cache.memoryCache enumerateObjectsWithBlock:^(id<PINCaching> cache, NSString *key, id _Nullable object, BOOL *stop) {
983984
objCount++;
984985
}];
985986

@@ -1005,7 +1006,7 @@ - (void)_testTTLCacheObjectEnumeration {
10051006
XCTAssertEqual(objCount, expectedObjCount, @"Expected %lu objects in the cache", (unsigned long)expectedObjCount);
10061007

10071008
objCount = 0;
1008-
[self.cache.memoryCache enumerateObjectsWithBlock:^(PINMemoryCache * _Nonnull cache, NSString * _Nonnull key, id _Nullable object, BOOL *stop) {
1009+
[self.cache.memoryCache enumerateObjectsWithBlock:^(id<PINCaching> _Nonnull cache, NSString * _Nonnull key, id _Nullable object, BOOL *stop) {
10091010
objCount++;
10101011
}];
10111012

@@ -1089,13 +1090,13 @@ - (void)testObjectTTLObjectAccess
10891090
// Neither object should be expired at this point and should exist in both caches
10901091

10911092
XCTestExpectation *memObjectForKey1Expectation = [self expectationWithDescription:@"memoryCache objectForKeyAsync - #1"];
1092-
[self.cache.memoryCache objectForKeyAsync:key1 completion:^(PINMemoryCache *cache, NSString *key, id object) {
1093+
[self.cache.memoryCache objectForKeyAsync:key1 completion:^(id<PINCaching> cache, NSString *key, id object) {
10931094
XCTAssertNotNil(object, @"should still be in memory cache");
10941095
[memObjectForKey1Expectation fulfill];
10951096
}];
10961097

10971098
XCTestExpectation *memObjectForKey2Expectation = [self expectationWithDescription:@"memoryCache objectForKeyAsync - #2"];
1098-
[self.cache.memoryCache objectForKeyAsync:key2 completion:^(PINMemoryCache *cache, NSString *key, id object) {
1099+
[self.cache.memoryCache objectForKeyAsync:key2 completion:^(id<PINCaching> cache, NSString *key, id object) {
10991100
XCTAssertNotNil(object, @"should still be in memory cache");
11001101
[memObjectForKey2Expectation fulfill];
11011102
}];
@@ -1120,13 +1121,13 @@ - (void)testObjectTTLObjectAccess
11201121
// The first object has been expired for 30 seconds and should not exist in the cache anymore.
11211122

11221123
memObjectForKey1Expectation = [self expectationWithDescription:@"memoryCache objectForKeyAsync - #1"];
1123-
[self.cache.memoryCache objectForKeyAsync:key1 completion:^(PINMemoryCache *cache, NSString *key, id object) {
1124+
[self.cache.memoryCache objectForKeyAsync:key1 completion:^(id<PINCaching> cache, NSString *key, id object) {
11241125
XCTAssertNil(object, @"should not be in memory cache");
11251126
[memObjectForKey1Expectation fulfill];
11261127
}];
11271128

11281129
memObjectForKey2Expectation = [self expectationWithDescription:@"memoryCache objectForKeyAsync - #2"];
1129-
[self.cache.memoryCache objectForKeyAsync:key2 completion:^(PINMemoryCache *cache, NSString *key, id object) {
1130+
[self.cache.memoryCache objectForKeyAsync:key2 completion:^(id<PINCaching> cache, NSString *key, id object) {
11301131
XCTAssertNotNil(object, @"should not be in memory cache");
11311132
[memObjectForKey2Expectation fulfill];
11321133
}];
@@ -1162,7 +1163,7 @@ - (void)testObjectTTLObjectEnumeration
11621163
// Neither object should be expired at this point and should exist in both caches
11631164

11641165
__block NSUInteger objCount = 0;
1165-
[self.cache.memoryCache enumerateObjectsWithBlock:^(PINMemoryCache *cache, NSString *key, id _Nullable object, BOOL *stop) {
1166+
[self.cache.memoryCache enumerateObjectsWithBlock:^(id<PINCaching> cache, NSString *key, id _Nullable object, BOOL *stop) {
11661167
objCount++;
11671168
}];
11681169
XCTAssertEqual(objCount, 2, @"Expected 2 objects, got %tu.", objCount);
@@ -1179,7 +1180,7 @@ - (void)testObjectTTLObjectEnumeration
11791180
// The first object has been expired for 30 seconds and should not exist in the cache anymore.
11801181

11811182
objCount = 0;
1182-
[self.cache.memoryCache enumerateObjectsWithBlock:^(PINMemoryCache *cache, NSString *key, id _Nullable object, BOOL *stop) {
1183+
[self.cache.memoryCache enumerateObjectsWithBlock:^(id<PINCaching> cache, NSString *key, id _Nullable object, BOOL *stop) {
11831184
objCount++;
11841185
}];
11851186
XCTAssertEqual(objCount, 1, @"Expected 1 object, got %tu.", objCount);
@@ -1215,13 +1216,13 @@ - (void)testRemoveExpiredObjects
12151216
[NSDate stopMockingDate];
12161217

12171218
XCTestExpectation *memObjectForKey1Expectation = [self expectationWithDescription:@"memoryCache objectForKeyAsync - #1"];
1218-
[self.cache.memoryCache objectForKeyAsync:key1 completion:^(PINMemoryCache *cache, NSString *key, id object) {
1219+
[self.cache.memoryCache objectForKeyAsync:key1 completion:^(id<PINCaching> cache, NSString *key, id object) {
12191220
XCTAssertNil(object, @"should not be in memory cache");
12201221
[memObjectForKey1Expectation fulfill];
12211222
}];
12221223

12231224
XCTestExpectation *memObjectForKey2Expectation = [self expectationWithDescription:@"memoryCache objectForKeyAsync - #2"];
1224-
[self.cache.memoryCache objectForKeyAsync:key2 completion:^(PINMemoryCache *cache, NSString *key, id object) {
1225+
[self.cache.memoryCache objectForKeyAsync:key2 completion:^(id<PINCaching> cache, NSString *key, id object) {
12251226
XCTAssertNotNil(object, @"should not be in memory cache");
12261227
[memObjectForKey2Expectation fulfill];
12271228
}];
@@ -1347,7 +1348,7 @@ - (void)testDiskCacheEmptyTrash
13471348
}
13481349

13491350
dispatch_group_enter(group);
1350-
[self.cache.diskCache removeAllObjectsAsync:^(PINDiskCache * _Nonnull cache) {
1351+
[self.cache.diskCache removeAllObjectsAsync:^(id<PINCaching> _Nonnull cache) {
13511352
// Temporary directory should be bigger now since the trash directory is still inside it
13521353
NSError *error = nil;
13531354
unsigned long long tempDirSize = [[fileManager attributesOfItemAtPath:trashPath error:&error] fileSize];

0 commit comments

Comments
 (0)