Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5fe3b34
Moved nested .framework dir to replace the high level .framework dire…
doanceaep Apr 28, 2016
2f7d480
Merge pull request #5 from doancea/release-fix
joshmg Jul 27, 2016
7f7e498
New mocker styles to support swift 3; also nimble extensions
keitzer Feb 23, 2017
03d6718
Merge pull request #6 from keitzer/master
joshmg Feb 23, 2017
f3c1dd8
MOBEE-1075: Add shared data
doancea-wiser Jan 28, 2022
0a8e539
MOBEE-1075: Renaming
doancea-wiser Jan 28, 2022
b5d89db
MOBEE-1075: Streamlining library for mocking only
doancea-wiser Jan 28, 2022
0a744f5
Merge branch 'master' of github.com:PillarTechnology/swiftlibs into M…
doancea-wiser Jan 28, 2022
0e744f4
MOBEE-1075: re-add matchers to project
doancea-wiser Jan 28, 2022
7e3bdd1
MOBEE-1075: Streamline project to contain mocks only, added nimble as…
doancea-wiser Jan 28, 2022
d322ba0
MOBEE-1075: MockedMethod naming support added to replace raw strings
doancea-wiser Jan 28, 2022
ce7a0ec
MOBEE-1075: Recommended project settings
doancea-wiser Jan 28, 2022
a56ac4c
MOBEE-1075: Begin converting deprecated matcherfunc nimble matchers
doancea-wiser Jan 28, 2022
3c28c7d
MOBEE-1075: Renamed
doancea-wiser Jan 28, 2022
d4f7827
MOBEE-1075: Converted all custom matchers
doancea-wiser Jan 28, 2022
dda7307
MOBEE-1075: Comments
doancea-wiser Jan 28, 2022
7fc47b7
Project cleanup and package structure
doancea-wiser Jan 28, 2022
8343165
MOBEE-1075: Package updates
doancea-wiser Jan 31, 2022
2624059
Merge pull request #1 from WiserSolutions/MOBEE-1075
doancea-wiser Jan 31, 2022
8343fc2
MOBEE-1075: not sure but looks helpful
doancea-wiser Jan 31, 2022
07a02e2
MOBEE-1075: rename target to match package specification
doancea-wiser Feb 2, 2022
d90cfcc
MOBEE-1975: remove test target, troubleshooting
doancea-wiser Feb 2, 2022
dfa9787
MOBEE-1075: Syntax
doancea-wiser Feb 2, 2022
921d92b
MOBEE-1075: Packgage troubleshooting
doancea-wiser Feb 2, 2022
544f804
MOBEE-1075: Packgage troubleshooting
doancea-wiser Feb 2, 2022
273b8c3
MOBEE-1075: Package declaration location
doancea-wiser Feb 2, 2022
d95486c
Merge pull request #2 from WiserSolutions/MOBEE-1075
doancea-wiser Feb 2, 2022
c6266e5
MOBEE-905: Created global mocker method to simplify mock return value…
doancea-wiser Feb 10, 2022
5014a84
Merge pull request #3 from WiserSolutions/MOBEE-905
doancea-wiser Feb 11, 2022
07e22f6
MOBEE-905: Missing default value for first parameter
doancea-wiser Feb 11, 2022
b172b31
MOBEE-952: added global convienience method for resetting a mock's in…
doancea-wiser Feb 22, 2022
5983e0c
MOBEE-952: Mockable can only be used as a generic type because it has…
doancea-wiser Feb 22, 2022
648f56b
MOBEE-946: Remove UIKit import, unnecessary
doancea-wiser Feb 25, 2022
1327264
MOBEE-946: Remove UIKit import, unnecessary
doancea-wiser Feb 25, 2022
c8dc09a
MOBEE-1025: Migrate DI into package from the app project
doancea-wiser Mar 4, 2022
984ba10
MOBEE-1329: Added date same day matcher predicate
doancea-wiser May 17, 2022
78f7ec0
Merge branch 'main' of github.com:WiserSolutions/WiseMock into MOBEE-952
doancea-wiser May 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

