Skip to main content

PlayerMockMethodUtils

The native methods a mock stands in for, each named by the canonical Class.Method the production code path bottoms out in -- the interception point is the engine API, not the Nevermore util wrapping it. Reflection decides which paths exist; the modelled table below only says what one answers until a test says otherwise.

Every domain is an implementation the mock runs, whether it performs the call -- Player:Kick really removing the mock from the DataModel -- or answers it, like the truthful MarketplaceService:UserOwnsGamePassAsync for a fake UserId. Both are displaced the same way, by binding a stand-in over them with PlayerMockMethodUtils.bindMethod -- over the whole method, or over one argument tuple; PlayerMockMethodUtils.writeLookup is that bind with a constant answer in place of a callback. A domain that models argument and result shapes holds every call and every answer to them, whichever stand-in ran.

Use PlayerMock.callMethod, PlayerMock.bindMethod, PlayerMock.readLookup, PlayerMock.writeLookup and PlayerMock.getKickMessage.

Functions

call

PlayerMockMethodUtils.call(
playerPlayer,--

must be a PlayerMock

methodPathInstancePathTableLike,--

"Player.Kick" or "MarketplaceService.UserOwnsGamePassAsync"

...any--

the engine call's own arguments; for an injected answer, what it turns on

) → ...any

Calls a native method on a mock, running whichever stand-in it has: a callback bound over the whole method through PlayerMockMethodUtils.bindMethod, otherwise one bound over these arguments -- an answer injected through PlayerMockMethodUtils.writeLookup among them -- otherwise what the domain models. The domain's own shapes hold whichever ran, the arguments going in and the answer coming back alike.

Use PlayerMock.callMethod.

bindMethod

PlayerMockMethodUtils.bindMethod(
playerPlayer,--

must be a PlayerMock

methodPathInstancePathTableLike,--

"Player.Kick" or "Players.GetFriendsAsync"

callback((
playerPlayer,
...any
) → ...any)?,--

nil removes the binding

...any--

the arguments to bind over, or none for the whole method

) → () → ()

Binds a callback to stand in for a native method on one mock, displacing whatever PlayerMockMethodUtils.call would otherwise run. The callback receives the mock followed by the call's own arguments; binding again replaces the previous callback, and binding nil removes it, leaving the domain to answer what it models again.

Passing the call's arguments narrows the binding to that one argument tuple, leaving every other tuple to what the domain models; passing none binds the whole method, which wins over any tuple binding. The domain holds the tuple named here to its argument shape, and the callback's answer to its result shape when the call runs.

The path only has to name a real method, so this reaches methods the mock models no default for.

Returns a function that removes this binding, for a maid to hold. It removes only the binding it came from: after a rebind it is a no-op, so an unwinding maid cannot tear down a stand-in that replaced its own.

Use PlayerMock.bindMethod.

unbindMethod

PlayerMockMethodUtils.unbindMethod(
playerPlayer,--

must be a PlayerMock

methodPathInstancePathTableLike,--

"Player.Kick" or "Players.GetFriendsAsync"

...any--

the arguments the binding was made over, or none for the whole method

) → ()

Removes a callback bound through PlayerMockMethodUtils.bindMethod, so the domain falls back to its modelled stand-in. The arguments are the ones the binding was made over; unbinding a method that was never bound is a no-op.

Use PlayerMock.unbindMethod.

isMethodBound

PlayerMockMethodUtils.isMethodBound(
playerPlayer,--

must be a PlayerMock

methodPathInstancePathTableLike,--

"Player.Kick" or "Players.GetFriendsAsync"

...any--

the arguments the binding was made over, or none for the whole method

) → boolean

Returns whether a callback is currently bound for the method on this mock, over the arguments given or over the whole method when none are.

Use PlayerMock.isMethodBound.

readLookup

PlayerMockMethodUtils.readLookup(
playerPlayer,--

must be a PlayerMock

methodPathInstancePathTableLike,--

a known lookup domain, e.g. "GroupService.GetRolesInGroupAsync"

...any--

the engine call's own arguments, the ones the answer turns on

) → any

Reads back what the mock answers for an engine call, the test-side name for PlayerMockMethodUtils.call.

Use PlayerMock.readLookup.

writeLookup

PlayerMockMethodUtils.writeLookup(
playerPlayer,--

must be a PlayerMock

methodPathInstancePathTableLike,--

a known lookup domain, e.g. "MarketplaceService.UserOwnsGamePassAsync"

valueany,--

must match the domain's result shape; nil removes the injection

...any--

the engine call's own arguments, the ones the answer turns on

) → ()

