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).
  • Loading branch information
mvanbeusekom committed Feb 7, 2022
1 parent f7138f7 commit 441dea1
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/image_picker/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.8.4+7

* Refactores unit test to expose private interface via a separate test header instead of the inline declaration.

## 0.8.4+6

* Fixes minor type issues in iOS implementation.
Expand Down
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 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 Down Expand Up @@ -30,8 +31,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:(NSArray *)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
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for selecting images from the Android and iOS image
library, and taking new pictures with the camera.
repository: https://github.com/flutter/plugins/tree/main/packages/image_picker/image_picker
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
version: 0.8.4+6
version: 0.8.4+7

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down

0 comments on commit 441dea1

Please sign in to comment.