Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/razonyang/swoole-unit

The unit test helpers for Swoole
https://github.com/razonyang/swoole-unit

swoole unit-test unit-testing

Last synced: 28 days ago
JSON representation

The unit test helpers for Swoole

Awesome Lists containing this project

README

        

# Swoole Unit Test Helpers

[![Latest Stable Version](https://poser.pugx.org/razonyang/swoole-unit/v/stable.png)](https://packagist.org/packages/razonyang/swoole-unit)
[![Total Downloads](https://poser.pugx.org/razonyang/swoole-unit/downloads.png)](https://packagist.org/packages/razonyang/swoole-unit)
[![Build Status](https://github.com/razonyang/swoole-unit/actions/workflows/build.yml/badge.svg)](https://github.com/razonyang/swoole-unit/actions)
[![Coverage Status](https://coveralls.io/repos/github/razonyang/swoole-unit/badge.svg?branch=main)](https://coveralls.io/github/razonyang/swoole-unit?branch=main)
[![StyleCI](https://github.styleci.io/repos/537780358/shield?branch=main)](https://github.styleci.io/repos/537780358?branch=main)

## Installation

```bash
composer require razonyang/swoole-unit --prefer-dist --dev
```

## Helpers

### Request Builder

The `RequestBuilder` generates `Swoole\Http\Request` instances.

```php
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

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

#### Multipart Form Data

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

#### JSON Data

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