Skip to main content

PlayerMockService

Server-side home for the PlayerMocks a test stands up, and the discovery surface PlayerBinders observe. Creating a mock through the service (rather than PlayerMock.new by hand) parents it into the world and ties its lifetime to the service maid -- so tearing down the ServiceBag cleans up every mock it made.

Replication is the default, mirroring how a real Player exists for every peer: any mock parented into the DataModel (this service's or a hand-built one) is discovered by every PlayerMockService and PlayerMockServiceClient in the place, across ServiceBags and realms -- which is what lets TieInterfaces and Remoting bridge a server bag and a client bag in the same test.

Discovery and leak detection live in [PlayerMockServiceBase]: mocks may exist before this service boots (create and designate first, then boot -- production parity), and a leak is a mock that outlived the service that consumed it, not a mock that predates boot. There is one server per place, so only one server-realm service may be alive at a time.

local playerMockService = serviceBag:GetService(require("PlayerMockService"))
local player = playerMockService:CreatePlayer({ UserId = 12345 })

Functions

CreatePlayer

PlayerMockService:CreatePlayer(
overrides{[string]any}?--

Per-property seed values, e.g. { UserId = 12345 } (see PlayerMock.new).

) → Player

Creates a PlayerMock, parents it into Players -- where real players live, so the mock's subtree (PlayerGui, property backings) never hydrates instances inside Workspace -- and tracks it for cleanup. Parenting anywhere in the DataModel replicates it, so PlayerBinders and PlayerMockServiceClients in every bag discover it like a real join.

Show raw api
{
    "functions": [
        {
            "name": "CreatePlayer",
            "desc": "Creates a [PlayerMock], parents it into [Players] -- where real players live, so the mock's\nsubtree (PlayerGui, property backings) never hydrates instances inside Workspace -- and tracks it\nfor cleanup. Parenting anywhere in the DataModel replicates it, so PlayerBinders and\n[PlayerMockServiceClient]s in every bag discover it like a real join.",
            "params": [
                {
                    "name": "overrides",
                    "desc": "Per-property seed values, e.g. `{ UserId = 12345 }` (see [PlayerMock.new]).",
                    "lua_type": "{ [string]: any }?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 47,
                "path": "src/player-mock/src/Server/PlayerMockService.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "PlayerMockService",
    "desc": "Server-side home for the [PlayerMock]s a test stands up, and the discovery surface PlayerBinders\nobserve. Creating a mock through the service (rather than `PlayerMock.new` by hand) parents it into\nthe world and ties its lifetime to the service maid -- so tearing down the ServiceBag cleans up every\nmock it made.\n\nReplication is the default, mirroring how a real `Player` exists for every peer: any mock parented\ninto the DataModel (this service's or a hand-built one) is discovered by every [PlayerMockService]\nand [PlayerMockServiceClient] in the place, across ServiceBags and realms -- which is what lets\nTieInterfaces and Remoting bridge a server bag and a client bag in the same test.\n\nDiscovery and leak detection live in [PlayerMockServiceBase]: mocks may exist *before* this\nservice boots (create and designate first, then boot -- production parity), and a leak is a mock\nthat outlived the service that consumed it, not a mock that predates boot. There is one server per\nplace, so only one server-realm service may be alive at a time.\n\n```lua\nlocal playerMockService = serviceBag:GetService(require(\"PlayerMockService\"))\nlocal player = playerMockService:CreatePlayer({ UserId = 12345 })\n```",
    "source": {
        "line": 25,
        "path": "src/player-mock/src/Server/PlayerMockService.lua"
    }
}