razonyang / swoole-unit
PSR-7 implementation for Swoole
1.0.0
2022-09-18 06:33 UTC
Requires
- php: ^8.0
- ext-swoole: ^4.8|^5.0
- nyholm/psr7: ^1.5
Requires (Dev)
- phpunit/phpunit: ^9.5
- razonyang/unit-helper: ^1.0
- swoole/ide-helper: ^5.0
This package is auto-updated.
Last update: 2024-10-24 13:11:55 UTC
README
Installation
composer require razonyang/swoole-unit --prefer-dist --dev
Helpers
Request Builder
The RequestBuilder
generates Swoole\Http\Request
instances.
<?php $request = RequestBuilder::get('/') ->protocol('HTTP/1.1') ->host('localhost') ->contentType('application/x-www-form-urlencoded') ->contentLength(8) ->headers([ 'X-Foo' => [ 'Bar', ], ]) ->body('hello=world') ->create();
The RequestBuilder
supports chaining calls until create
.
Form Data
$data = [ 'hello' => 'world', ]; $request = RequestBuilder::post('/users') ->formData($data) ->create()
Multipart Form Data
$data = [ 'hello' => 'world', ]; $files = [ 'avatar' => __DIR__ . DIRECTORY_SEPARATOR . 'avatar.jpg', ]; $request = RequestBuilder::post('/users') ->multipart($data, $files) ->create()
JSON Data
$data = [ 'hello' => 'world', ]; $request = RequestBuilder::post('/users') ->jsonData($data) ->create()