cst / leantesting
Lean Testing PHP SDK
v2.0.1
2017-02-23 21:01 UTC
Requires
- php: >=5.4
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.0
- squizlabs/php_codesniffer: 2.*
This package is not auto-updated.
Last update: 2024-09-14 18:20:35 UTC
README
Lean Testing API 的 PHP 客户端
您可以在https://leantesting.com注册 Lean Testing 账户。
要求
- PHP 5.4 或更高版本
安装
通过 Composer 安装库。要安装,只需将其添加到您的 composer.json
文件
{ "require": { "cst/leantesting": "2.*" } }
然后运行 composer 更新您的依赖项
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update
基本用法
- 实例化客户端
$client = new LeanTesting\API\Client\Client(); $client->attachToken('<your token>'); // Listing projects $projects = $client->projects->all(); // Fetching project bugs $bugs = $client->projects->find(123)->bugs->all();
方法
- 获取当前 Token
$client->getCurrentToken()
- 附加新的 Token
$client->attachToken('<token>');
- 生成 授权 URL
$generated_URL = $client->auth->generateAuthLink( 'DHxaSvtpl91Xos4vb7d0GKkXRu0GJxd5Rdha2HHx', // client id 'https://www.example.com/appurl/', 'write', // scope 'a3ahdh2iqhdasdasfdjahf26' // random string ); print_r( $generated_URL );
- 将授权代码交换为 访问令牌
$token = $client->auth->exchangeAuthCode( 'DHxaSvtpl91Xos4vb7d0GKkXRu0GJxd5Rdha2asdasdx', // client id 'DpOZxNbeL1arVbjUINoA9pOhgS8FNQsOkpE4CtXU', // client secret 'authorization_code', 'JKHanMA897A7KA9ajqmxly', // auth code 'https://www.example.com/appurl/' ); print_r( $token );
- 获取 用户 信息
$client->user->getInformation()
- 获取 用户 组织
$client->user->organizations->all()->toArray()
- 检索现有的 用户组织
$client->user->organizations->find(31)->data
- 列出所有 项目
$client->projects->all()->toArray()
- 创建新的 项目
$new_project = $client->projects->create([ 'name' => 'Project135', 'organization_id' => 5779 ]); print_r( $new_project->data );
- 检索现有的 项目
$client->projects->find(3515)->data
- 列出 项目部分
$client->projects->find(3515)->sections->all()->toArray()
- 添加 项目部分
$new_section = $client->projects->find(3515)->sections->create([ 'name' => 'SectionName' ]); print_r( $new_section->data );
- 列出 项目版本
$client->projects->find(3515)->versions->all()->toArray()
- 添加 项目版本
$new_version = $client->projects->find(3515)->versions->create([ 'number' => 'v0.3.1104' ]); print_r( $new_version->data );
- 列出 项目测试用例
$client->projects->find(3515)->testCases->all()->toArray();
- 列出 项目测试运行
$client->projects->find(3515)->testRuns->all()->toArray();
- 检索测试运行的结果
$client->projects->find(3515)->testRuns->find(123)->data;
- 列出 项目用户
$client->projects->find(3515)->users->all()->toArray();
- 移除 项目用户
$client->projects->find(3515)->users->delete(123);
- 列出 错误类型方案
$client->projects->find(3515)->bugTypeScheme->all()->toArray()
- 列出 错误状态方案
$client->projects->find(3515)->bugStatusScheme->all()->toArray()
- 列出 错误严重程度方案
$client->projects->find(3515)->bugSeverityScheme->all()->toArray()
- 列出 错误可重现性方案
$client->projects->find(3515)->bugReproducibilityScheme->all()->toArray()
- 列出项目中的所有 错误
$client->projects->find(3515)->bugs->all()->toArray()
- 创建新的 错误
$new_bug = $client->projects->find(3515)->bugs->create([ 'title' => 'Something bad happened...', 'status_id' => 1, 'severity_id' => 2, 'project_version_id' => 123 ]); print_r( $new_bug->data );
- 检索现有的 错误
$client->bugs->find(123)->data
- 更新 错误
$updated_bug = $client->bugs->update(123, [ 'title' => 'Updated title', 'status_id' => 1, 'severity_id' => 2, 'project_version_id' => 123 ]); print_r( $updated_bug->data );
- 删除 错误
$client->bugs->delete(123)
- 列出错误 评论
$client->bugs->find(123)->comments->all()->toArray()
- 列出错误 附件
$client->bugs->find(123)->attachments->all()->toArray()
- 上传 附件
$file_path = '/place/Downloads/Images/1370240743_2294218.jpg'; $new_attachment = $client->bugs->find(123)->attachments->upload($file_path); print_r( $new_attachment->data )
- 检索现有的 附件
$client->attachments->find(21515)->data
- 删除 附件
$client->attachments->delete(75198)
- 列出 平台类型
$client->platform->types->all()->toArray()
- 检索 平台类型
$client->platform->types->find(1)->data
- 列出 平台设备
$client->platform->types->find(1)->devices->all()->toArray()
- 检索现有的 设备
$client->platform->devices->find(11)->data
- 列出 操作系统
$client->platform->os->all()->toArray()
- 检索现有的 操作系统
$client->platform->os->find(1)->data
- 列出 操作系统版本
$client->platform->os->find(1)->versions->all()->toArray()
- 列出 浏览器
$client->platform->browsers->all()->toArray()
- 检索现有的 浏览器
$client->platform->browsers->find(1)->data
- 列出 浏览器版本
$client->platform->browsers->find(1)->versions->all()->toArray()
- 使用 过滤器
$client->projects->find(3515)->bugs->all(['limit' => 2, 'page' => 5]).toArray();
- 实体列表 函数
$browsers = $client->platform->browsers->all() echo $browsers->total() echo $browsers->totalPages() echo $browsers->count() echo $browsers->toArray()
- 实体列表 迭代器:当在 foreach() 循环中使用时,实体列表将自动重置,无论
page
过滤器如何。循环结束后,实体列表将 不会 返回到第一页或初始实例化的page
过滤器设置,以避免产生无用的 API 请求调用。
$comments = $client->bugs->find(123)->comments->all(['limit' => 1]); foreach ($comments as $page) { print_r( $page ); }
- 实体列表 手动迭代
$comments = $client->bugs->find(123)->comments->all(['limit' => 1]); echo $comments->toArray(); // Will return false if unable to move forwards $comments->next(); echo $comments->toArray(); // Will return false if already on last page $comments->last(); echo $comments->toArray(); // Will return false if unable to move backwards $comments->previous(); echo $comments->toArray(); // Will return false if already on first page $comments->first(); echo $comments->toArray();
安全
需要报告安全漏洞?请发送电子邮件至 support@crowdsourcedtesting.com 或直接访问我们的安全漏洞赏金网站 https://hackerone.com/leantesting。
开发
安装依赖项
composer install
测试
按照上述说明安装依赖项(这将解决 PHPUnit),然后您可以运行测试套件
./vendor/bin/phpunit
贡献
有关详细信息,请参阅 CONTRIBUTING。