silverslice / http-tester
轻量级http测试工具
dev-master
2023-03-16 00:41 UTC
Requires
- php: >=8.0
- ext-curl: *
Requires (Dev)
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-09-16 04:17:44 UTC
README
HttpTester 是 curl 的一个薄包装器,用于测试 http 请求。如果您需要更复杂的工具,请使用 Goutte 或其组件之一。
安装
php composer.phar require silverslice/http-tester:dev-master
使用示例
require __DIR__ . '/../vendor/autoload.php'; use Silverslice\HttpTester\Request; class EasyTest extends \PHPUnit_Framework_TestCase { public function testSimple() { $request = new Request(); $response = $request ->get('https://getcomposer.org/') ->setReferrer('https://php.ac.cn/') ->setUserAgent('Curl agent') ->setCookie('hello', 'world') ->send(); // the response has status code "200" $this->assertTrue($response->isSuccess()); // the response body has title "Composer" $this->assertTrue($response->hasTitle('Composer')); // the response body has this part $this->assertTrue($response->hasHtml('<a href="https://packagist.org.cn/">Browse Packages</a>')); // the response hasn't this cookie $this->assertFalse($response->hasCookie('laravel_session')); } public function testSendJson() { $request = new Request(); $response = $request ->post('https://:8000/json', ['name' => 'John']) ->asJson() ->send(); $json = $response->getBodyJson(); $this->assertEquals('John', $json['name']); } }