PersistenceController tests

This commit is contained in:
Lysann Tranvouez 2026-03-09 14:04:12 +01:00
parent 5a51425d01
commit c8cce5c322
4 changed files with 112 additions and 7 deletions

View file

@ -18,19 +18,19 @@ public class PersistenceController {
let container: NSPersistentContainer
init(isUnitTest: Bool = false) {
init(storeURL: URL? = nil) {
self.container = NSPersistentContainer(name: Self.modelName, managedObjectModel: .sharedModel)
let description = container.persistentStoreDescriptions.first
description?.shouldMigrateStoreAutomatically = false
description?.shouldInferMappingModelAutomatically = false
if isUnitTest {
description?.url = URL(fileURLWithPath: "/dev/null")
} else {
description?.url = URL(fileURLWithPath: Globals.dbPath)
}
description?.url = storeURL ?? URL(fileURLWithPath: Globals.dbPath)
setup()
}
static func forUnitTests() -> PersistenceController {
PersistenceController(storeURL: URL(fileURLWithPath: "/dev/null"))
}
func setup() {
container.loadPersistentStores { _, error in
if error != nil {