Skip to content

FlipMock is a extended Flipper plugin that manipulates network response.

License

Notifications You must be signed in to change notification settings

enciyo/FlipMockiOS

Repository files navigation

logo

FlipMock

FlipMock is a extended Flipper plugin that manipulates network response.

Table of Contents

SDK Features

  • Support Alomofire
  • Mock the response by HTTP method.
  • Mock the response by query parameters.
  • For response, support HTTP code
  • Support Moya

Installation

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate FlipMock into your Xcode project using CocoaPods, specify it in your Podfile:

# ...
# Flipper integration
#  ...
pod 'FlipperMockPlugin', :git => 'https://github.com/enciyo/FlipMockiOS', :tag => 'v1.0.4'

How to adding Flipper to IOS apps?

Using FlipMock

AppDelegate

import UIKit
import FlipperMockPlugin
import FlipperKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        let client = FlipperClient.shared() // from FlipperKit
        //...
        client?.add(FlipMock.plugin)
        //...
        client?.start()
        return true
    }

Making Simple Request (Not recomended for production)

FM.request("https://httpbin.org/get").response { response in
    debugPrint(response)
}

Recomended Usage

    private lazy var session : Session = {
        #if DEBUG
        return FM //FlipMock
        #endif
        return AF //Alomofire
    }()
    
    func fetch(onSuccess : @escaping (String?) -> Void){
        self.session.request("https://httpbin.org/get").response { response in
    			debugPrint(response)
		}
    }

If you need customize your session

 private lazy var customMockSession: Session = {
             let configuration: URLSessionConfiguration = {
                 let configuration = URLSessionConfiguration.af.default
                 //@Warning => [FlipMockUrlProtocol.self] should be first
                 let safeProtocolClasses = [FlipMockUrlProtocol.self] + (configuration.protocolClasses ?? [])
                 configuration.protocolClasses = safeProtocolClasses
                 return configuration}()
         return Session(configuration:configuration)}()

Warning

FlipMockUrlProtocol should be first

let safeProtocolClasses = [FlipMockUrlProtocol.self] + (configuration.protocolClasses ?? [])

How can I mock the response?

In this section, you can mock response using FlipMock desktop Plugin on the Flipper.

How to use FlipMock Desktop Plugin?

About

FlipMock is a extended Flipper plugin that manipulates network response.

Resources

License

Stars

Watchers

Forks

Packages

No packages published