Skip to content

Commit

Permalink
Allow subclassing the MockingURLProtocol, fallback for HTTP Body (#109)
Browse files Browse the repository at this point in the history
* Allow subclassing the MockingURLProtocol, fallback for HTTP Body

* Update CI

* Fix building for SwiftLint phase

* Fix Danger

* Fix Danger
  • Loading branch information
AvdLee authored Nov 23, 2021
1 parent fdfa7cb commit 077c52a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
14 changes: 8 additions & 6 deletions Mocker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0830;
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1320;
ORGANIZATIONNAME = WeTransfer;
TargetAttributes = {
501E26931F3DAE370048F39E = {
Expand Down Expand Up @@ -259,7 +259,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "./Submodules/WeTransfer-iOS-CI/SwiftLint/swiftlint.sh\n";
shellScript = "./Submodules/WeTransfer-iOS-CI/BuildTools/swiftlint.sh\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down Expand Up @@ -321,6 +321,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand All @@ -346,7 +347,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -385,6 +386,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand All @@ -404,7 +406,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand All @@ -430,7 +432,7 @@
);
INFOPLIST_FILE = "Mocker/Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.wetransfer.Mocker;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -453,7 +455,7 @@
);
INFOPLIST_FILE = "Mocker/Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.wetransfer.Mocker;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
2 changes: 1 addition & 1 deletion Mocker.xcodeproj/xcshareddata/xcschemes/Mocker.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1320"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
11 changes: 7 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.1
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.
// We're hiding dev, test, and danger dependencies with // dev to make sure they're not fetched by users of this package.

Expand All @@ -15,11 +15,14 @@ let package = Package(name: "Mocker",
.library(name: "Mocker", targets: ["Mocker"])
],
dependencies: [
// dev .package(url: "https://github.com/danger/swift", from: "3.0.0"),
// dev .package(path: "Submodules/WeTransfer-iOS-CI/Danger-Swift")
// dev .package(name: "danger-swift", url: "https://github.com/danger/swift", from: "3.12.1"),
// dev .package(name: "WeTransferPRLinter", path: "Submodules/WeTransfer-iOS-CI/WeTransferPRLinter")
],
targets: [
// dev .target(name: "DangerDependencies", dependencies: ["Danger", "WeTransferPRLinter"], path: "Submodules/WeTransfer-iOS-CI/Danger-Swift", sources: ["DangerFakeSource.swift"]),
// dev .target(name: "DangerDependencies", dependencies: [
// dev .product(name: "Danger", package: "danger-swift"),
// dev .product(name: "WeTransferPRLinter", package: "WeTransferPRLinter")
// dev ], path: "Submodules/WeTransfer-iOS-CI/DangerFakeSources", sources: ["DangerFakeSource.swift"]),
.target(name: "Mocker", path: "Sources"),
.testTarget(name: "MockerTests", dependencies: ["Mocker"], path: "MockerTests")
],
Expand Down
4 changes: 2 additions & 2 deletions Sources/MockingURLProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

/// The protocol which can be used to send Mocked data back. Use the `Mocker` to register `Mock` data
public final class MockingURLProtocol: URLProtocol {
open class MockingURLProtocol: URLProtocol {

enum Error: Swift.Error, LocalizedError, CustomDebugStringConvertible {
case missingMockedData(url: String)
Expand Down Expand Up @@ -108,7 +108,7 @@ private extension Data {

private extension URLRequest {
var postBodyArguments: [String: Any]? {
guard let httpBody = httpBodyStreamData() else { return nil }
guard let httpBody = httpBodyStreamData() ?? httpBody else { return nil }
return try? JSONSerialization.jsonObject(with: httpBody, options: .fragmentsAllowed) as? [String: Any]
}

Expand Down
2 changes: 1 addition & 1 deletion Submodules/WeTransfer-iOS-CI
Submodule WeTransfer-iOS-CI updated 185 files

0 comments on commit 077c52a

Please sign in to comment.