Skip to content

Class

ArrayTestDatabase

Lets you mock the row results for each query.
final class ArrayTestDatabase

Overview

Make sure you append a result for each query you will make to the database. Running out of results will result in a failed EventLoopFuture with the TestDatabaseError.ranOutOfResults error.

Examples:

Return an empty result for the next query:

let db = ArrayTestDatabase()
db.append([])

Return an empty result for first query, and a single result for the second query (perhaps a query to find a record with no results followed by a successful query to create the record):

let db = ArrayTestDatabase()
db.append([])
db.append([
    TestOutput(["id": 1, "name": "Boise"])
])

Return multiple rows for one query:

let db = ArrayTestDatabase()
db.append([
    TestOutput(["id": 1, ...]),
    TestOutput(["id": 2, ...])
])

Append a Model:

let db = ArrayTestDatabase()
db.append([
    TestOutput(Planet(name: "Pluto"))
])

Topics

Initializers

Instance Methods

Relationships

Conforms To