razonyang/swoole-unit

PSR-7 implementation for Swoole

1.0.0 2022-09-18 06:33 UTC

This package is auto-updated.

Last update: 2024-10-24 13:11:55 UTC


README

Latest Stable Version Total Downloads Build Status Coverage Status StyleCI

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