Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #49 from jinSasaki/divide-stub-framework
Browse files Browse the repository at this point in the history
Divide stub framework
  • Loading branch information
jinSasaki authored Dec 10, 2020
2 parents 19fae69 + d581ce5 commit c2f31f1
Show file tree
Hide file tree
Showing 32 changed files with 577 additions and 211 deletions.
236 changes: 211 additions & 25 deletions InAppPurchase.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1170"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "93396AD925825467006ABE59"
BuildableName = "InAppPurchaseStubs.framework"
BlueprintName = "InAppPurchaseStubs"
ReferencedContainer = "container:InAppPurchase.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "93396AE125825467006ABE59"
BuildableName = "InAppPurchaseStubsTests.xctest"
BlueprintName = "InAppPurchaseStubsTests"
ReferencedContainer = "container:InAppPurchase.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "93396AD925825467006ABE59"
BuildableName = "InAppPurchaseStubs.framework"
BlueprintName = "InAppPurchaseStubs"
ReferencedContainer = "container:InAppPurchase.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
onlyGenerateCoverageForSpecifiedTargets = "YES">
<CodeCoverageTargets>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "938BFA6F1F5E8411006A4C2A"
BuildableName = "InAppPurchase.framework"
BlueprintName = "InAppPurchase"
ReferencedContainer = "container:InAppPurchase.xcodeproj">
</BuildableReference>
</CodeCoverageTargets>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -24,8 +34,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -37,8 +45,6 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
19 changes: 19 additions & 0 deletions InAppPurchaseStubs/InAppPurchaseStubs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// InAppPurchaseStubs.h
// InAppPurchaseStubs
//
// Created by Jin Sasaki on 2020/12/10.
// Copyright © 2020 Jin Sasaki. All rights reserved.
//

#import <Foundation/Foundation.h>

//! Project version number for InAppPurchaseStubs.
FOUNDATION_EXPORT double InAppPurchaseStubsVersionNumber;

//! Project version string for InAppPurchaseStubs.
FOUNDATION_EXPORT const unsigned char InAppPurchaseStubsVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <InAppPurchaseStubs/PublicHeader.h>


22 changes: 22 additions & 0 deletions InAppPurchaseStubs/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Copyright © 2017年 Jin Sasaki. All rights reserved.
//

@testable import InAppPurchase
import InAppPurchase

