message icon indicating copy to clipboard operation
message copied to clipboard

Additional implementations of RequestMatcher

Open localheinz opened this issue 5 years ago • 1 comments

Q A
Bug? no
New Feature? yes
Version n/a

Question

In a project we are currently using implementations of the RequestMatcher which allow us to reuse and compose request matchers.

For example

$httpClient->on(
    AllOf::matchers(
        Method::is('GET'),
        Path::is('foo/bar'),
        Uri\QueryParameters::are([
            'baz' => '1',
            'qux' => 'hmm',
        ])
    ),
    new Psr7\Response(Http::OK)
);

Would there be interest in having these pushed upstream, that is, into this repository?

localheinz avatar Aug 03 '19 18:08 localheinz

i think generally we are open to contributions.

while this is quite expressive to read, i think this creates a lot of classes and method calls. how about a RequestMatcherFactory with fluent interface?

$rmf
    ->method('GET')
    ->path('foo/bar')
    ->queryParameters(['baz' => '1'])
    ->getMatcher()
;

i see that your approach could also do AnyOf or something like that, but i doubt that comes up much - and there is still the CallbackRequestMatcher for such situations.

dbu avatar Aug 06 '19 06:08 dbu