vmpublishing/psr15-middleware-test-helpers

couple of often reused mocks for testing psr-15 middlewares

1.0.4 2019-06-17 10:14 UTC

This package is auto-updated.

Last update: 2024-04-17 21:30:44 UTC


README

Code Coverage Scrutinizer Code Quality Build Status

WHAT

a collection of reusable mocks for phpunit for the common middleware-related interfaces

INSTALL

To install simply use composer require vmpublishing/psr15-middleware-test-helpers

USE

As these are traits, just use them inside your testcase:


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);
    }
}