Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 6 additions & 26 deletions IntegrationTests/Sources/main.swift
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
import Foundation
import mParticle_Apple_SDK_NoLocation

// Listener for tracking upload events
class EventUploadWaiter: NSObject, MPListenerProtocol {
private var uploadCompletedSemaphore: DispatchSemaphore?
// Helper for triggering uploads and waiting for completion
class EventUploadWaiter {
var mparticle = MParticle.sharedInstance()

@discardableResult
func wait(timeout: Int = 5) -> Bool {
func wait(timeout: UInt32 = 5) -> Bool {
mparticle.upload()
let semaphore = DispatchSemaphore(value: 0)
uploadCompletedSemaphore = semaphore

let timeoutTime = DispatchTime.now() + .seconds(timeout)
let result = semaphore.wait(timeout: timeoutTime)

uploadCompletedSemaphore = nil

return result == .success
sleep(timeout)
return true
}

func onNetworkRequestFinished(_ type: MPEndpoint,
url: String,
body: NSObject,
responseCode: Int) {
if type == .events {
uploadCompletedSemaphore?.signal()
}
}

func onNetworkRequestStarted(_ type: MPEndpoint, url: String, body: NSObject) {}
}

// Test 1: Simple Event
Expand Down Expand Up @@ -455,9 +436,8 @@ networkOptions.pinningDisabled = true;

options.networkOptions = networkOptions

// Register listener for tracking upload events
// Create upload waiter for triggering uploads and waiting for completion
let uploadWaiter = EventUploadWaiter()
MPListenerController.sharedInstance().addSdkListener(uploadWaiter)

let mparticle = MParticle.sharedInstance()
mparticle.start(with: options)
Expand Down
4 changes: 4 additions & 0 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This document provides migration guidance for breaking changes in the mParticle

## Migrating from versions < 9.0.0

### Removed MPListenerController

The `MPListenerController` class has been removed. The SDK no longer invokes any listener callbacks.

### Removed Deprecated UIApplicationDelegate Methods

Apple has deprecated several `UIApplicationDelegate` protocol methods in favor of the modern `UIScene` lifecycle introduced in iOS 13. The mParticle SDK previously provided wrapper methods for these deprecated delegate methods, but these have been removed as they are scheduled for removal by Apple in iOS 27.
Expand Down
2 changes: 0 additions & 2 deletions UnitTests/MParticle+PrivateMethods.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#import "SettingsProvider.h"
#import "MParticleSwift.h"
#import "MPDataPlanFilter.h"
#import "MPListenerController.h"
#import "AppEnvironmentProvider.h"
#import "MPAppNotificationHandler.h"

Expand Down Expand Up @@ -55,7 +54,6 @@
@property (nonatomic, strong) SceneDelegateHandler *sceneDelegateHandler;
@property (nonatomic, strong) id<SettingsProviderProtocol> settingsProvider;
@property (nonatomic, strong, nullable) id<MPDataPlanFilterProtocol> dataPlanFilter;
@property (nonatomic, strong, nonnull) id<MPListenerControllerProtocol> listenerController;
@property (nonatomic, strong) id<MPStateMachineProtocol> stateMachine;
@property (nonatomic, strong) id<MPPersistenceControllerProtocol> persistenceController;
@property (nonatomic, strong, nonnull) id<MPNotificationControllerProtocol> notificationController;
Expand Down
112 changes: 0 additions & 112 deletions UnitTests/Mocks/MPListenerControllerMock.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ final class MParticleCommerceEventTests: MParticleTestBase {

XCTAssertNotNil(commerceEvent.timestamp)
XCTAssertTrue(backendController.logCommerceEventCalled)
XCTAssertTrue(listenerController.onAPICalledParameter1 === commerceEvent)
XCTAssertTrue(executor.executeOnMessageQueueAsync)
}

Expand All @@ -23,10 +22,6 @@ final class MParticleCommerceEventTests: MParticleTestBase {
// Verify event timestamp added
XCTAssertNotNil(commerceEvent.timestamp)

// Verify listener was called
XCTAssertEqual(listenerController.onAPICalledApiName?.description, "logCommerceEvent:")
XCTAssertTrue(listenerController.onAPICalledParameter1 === commerceEvent)

// Verify backend was called
XCTAssertTrue(backendController.logCommerceEventCalled)
XCTAssertTrue(backendController.logCommerceEventParam === commerceEvent)
Expand All @@ -53,10 +48,6 @@ final class MParticleCommerceEventTests: MParticleTestBase {
// Verify event timestamp added
XCTAssertNotNil(commerceEvent.timestamp)

// Verify listener was called
XCTAssertEqual(listenerController.onAPICalledApiName?.description, "logCommerceEvent:")
XCTAssertTrue(listenerController.onAPICalledParameter1 === commerceEvent)

// Verify backend was called
XCTAssertTrue(backendController.logCommerceEventCalled)
XCTAssertTrue(backendController.logCommerceEventParam === commerceEvent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ final class MParticleCustomEventTests: MParticleTestBase {
// Verify event timing ended
XCTAssertNil(event.endTime)

// Verify listener was called
XCTAssertEqual(listenerController.onAPICalledApiName?.description, "logCustomEvent:")
XCTAssertTrue(listenerController.onAPICalledParameter1 === event)

// Verify backend was called
XCTAssertTrue(backendController.logEventCalled)
XCTAssertTrue(backendController.logEventEventParam === event)
Expand All @@ -44,10 +40,6 @@ final class MParticleCustomEventTests: MParticleTestBase {
// Verify event timing ended
XCTAssertNil(event.endTime)

// Verify listener was called
XCTAssertEqual(listenerController.onAPICalledApiName?.description, "logCustomEvent:")
XCTAssertTrue(listenerController.onAPICalledParameter1 === event)

// Verify backend was called
XCTAssertTrue(backendController.logEventCalled)
XCTAssertTrue(backendController.logEventEventParam === event)
Expand Down
2 changes: 0 additions & 2 deletions UnitTests/SwiftTests/MParticle/MParticleErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ final class MParticleErrorTests: MParticleTestBase {
mparticle.logError(errorMessage)

XCTAssertTrue(executor.executeOnMessageQueueAsync)
listenerController.assertCalled(#selector(mparticle.logError(_:eventInfo:)))

XCTAssertTrue(backendController.logErrorCalled)
XCTAssertNil(backendController.logErrorExceptionParam)
Expand All @@ -78,7 +77,6 @@ final class MParticleErrorTests: MParticleTestBase {
mparticle.logError(errorMessage, eventInfo: keyValueDict)

XCTAssertTrue(executor.executeOnMessageQueueAsync)
listenerController.assertCalled(#selector(mparticle.logError(_:eventInfo:)))

XCTAssertTrue(backendController.logErrorCalled)
XCTAssertNil(backendController.logErrorExceptionParam)
Expand Down
29 changes: 0 additions & 29 deletions UnitTests/SwiftTests/MParticle/MParticleEventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,11 @@ import mParticle_Apple_SDK_NoLocation

final class MParticleEventTests: MParticleTestBase {

func test_logEvent_callsLogCustomEvent() {
mparticle.logEvent(event)
wait(for: [listenerController.onAPICalledExpectation!], timeout: 0.1)
XCTAssertEqual(listenerController.onAPICalledApiName?.description, "logCustomEvent:")
}

func test_logEvent_callsLogCommerceEvent() {
mparticle.logEvent(commerceEvent)
wait(for: [listenerController.onAPICalledExpectation!], timeout: 0.1)
XCTAssertEqual(listenerController.onAPICalledApiName?.description, "logCommerceEvent:")
}

func test_logEvent_blocksEvent_whenFilterReturnsNil() {
dataPlanFilter.transformEventForBaseEventReturnValue = nil

mparticle.logEvent(baseEvent)

// Verify listener was called
XCTAssertEqual(listenerController.onAPICalledApiName?.description, "logEvent:")
XCTAssertTrue(listenerController.onAPICalledParameter1 === baseEvent)

// Verify backend was called
XCTAssertTrue(backendController.logBaseEventCalled)
XCTAssertTrue(backendController.logBaseEventEventParam === baseEvent)
Expand All @@ -47,10 +31,6 @@ final class MParticleEventTests: MParticleTestBase {

mparticle.logEvent(baseEvent)

// Verify listener was called
XCTAssertEqual(listenerController.onAPICalledApiName?.description, "logEvent:")
XCTAssertTrue(listenerController.onAPICalledParameter1 === baseEvent)

// Verify backend was called
XCTAssertTrue(backendController.logBaseEventCalled)
XCTAssertTrue(backendController.logBaseEventEventParam === baseEvent)
Expand Down Expand Up @@ -145,9 +125,6 @@ final class MParticleEventTests: MParticleTestBase {

XCTAssertTrue(backendController.eventWithNameCalled)
XCTAssertEqual(backendController.eventWithNameEventNameParam, event.name)

XCTAssertTrue(listenerController.onAPICalledCalled)
XCTAssertTrue(listenerController.onAPICalledParameter1 === event)
}

func test_logEvent_createsNewEvent_whenNotFound() {
Expand All @@ -157,11 +134,5 @@ final class MParticleEventTests: MParticleTestBase {

XCTAssertTrue(backendController.eventWithNameCalled)
XCTAssertEqual(backendController.eventWithNameEventNameParam, event.name)

XCTAssertTrue(listenerController.onAPICalledCalled)
let createdEvent: MPEvent = (listenerController.onAPICalledParameter1 as? MPBaseEvent)! as! MPEvent
XCTAssertEqual(createdEvent.name, event.name)
XCTAssertEqual(createdEvent.type, event.type)
XCTAssertEqual(createdEvent.customAttributes as! [String: String], event.customAttributes as! [String: String])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ final class MParticleKitBatchTests: MParticleTestBase {
kitContainer.kitsInitialized = true
mparticle.executeKitsInitializedBlocks()

XCTAssertEqual(listenerController.onAPICalledApiName?.description, "executeKitsInitializedBlocks")
XCTAssertTrue(executor.executeOnMainAsync)
XCTAssertTrue(kitContainer.forwardSDKCallCalled)
XCTAssertEqual(kitContainer.forwardSDKCallSelectorParam?.description, "logBatch:")
Expand Down
9 changes: 0 additions & 9 deletions UnitTests/SwiftTests/MParticle/MParticleLTVTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ final class MParticleLTVTests: MParticleTestBase {
XCTAssertEqual(attrs["currency"] as? String, "USD")
XCTAssertEqual(attrs.count, 4)

// Listener controller should be notified
XCTAssertEqual(listenerController.onAPICalledApiName?.description, "logLTVIncrease:eventName:eventInfo:")

// Backend completion handler should be stored
XCTAssertTrue(backendController.logEventCalled)
let completion = backendController.logEventCompletionHandler!
Expand All @@ -54,12 +51,6 @@ final class MParticleLTVTests: MParticleTestBase {
XCTAssertEqual(attrs["$MethodName"] as? String, "LogLTVIncrease")
XCTAssertEqual(attrs.count, 2)

// Listener controller should be notified
XCTAssertEqual(listenerController.onAPICalledApiName?.description, "logLTVIncrease:eventName:eventInfo:")
XCTAssertEqual(listenerController.onAPICalledParameter1 as? Double, amount)
XCTAssertEqual(listenerController.onAPICalledParameter2 as? String, name)
XCTAssertNil(listenerController.onAPICalledParameter3)

// Backend completion handler should be stored
XCTAssertTrue(backendController.logEventCalled)
let completion = backendController.logEventCompletionHandler!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ import mParticle_Apple_SDK_NoLocation

final class MParticleRuntimeValuesTests: MParticleTestBase {

func test_setSharedInstance_notifiesListener() {
MParticle.setSharedInstance(mparticle)
XCTAssertEqual(listenerController.onAPICalledApiName?.description, "setSharedInstance:")
XCTAssertTrue(listenerController.onAPICalledParameter1 === mparticle)
}

func test_setOptOutCompletion_logsMessage_onSuccess() {
mparticle.setOptOutCompletion(.success, optOut: true)
assertReceivedMessage("Set Opt Out: 1")
Expand Down
Loading
Loading