I wrote a hyperf test case extension that provides a test case method that is almost consistent with laravel

Time:2021-12-1

preface

Everyone who uses laravel and then uses hyperf knows that there is a big gap between the written test cases of hyperf and laravel, and does not support detailed assertions of response, such as status, response header, etc. But sometimes I have to assert, so I wrote this extension.

qbhy/hyperf-testing

The expansion package can provide andlaravelAlmost consistent test case writing experience

Install – install

$ composer require qbhy/hyperf-testing

Use – Usage

1. ModificationHyperfTest\HttpTestCaseof$client, put the defaultClientChange toQbhy\HyperfTesting\Client
2. Modify test cases

<?php

namespace HyperfTest\Cases\Dev;

use HyperfTest\HttpTestCase;
use Qbhy\HyperfTesting\Client;
use Qbhy\HyperfTesting\TestResponse;

/**
 * Class DevTest * @method TestResponse get($uri, $data = [], $headers = []) * @method TestResponse post($uri, $data = [], $headers = []) * @method TestResponse delete($uri, $data = [], $headers = []) * @method TestResponse put($uri, $data = [], $headers = []) * @method TestResponse json($uri, $data = [], $headers = []) * @method TestResponse file($uri, $data = [], $headers = []) * @package HyperfTest\Cases\Dev */class DevTest extends HttpTestCase
{
 public function __construct($name = null, array $data = [], $dataName = '') { parent::__construct($name, $data, $dataName); $this->client = make(Client::class); }
 public function testExample() { $this->get('/')->assertOk()->assertJsonStructure([ 'data', 'code', 'message', ]); }}

Cookies and session related assertions are not supported at the moment!

Statement – statement

The package makes a lot of reference to laravel’s code. Thanks to laravel for implementing such easy-to-use test case components.

github.com/qbhy/hyperf-testing
[email protected]

This work adoptsCC agreement, reprint must indicate the author and the link to this article