Injects the answer a mock gives for one argument tuple of an engine call: the PlayerMockMethodUtils.bindMethod bind, with a constant in place of a callback. Passing nil removes the injection, leaving the domain to answer what it models again.

The domain holds the value to its result shape when it is read, the way it holds any stand-in's answer.

Use PlayerMock.writeLookup.

getKickMessage

PlayerMockMethodUtils.getKickMessage(
playerPlayer--

must be a PlayerMock

) → string?

Returns the message a mock was kicked with, or nil when the mock was never kicked. The engine has no counterpart -- a real Player:Kick leaves nothing to read -- so this is the test-side reader for the "Player.Kick" domain.

Use PlayerMock.getKickMessage.

Show raw api
{
    "functions": [
        {
            "name": "call",
            "desc": "Calls a native method on a mock, running whichever stand-in it has: a callback bound over the\nwhole method through [PlayerMockMethodUtils.bindMethod], otherwise one bound over these arguments\n-- an answer injected through [PlayerMockMethodUtils.writeLookup] among them -- otherwise what the\ndomain models. The domain's own shapes hold whichever ran, the arguments going in and the answer\ncoming back alike.\n\nUse [PlayerMock.callMethod].",
            "params": [
                {
                    "name": "player",
                    "desc": "must be a PlayerMock",
                    "lua_type": "Player"
                },
                {
                    "name": "methodPath",
                    "desc": "`\"Player.Kick\"` or `\"MarketplaceService.UserOwnsGamePassAsync\"`",
                    "lua_type": "InstancePathTableLike"
                },
                {
                    "name": "...",
                    "desc": "the engine call's own arguments; for an injected answer, what it turns on",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "...any"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 326,
                "path": "src/player-mock/src/Shared/Helpers/Methods/PlayerMockMethodUtils.lua"
            }
        },
        {
            "name": "bindMethod",
            "desc": "Binds a callback to stand in for a native method on one mock, displacing whatever\n[PlayerMockMethodUtils.call] would otherwise run. The callback receives the mock followed by the\ncall's own arguments; binding again replaces the previous callback, and binding nil removes it,\nleaving the domain to answer what it models again.\n\nPassing the call's arguments narrows the binding to that one argument tuple, leaving every other\ntuple to what the domain models; passing none binds the whole method, which wins over any tuple\nbinding. The domain holds the tuple named here to its argument shape, and the callback's answer to\nits result shape when the call runs.\n\nThe path only has to name a real method, so this reaches methods the mock models no default for.\n\nReturns a function that removes this binding, for a maid to hold. It removes only the binding it\ncame from: after a rebind it is a no-op, so an unwinding maid cannot tear down a stand-in that\nreplaced its own.\n\nUse [PlayerMock.bindMethod].",
            "params": [
                {
                    "name": "player",
                    "desc": "must be a PlayerMock",
                    "lua_type": "Player"
                },
                {
                    "name": "methodPath",
                    "desc": "`\"Player.Kick\"` or `\"Players.GetFriendsAsync\"`",
                    "lua_type": "InstancePathTableLike"
                },
                {
                    "name": "callback",
                    "desc": "nil removes the binding",
                    "lua_type": "((player: Player, ...any) -> ...any)?"
                },
                {
                    "name": "...",
                    "desc": "the arguments to bind over, or none for the whole method",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "() -> ()"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 388,
                "path": "src/player-mock/src/Shared/Helpers/Methods/PlayerMockMethodUtils.lua"
            }
        },
        {
            "name": "unbindMethod",
            "desc": "Removes a callback bound through [PlayerMockMethodUtils.bindMethod], so the domain falls back to\nits modelled stand-in. The arguments are the ones the binding was made over; unbinding a method\nthat was never bound is a no-op.\n\nUse [PlayerMock.unbindMethod].",
            "params": [
                {
                    "name": "player",
                    "desc": "must be a PlayerMock",
                    "lua_type": "Player"
                },
                {
                    "name": "methodPath",
                    "desc": "`\"Player.Kick\"` or `\"Players.GetFriendsAsync\"`",
                    "lua_type": "InstancePathTableLike"
                },
                {
                    "name": "...",
                    "desc": "the arguments the binding was made over, or none for the whole method",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 426,
                "path": "src/player-mock/src/Shared/Helpers/Methods/PlayerMockMethodUtils.lua"
            }
        },
        {
            "name": "isMethodBound",
            "desc": "Returns whether a callback is currently bound for the method on this mock, over the arguments\ngiven or over the whole method when none are.\n\nUse [PlayerMock.isMethodBound].",
            "params": [
                {
                    "name": "player",
                    "desc": "must be a PlayerMock",
                    "lua_type": "Player"
                },
                {
                    "name": "methodPath",
                    "desc": "`\"Player.Kick\"` or `\"Players.GetFriendsAsync\"`",
                    "lua_type": "InstancePathTableLike"
                },
                {
                    "name": "...",
                    "desc": "the arguments the binding was made over, or none for the whole method",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 445,
                "path": "src/player-mock/src/Shared/Helpers/Methods/PlayerMockMethodUtils.lua"
            }
        },
        {
            "name": "readLookup",
            "desc": "Reads back what the mock answers for an engine call, the test-side name for\n[PlayerMockMethodUtils.call].\n\nUse [PlayerMock.readLookup].",
            "params": [
                {
                    "name": "player",
                    "desc": "must be a PlayerMock",
                    "lua_type": "Player"
                },
                {
                    "name": "methodPath",
                    "desc": "a known lookup domain, e.g. \"GroupService.GetRolesInGroupAsync\"",
                    "lua_type": "InstancePathTableLike"
                },
                {
                    "name": "...",
                    "desc": "the engine call's own arguments, the ones the answer turns on",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 473,
                "path": "src/player-mock/src/Shared/Helpers/Methods/PlayerMockMethodUtils.lua"
            }
        },
        {
            "name": "writeLookup",
            "desc": "Injects the answer a mock gives for one argument tuple of an engine call: the\n[PlayerMockMethodUtils.bindMethod] bind, with a constant in place of a callback. Passing nil\nremoves the injection, leaving the domain to answer what it models again.\n\nThe domain holds the value to its result shape when it is read, the way it holds any stand-in's\nanswer.\n\nUse [PlayerMock.writeLookup].",
            "params": [
                {
                    "name": "player",
                    "desc": "must be a PlayerMock",
                    "lua_type": "Player"
                },
                {
                    "name": "methodPath",
                    "desc": "a known lookup domain, e.g. \"MarketplaceService.UserOwnsGamePassAsync\"",
                    "lua_type": "InstancePathTableLike"
                },
                {
                    "name": "value",
                    "desc": "must match the domain's result shape; nil removes the injection",
                    "lua_type": "any"
                },
                {
                    "name": "...",
                    "desc": "the engine call's own arguments, the ones the answer turns on",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 496,
                "path": "src/player-mock/src/Shared/Helpers/Methods/PlayerMockMethodUtils.lua"
            }
        },
        {
            "name": "getKickMessage",
            "desc": "Returns the message a mock was kicked with, or nil when the mock was never kicked. The engine has\nno counterpart -- a real `Player:Kick` leaves nothing to read -- so this is the test-side reader\nfor the `\"Player.Kick\"` domain.\n\nUse [PlayerMock.getKickMessage].",
            "params": [
                {
                    "name": "player",
                    "desc": "must be a PlayerMock",
                    "lua_type": "Player"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 515,
                "path": "src/player-mock/src/Shared/Helpers/Methods/PlayerMockMethodUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "PlayerMockMethodUtils",
    "desc": "The native methods a mock stands in for, each named by the canonical `Class.Method` the production\ncode path bottoms out in -- the interception point is the engine API, not the Nevermore util\nwrapping it. Reflection decides which paths exist; the modelled table below only says what one\nanswers until a test says otherwise.\n\nEvery domain is an implementation the mock runs, whether it performs the call -- `Player:Kick`\nreally removing the mock from the DataModel -- or answers it, like the truthful\n`MarketplaceService:UserOwnsGamePassAsync` for a fake UserId. Both are displaced the same way, by\nbinding a stand-in over them with [PlayerMockMethodUtils.bindMethod] -- over the whole method, or\nover one argument tuple; [PlayerMockMethodUtils.writeLookup] is that bind with a constant answer in\nplace of a callback. A domain that models argument and result shapes holds every call and every\nanswer to them, whichever stand-in ran.\n\nUse [PlayerMock.callMethod], [PlayerMock.bindMethod], [PlayerMock.readLookup],\n[PlayerMock.writeLookup] and [PlayerMock.getKickMessage].",
    "source": {
        "line": 21,
        "path": "src/player-mock/src/Shared/Helpers/Methods/PlayerMockMethodUtils.lua"
    }
}