Skip to content

Commit 4d3b9eb

Browse files
committed
Merge pull request #874 from ParsePlatform/nlutsenko.initialize
Add assertion that makes it invalid to initialize Parse twice in a single runtime.
2 parents a037213 + a522675 commit 4d3b9eb

File tree

5 files changed

+13
-30
lines changed

5 files changed

+13
-30
lines changed

Parse/Parse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ NS_ASSUME_NONNULL_BEGIN
107107
/**
108108
The current client key that was used to configure Parse framework.
109109
*/
110-
+ (NSString *)getClientKey;
110+
+ (nullable NSString *)getClientKey;
111111

112112
///--------------------------------------
113113
#pragma mark - Enabling Local Datastore

Parse/Parse.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ + (void)initializeWithConfiguration:(ParseClientConfiguration *)configuration {
7373
configuration.applicationGroupIdentifier == nil ||
7474
configuration.containingApplicationBundleIdentifier != nil,
7575
@"'containingApplicationBundleIdentifier' must be non-nil in extension environment");
76+
PFConsistencyAssert(![self currentConfiguration], @"Parse is already initialized.");
7677

7778
ParseManager *manager = [[ParseManager alloc] initWithConfiguration:configuration];
7879
[manager startManaging];
@@ -104,7 +105,7 @@ + (void)initializeWithConfiguration:(ParseClientConfiguration *)configuration {
104105
[[self parseModulesCollection] parseDidInitializeWithApplicationId:configuration.applicationId clientKey:configuration.clientKey];
105106
}
106107

107-
+ (ParseClientConfiguration *)currentConfiguration {
108+
+ (nullable ParseClientConfiguration *)currentConfiguration {
108109
return currentParseManager_.configuration;
109110
}
110111

@@ -114,7 +115,7 @@ + (NSString *)getApplicationId {
114115
return currentParseManager_.configuration.applicationId;
115116
}
116117

117-
+ (NSString *)getClientKey {
118+
+ (nullable NSString *)getClientKey {
118119
PFConsistencyAssert(currentParseManager_,
119120
@"You have to call setApplicationId:clientKey: on Parse to configure Parse.");
120121
return currentParseManager_.configuration.clientKey;

Tests/Unit/InstallationIdentifierUnitTests.m

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,21 @@
88
*/
99

1010
#import "PFInstallationIdentifierStore_Private.h"
11-
#import "PFTestCase.h"
11+
#import "PFUnitTestCase.h"
1212
#import "Parse_Private.h"
1313
#import "BFTask+Private.h"
1414

15-
@interface InstallationIdentifierUnitTests : PFTestCase
15+
@interface InstallationIdentifierUnitTests : PFUnitTestCase
1616

1717
@end
1818

1919
@implementation InstallationIdentifierUnitTests
2020

21-
///--------------------------------------
22-
#pragma mark - XCTestCase
23-
///--------------------------------------
24-
25-
- (void)tearDown {
26-
[[Parse _currentManager] clearEventuallyQueue];
27-
[[[Parse _currentManager].installationIdentifierStore clearInstallationIdentifierAsync] waitForResult:nil];
28-
[Parse _clearCurrentManager];
29-
30-
[super tearDown];
31-
}
32-
3321
///--------------------------------------
3422
#pragma mark - Tests
3523
///--------------------------------------
3624

3725
- (void)testNewInstallationIdentifierIsLowercase {
38-
[Parse setApplicationId:@"b" clientKey:@"c"];
3926
PFInstallationIdentifierStore *store = [Parse _currentManager].installationIdentifierStore;
4027

4128
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
@@ -51,7 +38,6 @@ - (void)testNewInstallationIdentifierIsLowercase {
5138
}
5239

5340
- (void)testCachedInstallationId {
54-
[Parse setApplicationId:@"b" clientKey:@"c"];
5541
PFInstallationIdentifierStore *store = [Parse _currentManager].installationIdentifierStore;
5642

5743
[[store _clearCachedInstallationIdentifierAsync] waitForResult:nil];

Tests/Unit/InstallationUnitTests.m

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,15 @@
88
*/
99

1010
#import "PFInstallation.h"
11-
#import "PFTestCase.h"
11+
#import "PFUnitTestCase.h"
1212
#import "Parse.h"
1313

14-
@interface InstallationUnitTests : PFTestCase
14+
@interface InstallationUnitTests : PFUnitTestCase
1515

1616
@end
1717

1818
@implementation InstallationUnitTests
1919

20-
+ (void)setUp {
21-
[super setUp];
22-
23-
[Parse setApplicationId:@"a" clientKey:@"a"];
24-
}
25-
2620
- (void)testInstallationImmutableFieldsCannotBeChanged {
2721
PFInstallation *installation = [PFInstallation currentInstallation];
2822
installation.deviceToken = @"11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306";

Tests/Unit/SessionUnitTests.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#import "PFSession_Private.h"
1616
#import "PFUnitTestCase.h"
1717
#import "Parse_Private.h"
18+
#import "PFObjectSubclassingController.h"
1819

1920
@interface SessionUnitTests : PFUnitTestCase
2021

@@ -44,12 +45,13 @@ - (PFSessionController *)sessionControllerMockWithSessionResult:(PFSession *)ses
4445
///--------------------------------------
4546

4647
- (void)testSessionClassIsRegistered {
48+
[[Parse _currentManager] clearEventuallyQueue];
49+
[Parse _clearCurrentManager];
50+
[PFObjectSubclassingController clearDefaultController];
51+
4752
[PFObject unregisterSubclass:[PFSession class]];
4853
[Parse setApplicationId:@"a" clientKey:@"b"];
4954
XCTAssertNotNil([PFSession query]);
50-
51-
[[Parse _currentManager] clearEventuallyQueue];
52-
[Parse _clearCurrentManager];
5355
}
5456

5557
- (void)testConstructorsClassNameValidation {

0 commit comments

Comments
 (0)