MMOframework
Pourquoi l'IA Playground Bibliothèques Documentation Rechercher Agence
FR EN
Index

TestData

MMO\admin\helpers · 1 symbole · générée le 27 Oct 2026

class

TestData

TestData.php:48

The test records of a checklist's recipe (recipe.testData): what each test account (recipe.accounts, TestAccounts) must find in its perimeter and must not find outside it, for every « Open as … » check to have something to look at -- an AT of a subcontractor of the North group for the account limited to it, and one of the South-East group it must not see.

class MMO\admin\helpers\TestData
Espace de noms
MMO\admin\helpers
"testData": { "prefix": "TEST CLAUDE", // what every record's label starts with (the default) "by": "admin", // the profile whose account writes them: its rights, the application's rules "records": { "employeeNorth": {"collection": "salaries", "label": "TEST CLAUDE Salarié Nord", "fields": {"nom": "TEST CLAUDE", "prenom": "Salarié Nord"}}, "contractNorth": {"collection": "contrats", "label": "TEST CLAUDE Contrat Nord", "fields": {"salarie": "@employeeNorth", "entreprise": {"$find": "groupes", "where": {"label": "North"}, "path": "entreprises/0"}, "type": "CDI", "debut": {"$date": "2024-01-01"}}}, "atNorth": {"collection": "accidentTravails", "label": "TEST CLAUDE AT Nord", "status": "draft", "fields": {"contrat": "@contractNorth", "date": {"$date": "-10 days"}}, "calls": [{"method": "addCommentaire", "args": ["$by", "TEST CLAUDE comment"]}]}, "certificateNorth": {"collection": "files", "label": "TEST CLAUDE certificat Nord.pdf", "file": {}, "labels": ["\"#certificat\""], "fields": {"attachment": "@atNorth"}} }, "expect": [ {"as": "limited", "match": "/sousTraitants/", "sees": ["astNorth"], "hides": ["astSouthEast"]}, {"as": "limited", "sees": ["atNorth"], "hides": ["atSouthEast"]} ] } - a record is made through the application's entities, as the account `by` names (\MMO\oauth\user() while it is committed): the application's rules apply to it as to a request of that account (a contract without its employee is refused...), never a raw insert. A file (`file`: `{name?, content?}`, a small PDF by default) is made as mmo.edms' `FileManager::uploadFile()` does ([`TestDataStore::upload`](https://mmoframework.fr/fr/documentation/mmo.admin/php/helpers/TestDataStore.md#testdatastore-upload)), its labels its tokens; - a field's value: `"@key"` the record of that key (made first), `"@key/path"` a value of it, `{"$find": collection, "where": {...}, "path": "a/0"}` a record the database has (read, never written), `{"$date": "-10 days"}` a date; `"$by"` (in `calls`) the account writing; `"@@x"` is the text `@x`; - `calls`: the entity's `add…()` methods to call before it is saved (`addCommentaire`), their arguments as the fields'; - `status`: the status it is made with (`draft`: a declaration not complete is not submitted); - `expect`: what a check opened as a test account must and must not show, by profile (`as`), by item (`items`: refs), or by what its text says (`match`, a regular expression on its address, title and steps) -- the first rule that fits; `sees` and `hides` name records (their label is shown) or say it in words (`@key` in them: the record's label). `php admin.php developer test-data` makes them ([`DeveloperShellController::route_test_data`](https://mmoframework.fr/fr/documentation/mmo.admin/php/controllers/DeveloperShellController.md#developershellcontroller-route-test-data)) in this machine's own database only, keeps what it made (by database), makes nothing twice, never changes a record it did not make, and archives what it made (`--archive`).
$recipe = TestData::Recipe($checklist->data['recipe']['testData'], TestAccounts::Profiles($checklist->data['recipe']['accounts']), $errors);[$report, $made] = (new TestData($recipe, new TestDataStore($repository)))->create($made, true); // a dry run

Index

CALLa method calls may call: an entity's add…()
COLLECTIONa collection's id
KEYa record's key: what @key names
PREFIXwhat every record's label starts with, by default
REFERENCEa reference to a record of the recipe: @key, @key/path/0/to
recipe
store
archive($made, $dryRun)Archive what this command made (create), the last made first: a record that is gone, or archived already, is only forgotten.
create($made, $dryRun)Make the records the database lacks: a record this command made ($made) that is still there is not made again; one whose label a record it did not make has (not archived) is left alone (the recor…
Expectations($recipe, $items) staticWhat each item opened as a test account must show, and must not: the first rule of expect that fits it -- its profile (as), its ref (items), its text (match: its address, its title, its ste…
Pdf($text) static
planned($key, $report)
Prefixed($label, $prefix) static
Recipe($testData, $profiles, $errors) static
References($record) static
resolve($value, $entities, $author, $dryRun)
__construct($recipe, $store)

Constantes5

CALL

a method calls may call: an entity's add…()

const CALL = '/^add[A-Z]\\w{0,63}$/'

COLLECTION

a collection's id

const COLLECTION = '/^[A-Za-z][\\w]{0,63}$/'

KEY

a record's key: what @key names

const KEY = '/^[A-Za-z][\\w.-]{0,63}$/'

PREFIX

what every record's label starts with, by default

const PREFIX = 'TEST CLAUDE'

REFERENCE

a reference to a record of the recipe: @key, @key/path/0/to

const REFERENCE = '#^@([A-Za-z][\\w.-]{0,63})(?:/(.+))?$#'

Propriétés2

recipe

array $recipe
Type
array

store

protected MMO\admin\helpers\TestDataStore $store
Type
TestDataStore

Méthodes10

archive($made, $dryRun)

TestData.php:280

Archive what this command made (create), the last made first: a record that is gone, or archived already, is only forgotten.

function archive(array $made, bool $dryRun): array
$madearray
$dryRunboolonly say what would be archived
retournearraylist<array{key: string, collection: string, label: string, state: string, id: string, error?: string}>, 1: array} what was done with each, and what is left made (only the ones that could not be archived; all of them in a dry run)

create($made, $dryRun)

TestData.php:227

Make the records the database lacks: a record this command made ($made) that is still there is not made again; one whose label a record it did not make has (not archived) is left alone (the records naming it with it) -- nothing is ever written in a record this command did not make. It stops at the first record the application refuses.

function create(array $made, bool $dryRun): array
$madearray
$dryRunboolonly say what would be made
retournearraylist<array{key: string, collection: string, label: string, state: string, id?: string, error?: string}>, 1: array} what was done with each record (exists, created, would create, skipped, error), and what it made now

Expectations($recipe, $items)

staticTestData.php:194

What each item opened as a test account must show, and must not: the first rule of expect that fits it -- its profile (as), its ref (items), its text (match: its address, its title, its steps) --, the records' labels in place of their keys.

static function Expectations(array $recipe, array $items): array
$recipearrayRecipe
$itemsarraya checklist's items
retournearrayarray{sees: list<string>, hides: list<string>}> by item id; an item no rule fits is not there
TestData::Expectations($recipe, $items); // ['3d332c914651' => ['sees' => ['TEST CLAUDE AST Nord'], 'hides' => ['TEST CLAUDE AST Sud-Est']]]

Pdf($text)

staticTestData.php:347
static function Pdf(string $text): string
$textstringwhat the page says
retournestringa one-page PDF saying $text: a test file's bytes
file_put_contents('/tmp/x.pdf', TestData::Pdf('TEST CLAUDE certificat Nord'));

planned($key, $report)

TestData.php:300
protected function planned(string $key, array $report): bool
$keystring
$reportarray
retourneboolwhether a dry run would make the record $key (create's report so far)

Prefixed($label, $prefix)

staticTestData.php:166
static function Prefixed(string $label, string $prefix): bool
$labelstring
$prefixstring
retourneboolwhether $label starts with $prefix (the prefix alone, or followed by a space or a punctuation mark)

Recipe($testData, $profiles, $errors)

staticTestData.php:80
static function Recipe(mixed $testData, array $profiles = [], ?array &$errors = null): array
$testDatamixeda recipe's testData
$profiles = []array
$errors = nullnull | arraywhat was refused, and why
retournearraystring, by: ?string, records: array<string, array{collection: string, label: string, fields: array, status: ?string, file: ?array{name: string, content: ?string}, labels: list<string>, calls: list<array{method: string, args: list<mixed>}>, by: ?string}>, order: list<string>, expect: list<array{as: ?string, items: list<string>, match: ?string, sees: list<string>, hides: list<string>}>} the valid records -- by their writer's username --, in the order they are made (a record after the ones it names): a record whose label does not start with the prefix, of no collection, naming a record that is not, or written by no test account, is left out (and the ones naming it)
TestData::Recipe(['records' => ['x' => ['collection' => 'salaries', 'label' => 'Bob']]], [], $errors); // records: [], $errors: ['x: its label [Bob] does not start with [TEST CLAUDE].']

References($record)

staticTestData.php:174
static function References(array $record): array
$recordarraya record of Recipe
retournearraythe keys of the records it names (@key), each once

resolve($value, $entities, $author, $dryRun)

TestData.php:315
protected function resolve(mixed $value, array $entities, object $author, bool $dryRun): mixed
$valuemixeda field's value in the recipe
$entitiesarray
$authorobjectthe account writing ($by)
$dryRunboola record not made yet stands for itself (@key)
retournemixedthe value to give the entity
lèvewhen a record $find looks for is not in the database

__construct($recipe, $store)

TestData.php:68
function __construct(array $recipe, MMO\admin\helpers\TestDataStore $store)
$recipearray
$storeTestDataStorewhere the records are read and made