Skip to main content

PlayerMockServiceBase

Shared behavior for PlayerMockService (server realm) and PlayerMockServiceClient (client realm): the place-wide discovery surface, and mock consumption -- the leak detection between sequential tests in the shared place.

Every mock a service observes -- alive at PlayerMockServiceBase.Init, or parented later -- is marked as consumed in the service's realm, and the mark carries the consuming service's identity. Observing a mock whose consumer has since been destroyed is an error: the mock outlived the service that consumed it, which means it leaked from an earlier test. Because consumption replaces asserting an empty place at Init, mocks may be created (and the local player designated) before bags boot -- matching production, where Players.LocalPlayer exists before any service runs.

Only one server-realm service may be alive at a time, while multiple client-realm services (simulated clients) may coexist -- so the client service tolerates marks from live concurrent consumers and the server service treats them as an error. A mock never observed by any mock service carries no mark and is not protected; the batch runner's between-package sweep is the backstop there.

Functions

Init

PlayerMockServiceBase:Init(serviceBagServiceBag) → ()

Initializes the service and begins consuming every mock in the place. Deriving services must define ServiceName, _consumedAttributeName, and _allowConcurrentConsumers as static fields.

GetPlayerMocks

PlayerMockServiceBase:GetPlayerMocks() → {Player}

Returns the mocks currently in the place. Mirrors Players:GetPlayers() -- the same answer from any ServiceBag in either realm -- so infrastructure that sweeps existing players (e.g. a binder unbinding on disable) can sweep the mocks the same way.

ObservePlayerMocks

PlayerMockServiceBase:ObservePlayerMocks() → Observable<Player>

Observes every mock in the place -- those already alive and those parented later, from any bag in either realm -- emitting each mock once. Mirrors how Players.PlayerAdded + Players:GetPlayers() are consumed, so a PlayerBinder can treat mocks like real joins.

Show raw api
{
    "functions": [
        {
            "name": "Init",
            "desc": "Initializes the service and begins consuming every mock in the place. Deriving services must\ndefine `ServiceName`, `_consumedAttributeName`, and `_allowConcurrentConsumers` as static fields.",
            "params": [
                {
                    "name": "serviceBag",
                    "desc": "",
                    "lua_type": "ServiceBag"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 43,
                "path": "src/player-mock/src/Shared/PlayerMockServiceBase.lua"
            }
        },
        {
            "name": "GetPlayerMocks",
            "desc": "Returns the mocks currently in the place. Mirrors `Players:GetPlayers()` -- the same answer from\nany ServiceBag in either realm -- so infrastructure that sweeps existing players (e.g. a binder\nunbinding on disable) can sweep the mocks the same way.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{ Player }"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 60,
                "path": "src/player-mock/src/Shared/PlayerMockServiceBase.lua"
            }
        },
        {
            "name": "ObservePlayerMocks",
            "desc": "Observes every mock in the place -- those already alive and those parented later, from any bag in\neither realm -- emitting each mock once. Mirrors how `Players.PlayerAdded` +\n`Players:GetPlayers()` are consumed, so a PlayerBinder can treat mocks like real joins.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<Player>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 77,
                "path": "src/player-mock/src/Shared/PlayerMockServiceBase.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "PlayerMockServiceBase",
    "desc": "Shared behavior for [PlayerMockService] (server realm) and [PlayerMockServiceClient] (client\nrealm): the place-wide discovery surface, and mock consumption -- the leak detection between\nsequential tests in the shared place.\n\nEvery mock a service observes -- alive at [PlayerMockServiceBase.Init], or parented later -- is\nmarked as consumed in the service's realm, and the mark carries the consuming service's identity.\nObserving a mock whose consumer has since been destroyed is an error: the mock outlived the\nservice that consumed it, which means it leaked from an earlier test. Because consumption replaces\nasserting an empty place at Init, mocks may be created (and the local player designated) *before*\nbags boot -- matching production, where `Players.LocalPlayer` exists before any service runs.\n\nOnly one server-realm service may be alive at a time, while multiple client-realm services\n(simulated clients) may coexist -- so the client service tolerates marks from live concurrent\nconsumers and the server service treats them as an error. A mock never observed by any mock\nservice carries no mark and is not protected; the batch runner's between-package sweep is the\nbackstop there.",
    "source": {
        "line": 22,
        "path": "src/player-mock/src/Shared/PlayerMockServiceBase.lua"
    }
}