FIRFakeApp.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "FIRFakeApp.h"
  17. #import "FIRAuthInteropFake.h"
  18. #import "FIRComponentTestUtilities.h"
  19. #import "FIRDatabaseComponent.h"
  20. @interface FIRFakeOptions: NSObject
  21. @property(nonatomic, readonly, copy) NSString *databaseURL;
  22. - (instancetype)initWithURL:(NSString *)url;
  23. @end
  24. @implementation FIRFakeOptions
  25. - (instancetype)initWithURL:(NSString *)url {
  26. self = [super init];
  27. if (self) {
  28. _databaseURL = url;
  29. }
  30. return self;
  31. }
  32. @end
  33. @interface FIRDatabaseComponent (Internal)
  34. - (instancetype)initWithApp:(FIRApp *)app;
  35. @end
  36. @implementation FIRFakeApp
  37. - (instancetype)initWithName:(NSString *)name URL:(NSString *)url {
  38. self = [super init];
  39. if (self) {
  40. _name = name;
  41. _options = [[FIRFakeOptions alloc] initWithURL:url];
  42. _Nullable id (^authBlock)(FIRComponentContainer *, BOOL *) =
  43. ^(FIRComponentContainer *container, BOOL *isCacheable) {
  44. return [[FIRAuthInteropFake alloc] initWithToken:nil userID:nil error:nil];
  45. };
  46. FIRComponentCreationBlock databaseBlock =
  47. ^id _Nullable(FIRComponentContainer *container, BOOL *isCacheable) {
  48. *isCacheable = YES;
  49. return [[FIRDatabaseComponent alloc] initWithApp:container.app];
  50. };
  51. NSDictionary<NSString *, FIRComponentCreationBlock> *components =
  52. @{NSStringFromProtocol(@protocol(FIRAuthInterop)) : authBlock,
  53. NSStringFromProtocol(@protocol(FIRDatabaseProvider)) : databaseBlock};
  54. _container = [[FIRComponentContainer alloc] initWithApp:(FIRApp *)self components:components];
  55. }
  56. return self;
  57. }
  58. @end