Skip to content

Commit f963f12

Browse files
committed
Refactored tests to expose private interface in separate test header.
Refactored the existing unit tests to expose private interfaces in a separate test header instead of an inline interface. This was first introduced in the google_sign_in plugin (flutter#4157) and after that also applied in the camera plugin (flutter#4426) and the webview_flutter plugin (flutter#4480). This commit also removed several obsolete `OCMStub` declarations.
1 parent a5b97ea commit f963f12

File tree

6 files changed

+40
-25
lines changed

6 files changed

+40
-25
lines changed

packages/image_picker/image_picker/example/ios/RunnerTests/ImagePickerPluginTests.m

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#import "ImagePickerTestImages.h"
66

77
@import image_picker;
8+
@import image_picker.Test;
89
@import XCTest;
910
#import <OCMock/OCMock.h>
1011

@@ -21,12 +22,6 @@ - (UIViewController *)presentedViewController {
2122

2223
@end
2324

24-
@interface FLTImagePickerPlugin (Test)
25-
@property(copy, nonatomic) FlutterResult result;
26-
- (void)handleSavedPathList:(NSMutableArray *)pathList;
27-
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
28-
@end
29-
3025
@interface ImagePickerPluginTests : XCTestCase
3126
@property(readonly, nonatomic) id mockUIImagePicker;
3227
@property(readonly, nonatomic) id mockAVCaptureDevice;
@@ -50,10 +45,6 @@ - (void)testPluginPickImageDeviceBack {
5045
[_mockUIImagePicker isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]))
5146
.andReturn(YES);
5247

53-
// AVAuthorizationStatusAuthorized is supported
54-
OCMStub([_mockAVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo])
55-
.andReturn(AVAuthorizationStatusAuthorized);
56-
5748
// Run test
5849
FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new];
5950
FlutterMethodCall *call =
@@ -78,10 +69,6 @@ - (void)testPluginPickImageDeviceFront {
7869
isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]))
7970
.andReturn(YES);
8071

81-
// AVAuthorizationStatusAuthorized is supported
82-
OCMStub([_mockAVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo])
83-
.andReturn(AVAuthorizationStatusAuthorized);
84-
8572
// Run test
8673
FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new];
8774
FlutterMethodCall *call =
@@ -106,10 +93,6 @@ - (void)testPluginPickVideoDeviceBack {
10693
[_mockUIImagePicker isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]))
10794
.andReturn(YES);
10895

109-
// AVAuthorizationStatusAuthorized is supported
110-
OCMStub([_mockAVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo])
111-
.andReturn(AVAuthorizationStatusAuthorized);
112-
11396
// Run test
11497
FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new];
11598
FlutterMethodCall *call =
@@ -134,10 +117,6 @@ - (void)testPluginPickVideoDeviceFront {
134117
isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]))
135118
.andReturn(YES);
136119

137-
// AVAuthorizationStatusAuthorized is supported
138-
OCMStub([_mockAVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo])
139-
.andReturn(AVAuthorizationStatusAuthorized);
140-
141120
// Run test
142121
FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new];
143122
FlutterMethodCall *call =

packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
#import "FLTImagePickerPlugin.h"
6+
#import "FLTImagePickerPlugin_Test.h"
67

78
#import <AVFoundation/AVFoundation.h>
89
#import <MobileCoreServices/MobileCoreServices.h>
@@ -21,8 +22,6 @@ @interface FLTImagePickerPlugin () <UINavigationControllerDelegate,
2122
PHPickerViewControllerDelegate,
2223
UIAdaptivePresentationControllerDelegate>
2324

24-
@property(copy, nonatomic) FlutterResult result;
25-
2625
@property(assign, nonatomic) int maxImagesAllowed;
2726

2827
@property(copy, nonatomic) NSDictionary *arguments;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// This header is available in the Test module. Import via "@import image_picker.Test;"
6+
7+
#import <image_picker/FLTImagePickerPlugin.h>
8+
9+
/// Methods exposed for unit testing.
10+
@interface FLTImagePickerPlugin ()
11+
12+
@property(copy, nonatomic) FlutterResult result;
13+
- (void)handleSavedPathList:(NSMutableArray *)pathList;
14+
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
15+
16+
@end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
framework module image_picker {
2+
umbrella header "image_picker-umbrella.h"
3+
4+
export *
5+
module * { export * }
6+
7+
explicit module Test {
8+
header "FLTImagePickerPlugin_Test.h"
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import <Foundation/Foundation.h>
6+
#import <image_picker/FLTImagePickerImageUtil.h>
7+
#import <image_picker/FLTImagePickerMetaDataUtil.h>
8+
#import <image_picker/FLTImagePickerPhotoAssetUtil.h>
9+
#import <image_picker/FLTImagePickerPlugin.h>
10+
#import <image_picker/FLTPHPickerSaveImageToPathOperation.h>

packages/image_picker/image_picker/ios/image_picker.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ Downloaded by pub (not CocoaPods).
1414
s.author = { 'Flutter Dev Team' => '[email protected]' }
1515
s.source = { :http => 'https://github.com/flutter/plugins/tree/main/packages/image_picker' }
1616
s.documentation_url = 'https://pub.dev/packages/image_picker'
17-
s.source_files = 'Classes/**/*'
17+
s.source_files = 'Classes/**/*.{h,m}'
1818
s.public_header_files = 'Classes/**/*.h'
19+
s.module_map = 'Classes/ImagePickerPlugin.modulemap'
1920
s.dependency 'Flutter'
2021
s.platform = :ios, '9.0'
2122
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }

0 commit comments

Comments
 (0)