final class StubInAppPurchase: InAppPurchaseProvidable {
public final class StubInAppPurchase: InAppPurchaseProvidable {
private let _canMakePayments: Bool
private let _setShouldAddStorePayementHandler: ((_ shouldAddStorePaymentHandler: ((Product) -> Bool)?, _ handler: InAppPurchase.PurchaseHandler?) -> Void)?
private let _addTransactionObserverHandler: ((_ fallbackHandler: InAppPurchase.PurchaseHandler?) -> Void)?
Expand All @@ -18,14 +18,14 @@ final class StubInAppPurchase: InAppPurchaseProvidable {
private let _purchaseHandler: ((_ productIdentifier: String, _ handler: InAppPurchase.PurchaseHandler?) -> Void)?
private let _receiptRefreshHandler: ((_ handler: InAppPurchase.ReceiptRefreshHandler?) -> Void)?

init(canMakePayments: Bool = true,
setShouldAddStorePayementHandler: ((_ shouldAddStorePaymentHandler: ((Product) -> Bool)?, _ handler: InAppPurchase.PurchaseHandler?) -> Void)? = nil,
addTransactionObserverHandler: ((_ fallbackHandler: InAppPurchase.PurchaseHandler?) -> Void)? = nil,
removeTransactionObserverHandler: (() -> Void)? = nil,
fetchProductHandler: ((_ productIdentifiers: Set<String>, _ handler: ((_ result: Result<[Product], InAppPurchase.Error>) -> Void)?) -> Void)? = nil,
restoreHandler: ((_ handler: ((_ result: Result<Set<String>, InAppPurchase.Error>) -> Void)?) -> Void)? = nil,
purchaseHandler: ((_ productIdentifier: String, _ handler: InAppPurchase.PurchaseHandler?) -> Void)? = nil,
refreshReceiptHandler: ((_ handler: InAppPurchase.ReceiptRefreshHandler?) -> Void)? = nil) {
public init(canMakePayments: Bool = true,
setShouldAddStorePayementHandler: ((_ shouldAddStorePaymentHandler: ((Product) -> Bool)?, _ handler: InAppPurchase.PurchaseHandler?) -> Void)? = nil,
addTransactionObserverHandler: ((_ fallbackHandler: InAppPurchase.PurchaseHandler?) -> Void)? = nil,
removeTransactionObserverHandler: (() -> Void)? = nil,
fetchProductHandler: ((_ productIdentifiers: Set<String>, _ handler: ((_ result: Result<[Product], InAppPurchase.Error>) -> Void)?) -> Void)? = nil,
restoreHandler: ((_ handler: ((_ result: Result<Set<String>, InAppPurchase.Error>) -> Void)?) -> Void)? = nil,
purchaseHandler: ((_ productIdentifier: String, _ handler: InAppPurchase.PurchaseHandler?) -> Void)? = nil,
refreshReceiptHandler: ((_ handler: InAppPurchase.ReceiptRefreshHandler?) -> Void)? = nil) {

self._canMakePayments = canMakePayments
self._setShouldAddStorePayementHandler = setShouldAddStorePayementHandler
Expand All @@ -37,35 +37,35 @@ final class StubInAppPurchase: InAppPurchaseProvidable {
self._receiptRefreshHandler = refreshReceiptHandler
}

func canMakePayments() -> Bool {
public func canMakePayments() -> Bool {
return _canMakePayments
}

func set(shouldAddStorePaymentHandler: ((Product) -> Bool)?, handler: InAppPurchase.PurchaseHandler?) {
public func set(shouldAddStorePaymentHandler: ((Product) -> Bool)?, handler: InAppPurchase.PurchaseHandler?) {
_setShouldAddStorePayementHandler?(shouldAddStorePaymentHandler, handler)
}

func addTransactionObserver(fallbackHandler: InAppPurchase.PurchaseHandler?) {
public func addTransactionObserver(fallbackHandler: InAppPurchase.PurchaseHandler?) {
_addTransactionObserverHandler?(fallbackHandler)
}

func removeTransactionObserver() {
public func removeTransactionObserver() {
_removeTransactionObserverHandler?()
}

func fetchProduct(productIdentifiers: Set<String>, handler: ((_ result: Result<[Product], InAppPurchase.Error>) -> Void)?) {
public func fetchProduct(productIdentifiers: Set<String>, handler: ((_ result: Result<[Product], InAppPurchase.Error>) -> Void)?) {
_fetchProductHandler?(productIdentifiers, handler)
}

func restore(handler: ((_ result: Result<Set<String>, InAppPurchase.Error>) -> Void)?) {
public func restore(handler: ((_ result: Result<Set<String>, InAppPurchase.Error>) -> Void)?) {
_restoreHandler?(handler)
}

func purchase(productIdentifier: String, handler: InAppPurchase.PurchaseHandler?) {
public func purchase(productIdentifier: String, handler: InAppPurchase.PurchaseHandler?) {
_purchaseHandler?(productIdentifier, handler)
}

func refreshReceipt(handler: InAppPurchase.ReceiptRefreshHandler?) {
public func refreshReceipt(handler: InAppPurchase.ReceiptRefreshHandler?) {
_receiptRefreshHandler?(handler)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import Foundation
import StoreKit

final class StubPayment: SKPayment {
public final class StubPayment: SKPayment {
private let _productIdentifier: String
override var productIdentifier: String {
public override var productIdentifier: String {
return _productIdentifier
}

init(productIdentifier: String) {
public init(productIdentifier: String) {
self._productIdentifier = productIdentifier
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
//

import Foundation
@testable import InAppPurchase
import InAppPurchase
import StoreKit

final class StubPaymentQueue: SKPaymentQueue {
public final class StubPaymentQueue: SKPaymentQueue {
private static var _canMakePayments: Bool = false
private let _transactions: [StubPaymentTransaction]
private let _addObserverHandler: ((_ observer: SKPaymentTransactionObserver) -> Void)?
Expand All @@ -19,13 +19,13 @@ final class StubPaymentQueue: SKPaymentQueue {
private let _restoreCompletedTransactionsHandler: (() -> Void)?
private let _finishTransactionHandler: ((_ transaction: SKPaymentTransaction) -> Void)?

init(canMakePayments: Bool = true,
transactions: [StubPaymentTransaction] = [],
addObserverHandler: ((_ observer: SKPaymentTransactionObserver) -> Void)? = nil,
removeObserverHandler: ((_ observer: SKPaymentTransactionObserver) -> Void)? = nil,
addPaymentHandler: ((_ payment: SKPayment) -> Void)? = nil,
restoreCompletedTransactionsHandler: (() -> Void)? = nil,
finishTransactionHandler: ((_ transaction: SKPaymentTransaction) -> Void)? = nil) {
public init(canMakePayments: Bool = true,
transactions: [StubPaymentTransaction] = [],
addObserverHandler: ((_ observer: SKPaymentTransactionObserver) -> Void)? = nil,
removeObserverHandler: ((_ observer: SKPaymentTransactionObserver) -> Void)? = nil,
addPaymentHandler: ((_ payment: SKPayment) -> Void)? = nil,
restoreCompletedTransactionsHandler: (() -> Void)? = nil,
finishTransactionHandler: ((_ transaction: SKPaymentTransaction) -> Void)? = nil) {

StubPaymentQueue._canMakePayments = canMakePayments
self._transactions = transactions
Expand All @@ -36,31 +36,31 @@ final class StubPaymentQueue: SKPaymentQueue {
self._finishTransactionHandler = finishTransactionHandler
}

@objc override class func canMakePayments() -> Bool {
@objc public override class func canMakePayments() -> Bool {
return _canMakePayments
}

override func add(_ observer: SKPaymentTransactionObserver) {
public override func add(_ observer: SKPaymentTransactionObserver) {
_addObserverHandler?(observer)
}

override func remove(_ observer: SKPaymentTransactionObserver) {
public override func remove(_ observer: SKPaymentTransactionObserver) {
_removeObserverHandler?(observer)
}

override func add(_ payment: SKPayment) {
public override func add(_ payment: SKPayment) {
_addPaymentHandler?(payment)
}

override func restoreCompletedTransactions() {
public override func restoreCompletedTransactions() {
_restoreCompletedTransactionsHandler?()
}

override func finishTransaction(_ transaction: SKPaymentTransaction) {
public override func finishTransaction(_ transaction: SKPaymentTransaction) {
_finishTransactionHandler?(transaction)
}

override var transactions: [SKPaymentTransaction] {
public override var transactions: [SKPaymentTransaction] {
return self._transactions
}
}
20 changes: 20 additions & 0 deletions InAppPurchaseStubs/Stubs/StubPaymentResponse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// StubPaymentResponse.swift
// InAppPurchaseStubs
//
// Created by Jin Sasaki on 2020/12/11.
// Copyright © 2020 Jin Sasaki. All rights reserved.
//

import Foundation
import InAppPurchase

public final class StubPaymentResponse: PaymentResponse {
public let state: PaymentState
public let transaction: PaymentTransaction

public init(state: PaymentState, transaction: PaymentTransaction) {
self.state = state
self.transaction = transaction
}
}
Loading

0 comments on commit c2f31f1

Please sign in to comment.