43 changes: 43 additions & 0 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "wiser-ios-utils",
platforms: [
.macOS(.v10_10), .iOS(.v12)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "WiseMock",
targets: ["WiseMock"]
),
.library(
name: "DIWise",
targets: ["DIWise"]
),
],
dependencies: [
.package(url: "https://github.com/Quick/Nimble.git", from: "9.2.1"),
.package(url: "https://github.com/Quick/Quick.git", from: "5.0.1"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "WiseMock",
dependencies: [
.product(name: "Nimble", package: "Nimble",
condition: .when(platforms: [.macOS, .iOS])),
]
),
.testTarget(
name: "WiseMockTests",
dependencies: [ "Quick", "Nimble", "WiseMock" ]
),
.target(
name: "DIWise"
)

]
)
34 changes: 0 additions & 34 deletions README
Original file line number Diff line number Diff line change
@@ -1,34 +0,0 @@
This framework provides:
- iOS Mocker
- WebRequest
- HTTP MultiPart
- HTTP Methods (ex. GET/POST/PUT/etc)
- HTTP-Redirection
- Mock WebRequest
- Util Functions
- DataFromHexString
- SplitString

IMPORTANT:
This project contains two frameworks, one for development and another for production.
The production version is portable to the Apple App Store, but is incompatible with iOS-Simulators.
The development version is compatible with both iOS-Devices and the iOS-Simulators, but is NOT compatible with the Apple App Store.


Build:
Development (Non App Store):
1. Select the "SwiftLibsFramework" project from the target-menu.
2. Select any non-generic simulator from the build-target. (i.e. "iPhone 5s")
3. Copy the built framework from bin/development into your project's directory.
4. Add the framework as an embedded-binary into your application.
Production (App Store):
1. Select the "SwiftLibsFrameworkProduction" project from the target-menu.
2. Select any the generic simulator from the build-target. (i.e. "Generic iOS Device")
3. Copy the built framework from bin/production into your project's directory.
4. Add the framework as an embedded-binary into your application.


Pre-Built Binaries:
Located:
./release/<version>/

29 changes: 29 additions & 0 deletions Sources/DIWise/DIConfigurator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// DIConfigurator.swift
// mobee
//
// Created by Daniel Oancea on 2/8/22.
//

import Foundation
import Segment
import UIKit
import CoreLocation

@objcMembers
public open class DIConfigurator: NSObject {

private static let container: DIContainerProtocol = DIContainer.shared

public static func configuredComponentSingleton<Component>(_ type: Component.Type, factory: () -> Component) -> Component {
if let it = container.resolve(type: type) {
return it
} else {
let it = factory()

container.register(type: type, component: it)

return it
}
}
}
35 changes: 35 additions & 0 deletions Sources/DIWise/DIContainer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// DIContainer.swift
// mobee
//
// Created by Daniel Oancea on 2/8/22.

/**
Dependency Injection approach originally taken from here:
https://www.raywenderlich.com/14223279-dependency-injection-tutorial-for-ios-getting-started

Testing this out as a solution to DI for iOS, which is very helpful in writing testable code
*/

import Foundation

protocol DIContainerProtocol {
func register<Component>(type: Component.Type, component: Any)
func resolve<Component>(type: Component.Type) -> Component?
}

final class DIContainer: DIContainerProtocol {
static let shared = DIContainer()

private init() {}

var components: [String: Any] = [:]

func register<Component>(type: Component.Type, component: Any) {
components["\(type)"] = component
}

func resolve<Component>(type: Component.Type) -> Component? {
return components["\(type)"] as? Component
}
}
7 changes: 7 additions & 0 deletions Sources/WiseMock/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0.5</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
36 changes: 36 additions & 0 deletions Sources/WiseMock/Matchers/DateMatchers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// File.swift
//
//
// Created by Daniel Oancea on 5/17/22.
//

import Foundation
import Nimble


