amorpro3 / smoke-tests
此包的最新版本(dev-master)没有可用的许可证信息。
软件开发工具包,包含在项目中启动烟雾测试的工具
dev-master
2021-08-20 19:54 UTC
Requires
- php: 7.2.*
- ext-curl: *
- ext-json: *
- paquettg/php-html-parser: 3.1.*
- webmozart/assert: 1.*
- wp-cli/php-cli-tools: v0.11.*
Requires (Dev)
- phpunit/phpunit: 8.*
This package is auto-updated.
Last update: 2024-09-13 21:32:46 UTC
README
在项目中实现烟雾测试的库。
示例
<? use SmokeTests\Http\Header; use SmokeTests\Http\Response; use SmokeTests\Plugins\Display\Detailed; include_once './vendor/autoload.php'; $tests = (new \SmokeTests\Config\Json()) ->setNext(new \SmokeTests\Config\Php()) ->load('./configs/tests.json', 'http://landing'); foreach ($tests as $test) { $handler = SmokeTests\Handler::createFromConfig($test); $handler->addPlugin(new \SmokeTests\Plugins\Display\Detailed()); $response = $handler->handle(); }
结果
SmokeTests\Plugins\Log\Console\Detailed 插件
将提供关于测试和过程的详细信息
GET /api/jdialog/pornworld.js : OK
GET / : OK
GET / : OK
GET / : OK
ERROR Test [GET http://landing/api/user-data] is disabled
GET /api/user-data?username={username}&jdialog=jdialog3=t3a975ya71oubbcb6lag6y9wcmuhlfe9ia51uoegqmzinfcdfg : OK
SmokeTests\Plugins\Log\Console\Simple 插件
将提供关于测试的最基本信息,点 "." 表示 OK,"E" 表示失败
..E....
SmokeTests\Plugins\Log\Console\Failed 插件
仅提供失败的测试的详细信息
GET / : ERROR Test [GET http://landing/] is disabled
配置
支持以下类型的配置格式
最小配置加载代码
$tests = (new \SmokeTests\Config\Php()) ->load('./configs/tests.php', 'http://landing');
最小测试示例
return [ [ 'uri' => 'GET /', ], [ 'uri' => 'GET http://landing/', ], [ // Will be overwrited with http:// google.com from the uri bellow 'host' => 'http://landing', 'uri' => 'GET http://google/', ], ]
在前两个测试中,将调用 http://landing/ url,在第三个测试中调用 http://google.com。所有测试都将使用 GET 方法调用,并且仅在最小配置中测试 http_code = 200。在 uri 中设置的 host 优先级高于 'host' 选项,并将其使用,而不是使用它
完整测试示例
return [ [ // (Optional) can be filled automatically via config loader (see Config topic above) 'host' => 'http://landing', // (Required) Format for the url: (GET|POST|PUT|DELETE) [HOST, optional, override host config from above]/(uri) 'uri' => 'GET http/site.com/new_scenes', // (Optional) During the test the headers from bellow will be attached to the http request as POST or GET data 'data' => [ 'username' => 'amorpro3' ], // (Optional) During the test the headers from bellow will be attached to the http request 'headers' => [ 'Content-Type' => 'application/json' ], // (Optional) During the tests the cookies from bellow will be attached to the http request 'cookies' => [ 'is_authorize' => 111 ], // (Optional, default=true) If the enabled=false then test will be not called 'enabled' => true, // (Optional) Contains the actions that need to be done with the http response 'response' => [ // VALIDATION options // (Optional) SmokeTests\Plugins\Response\Status // Will check that the result contains 404 http_code 'status' => 404, // (Optional) SmokeTests\Plugins\Response\Contains // Will check that the result contains provided string or strings 'contains' => 'recommended', 'contains' => [ 'recommended', 'scenes', ], // (Optional) SmokeTests\Plugins\Response\Cookies // Will check that the result contains cookies from below 'cookies' => [ 'jdialog' => 't3a975ya71oubbcb6lag6y9wcmuhlfe9ia51uoegqmzinfcdfg', ], // (Optional) SmokeTests\Plugins\Response\Headers // Will check that the result contains headers from below 'headers' => [ 'Content-Type' => 'text/plain', ], // UTILITY options // (Optional) SmokeTests\Plugins\Response\Store // Provide an ability to save keys username or username+email from the json response // globally to be able to use them in the next tests via {username} ot {email} // Stored vars can be used in next options: url, data, cookies, headers. // Full example can be found bellow in the "Store and Store Cookies example" topic 'store' => 'username', 'store' => [ 'username', 'email', ], // (Optional) SmokeTests\Plugins\Response\StoreCookies // The same as Store utility from above but the variables will be taken // from the cookies that were returned in response. 'store_cookies' => 'jdialog3', 'store_cookies' => [ 'jdialog3', 'is_authorized', ], ], ] ]
存储和存储 Cookies 示例
存储和存储 Cookies 工具帮助您进行更复杂的测试,这些测试预先从某个测试中加载一些数据,并在之后的任何后续测试中使用它们
return [ // Request to get 'jdialog' cookie [ 'uri' => 'GET https://account.analvids.com/api/jdialog/pornworld.js', 'response' => [ 'store_cookies' => 'jdialog3' ] ], // Request to get 'website_user_id' and 'username' variables from the json response [ 'uri' => 'GET /api/user-data', 'response' => [ 'store' => 'website_user_id', 'store' => 'username', ], ], // Use 'jdialog', 'website_user_id' and 'username' to validate some data [ 'uri' => 'GET /api/get-scenes?website_user_id={website_user_id}', 'data' => [ 'website_user_id' => '{website_user_id}' ] 'response' => [ 'contains' => '{username}', 'cookies' => [ 'jdialog3' => '{jdialog3}' ] ] ], ];