Skip to content

Commit

Permalink
Refactored tests to expose private interface in separate test header.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mvanbeusekom committed Feb 2, 2022
1 parent a5b97ea commit f963f12
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "ImagePickerTestImages.h"

@import image_picker;
@import image_picker.Test;
@import XCTest;
#import <OCMock/OCMock.h>

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

@end

@interface FLTImagePickerPlugin (Test)
@property(copy, nonatomic) FlutterResult result;
- (void)handleSavedPathList:(NSMutableArray *)pathList;
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
@end

@interface ImagePickerPluginTests : XCTestCase
@property(readonly, nonatomic) id mockUIImagePicker;
@property(readonly, nonatomic) id mockAVCaptureDevice;
Expand All @@ -50,10 +45,6 @@ - (void)testPluginPickImageDeviceBack {
[_mockUIImagePicker isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]))
.andReturn(YES);

// AVAuthorizationStatusAuthorized is supported
OCMStub([_mockAVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo])
.andReturn(AVAuthorizationStatusAuthorized);

// Run test
FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new];
FlutterMethodCall *call =
Expand All @@ -78,10 +69,6 @@ - (void)testPluginPickImageDeviceFront {
isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]))
.andReturn(YES);

// AVAuthorizationStatusAuthorized is supported
OCMStub([_mockAVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo])
.andReturn(AVAuthorizationStatusAuthorized);

// Run test
FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new];
FlutterMethodCall *call =
Expand All @@ -106,10 +93,6 @@ - (void)testPluginPickVideoDeviceBack {
[_mockUIImagePicker isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]))
.andReturn(YES);

// AVAuthorizationStatusAuthorized is supported
OCMStub([_mockAVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo])
.andReturn(AVAuthorizationStatusAuthorized);

// Run test
FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new];
FlutterMethodCall *call =
Expand All @@ -134,10 +117,6 @@ - (void)testPluginPickVideoDeviceFront {
isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]))
.andReturn(YES);

// AVAuthorizationStatusAuthorized is supported
OCMStub([_mockAVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo])
.andReturn(AVAuthorizationStatusAuthorized);

// Run test
FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new];
FlutterMethodCall *call =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

#import "FLTImagePickerPlugin.h"
#import "FLTImagePickerPlugin_Test.h"

#import <AVFoundation/AVFoundation.h>
#import <MobileCoreServices/MobileCoreServices.h>
Expand All @@ -21,8 +22,6 @@ @interface FLTImagePickerPlugin () <UINavigationControllerDelegate,
PHPickerViewControllerDelegate,
UIAdaptivePresentationControllerDelegate>

@property(copy, nonatomic) FlutterResult result;

@property(assign, nonatomic) int maxImagesAllowed;

@property(copy, nonatomic) NSDictionary *arguments;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This header is available in the Test module. Import via "@import image_picker.Test;"

#import <image_picker/FLTImagePickerPlugin.h>

/// Methods exposed for unit testing.
@interface FLTImagePickerPlugin ()

@property(copy, nonatomic) FlutterResult result;
- (void)handleSavedPathList:(NSMutableArray *)pathList;
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
framework module image_picker {
umbrella header "image_picker-umbrella.h"

export *
module * { export * }

explicit module Test {
header "FLTImagePickerPlugin_Test.h"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import <Foundation/Foundation.h>
#import <image_picker/FLTImagePickerImageUtil.h>
#import <image_picker/FLTImagePickerMetaDataUtil.h>
#import <image_picker/FLTImagePickerPhotoAssetUtil.h>
#import <image_picker/FLTImagePickerPlugin.h>
#import <image_picker/FLTPHPickerSaveImageToPathOperation.h>
3 changes: 2 additions & 1 deletion packages/image_picker/image_picker/ios/image_picker.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ Downloaded by pub (not CocoaPods).
s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' }
s.source = { :http => 'https://github.com/flutter/plugins/tree/main/packages/image_picker' }
s.documentation_url = 'https://pub.dev/packages/image_picker'
s.source_files = 'Classes/**/*'
s.source_files = 'Classes/**/*.{h,m}'
s.public_header_files = 'Classes/**/*.h'
s.module_map = 'Classes/ImagePickerPlugin.modulemap'
s.dependency 'Flutter'
s.platform = :ios, '9.0'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
Expand Down

0 comments on commit f963f12

Please sign in to comment.