vmpublishing/psr15-middleware-test-helpers

为测试psr-15中间件常用的几个复用模拟

1.0.4 2019-06-17 10:14 UTC

This package is auto-updated.

Last update: 2024-09-17 22:34:42 UTC


README

Code Coverage Scrutinizer Code Quality Build Status

WHAT

一组用于phpunit的通用中间件相关接口的可复用模拟集合

安装

要安装,只需使用 composer require vmpublishing/psr15-middleware-test-helpers

使用

由于这些是特性,只需在测试用例中使用它们即可


class SomeTest extends TestCase
{
    use VM\Psr15Mocks\Middleware; // include to use
    // this will generate the member variables:
    // $request
    // $response
    // $requestHandler
    // $body

    // ..

    // create them all properly
    public function setUp(): void
    {
        $this->buildResponse();
        $this->buildRequest();
        $this->buildRequestHandler();
        $this->buildBody();
    }

    // destroy them all properly
    public function tearDown(): void
    {
        $this->destroyBody();
        $this->destroyRequestHandler();
        $this->destroyRequest();
        $this->destroyResponse();
    }

    // ..

    public function testSomething(): void
    {
        // use to validate calls
        $this->response->expects($this->once())->method('getBody')->willReturn($this->body);
    }
}