acromedia/mock-totara

模拟 Totara 的应用程序

dev-master 2020-04-02 20:48 UTC

This package is not auto-updated.

Last update: 2024-09-26 01:58:41 UTC


README

此应用程序模拟 Moodle 网站的 API,并记录一些状态信息,以便断言诸如你不能将某人添加到尚未添加到课程中的组等情况。

安装应用程序

使用 composer 安装依赖项。

$ composer install

用法

将 Web 服务器指向 index.php 或使用 PHP 内置的服务器。

$ composer start
> php -S localhost:8080 -t public

/api?wsfunction=foo 发送请求,其中 foo 是 Moodle 网服务的名称。

POST localhost:8080/api?wsfunction=core_users_create_user

... Some request to create a user.

响应将是该网络服务的标准响应。

{
  "id": 1234,
  "some other stuff": "huzzah!"
}

或者是一个错误!

{
  "exception": "invalid parameter exception",
  "message": "Invalid parameter value detected.",
  "errorcode": "invalidparameter",
  // Moodle doesn't like to explain its errors but that doesn't mean we can't.
  "debuginfo": [
    "User 123 must first be enrolled in course 456."
  ]
}

应用程序的状态在请求之间保存。在 settings.php 中设置文件路径,其中将存储状态。

'state' => [
    // State is saved here between requests.
    'path' => '../state.json',
],

要重置状态,向 /api/state 发送 DELETE 请求或使用 composer reset-state

$ composer reset-state
> curl -s localhost:8080/api/state --header "Accept: application/json"  --header "Content-Type: application/JSON" --request DELETE