PSR-7 request matcher equivalent of Symfony's RequestMatcher.
You may use Composer to install this package:
composer require fansipan/request-matcher
To create a matcher instance with your assertions, you can use the following example to match the request host:
use Fansipan\RequestMatcher\HostRequestMatcher;
use Psr\Http\Message\RequestInterface;
$matcher = new HostRequestMatcher('localhost');
// Matches http://localhost
/** @var RequestInterface $request */
$matcher->matches($request);
You can also create a matcher using a callback. For instance:
use Fansipan\RequestMatcher\CallbackRequestMatcher;
use Psr\Http\Message\RequestInterface;
$matcher = new CallbackRequestMatcher(static fn (RequestInterface $request) => $request->getUri()->getScheme() === 'https' && $request->getUri()->getHost() === 'my.app');
The example above can be grouped by using ChainRequestMatcher
use Fansipan\RequestMatcher\CallbackRequestMatcher;
use Fansipan\RequestMatcher\HostRequestMatcher;
use Fansipan\RequestMatcher\SchemeRequestMatcher;
use Psr\Http\Message\RequestInterface;
$matcher = new ChainRequestMatcher([
new SchemeRequestMatcher('https'),
new HostRequestMatcher('my.app'),
]);
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.