PHP code example of razonyang / swoole-unit

1. Go to this page and download the library: Download razonyang/swoole-unit library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

razonyang / swoole-unit example snippets



$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();

$data = [
    'hello' => 'world',
];
$request = RequestBuilder::post('/users')
    ->formData($data)
    ->create()

$data = [
    'hello' => 'world',
];
$files = [
    'avatar' => __DIR__ . DIRECTORY_SEPARATOR . 'avatar.jpg',
];
$request = RequestBuilder::post('/users')
    ->multipart($data, $files)
    ->create()

$data = [
    'hello' => 'world',
];
$request = RequestBuilder::post('/users')
    ->jsonData($data)
    ->create()