public func beTheSameDayAs(_ expectedDate: Date) -> Predicate<Date> {
return Predicate<Date>.define { actualExpression in
var expectationMessage: ExpectationMessage!
var status: PredicateStatus!

if let actualDate = try? actualExpression.evaluate() {
let actualMessage = String(describing: actualDate)

expectationMessage = .expectedActualValueTo(actualMessage)


status = PredicateStatus(bool: isSameDay(date1: actualDate, date2: expectedDate))
} else {
status = .fail
expectationMessage = .fail("something else happened")
}
return PredicateResult(status: status, message: expectationMessage)
}
}

fileprivate func isSameDay(date1: Date, date2: Date) -> Bool {
let diff = Calendar.current.dateComponents([.year, .month, .day], from: date1, to: date2)

return diff.day == 0 && diff.month == 0 && diff.year == 0
}
83 changes: 83 additions & 0 deletions Sources/WiseMock/Matchers/NimbleMatchers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import Foundation
import Nimble

///Invocation Count
public func invoke<T: Mockable>(_ name: T.MockedMethod, times: Int = 1) -> Predicate<T> {

return Predicate<T>.define { actualExpression in
var expectationMessage: ExpectationMessage!
var status: PredicateStatus!

if let mockable = try? actualExpression.evaluate() {
let failureExpectationMessage = "invoke \(name) \(times) times"
let actualMessage = "\(mockable.invocationCount(for: name)) invocations"
status = PredicateStatus(bool: mockable.invocationCount(for: name) == times)
expectationMessage = .expectedCustomValueTo(failureExpectationMessage, actual: actualMessage)
} else {
status = .fail
expectationMessage = .fail("something else happened")
}
return PredicateResult(status: status, message: expectationMessage)
}

}

///Equality
public func invoke<T: Mockable, E: Equatable>(_ name: T.MockedMethod, atInvocation invocationIndex: Int = 0, withParameter parameter: E?, at parameterIndex: Int = 0) -> Predicate<T> {
return Predicate<T>.define { actualExpression in
var expectationMessage: ExpectationMessage!
var status: PredicateStatus!

if let mockable = try? actualExpression.evaluate() {
let actualParameter: E? = mockable.parameter(for: name, at: parameterIndex, andInvocation: invocationIndex)
let actualMessage = String(describing: actualParameter)

expectationMessage = .expectedActualValueTo(actualMessage)
status = PredicateStatus(bool: actualParameter == parameter)
} else {
status = .fail
expectationMessage = .fail("something else happened")
}
return PredicateResult(status: status, message: expectationMessage)
}

}

///Identity
public func invoke<T: Mockable, E: AnyObject>(_ name: T.MockedMethod, atInvocation invocationIndex: Int = 0, withIdenticalParameter parameter: E?, at parameterIndex: Int = 0) -> Predicate<T> {
return Predicate<T>.define { actualExpression in
var expectationMessage: ExpectationMessage!
var status: PredicateStatus!

if let mockable = try? actualExpression.evaluate() {
let actualParameter: E? = mockable.parameter(for: name, at: parameterIndex, andInvocation: invocationIndex)
let actualMessage = String(describing: actualParameter)

expectationMessage = .expectedActualValueTo(actualMessage)
status = PredicateStatus(bool: actualParameter === parameter)
} else {
status = .fail
expectationMessage = .fail("something else happened")
}
return PredicateResult(status: status, message: expectationMessage)
}
}

/// Closure Matcher
public func invoke<T: Mockable, U>(_ name: T.MockedMethod, atInvocation invocationIndex: Int = 0, atParameterIndex parameterIndex: Int = 0, withMatcher matcher: @escaping ((U?) -> Bool)) -> Predicate<T> {
return Predicate<T>.define { actualExpression in
var expectationMessage: ExpectationMessage!
var status: PredicateStatus!

if let mockable = try? actualExpression.evaluate() {
let actualParameter: U? = mockable.parameter(for: name, at: parameterIndex, andInvocation: invocationIndex)

expectationMessage = .fail("parameter as \(String(describing: actualParameter)) does not match")
status = PredicateStatus(bool: matcher(actualParameter))
} else {
status = .fail
expectationMessage = .fail("something else happened")
}
return PredicateResult(status: status, message: expectationMessage)
}
}
Loading