public function loadUsersFromFile($filename)
{
// what are we doing?
$log = usingLog()->startAction("load test users from '{$filename}'");
// load the file
$raw = @file_get_contents($filename);
if (!$raw || empty($raw)) {
throw new E5xx_ActionFailed(__METHOD__, "cannot open file '{$filename}' or file is empty");
}
$plainUsers = json_decode($raw);
if ($plainUsers === null) {
throw new E5xx_ActionFailed(__METHOD__, "file '{$filename}' contains invalid JSON");
}
if (!is_object($plainUsers)) {
throw new E5xx_ActionFailed(__METHOD__, "file '{$filename}' must contain a JSON object");
}
// merge these in with any users we have already loaded
$users = new BaseObject();
$users->mergeFrom($plainUsers);
// remember what we've loaded
$this->st->setTestUsers($users);
// all done
$count = count(get_object_vars($users));
$log->endAction("loaded {$count} test user(s)");
return $users;
}