Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking request query string? #30

Closed
michaelherold opened this issue Apr 26, 2016 · 5 comments
Closed

Checking request query string? #30

michaelherold opened this issue Apr 26, 2016 · 5 comments

Comments

@michaelherold
Copy link

Is there a way to check the query string of a request (particularly for GET requests)? I want to make sure a transformation in my request wrapper actually occurs when I make the request.

If this isn't yet possible, here's the API I would expect:

$this->http->mock
    ->when()
        ->methodIs("GET")
        ->pathIs("/my/test/path")
        ->queryIs("param1=test1&param2=test2")
    ->then()->body("{}")->statusCode(200)
    ->end();

or

$this->http->mock
    ->when()
        ->methodIs("GET")
        ->pathIs("/my/test/path")
        ->queryIs(array("param1" => "test1", "param2" => "test2"))
    ->then()->body("{}")->statusCode(200)
    ->end();

PS: Thank you for making this library. It's nice to be able to mock HTTP requests in my test suite.

@lstrojny
Copy link
Contributor

Generally you can do anything by passing a matching callback. See this example:

        $this->http->mock
            ->when()
                ->callback(
                    function (Request $request) {
                        return $request->query->has('key1');
                    }
                )
                ->methodIs('GET')
            ->then()
                ->body('query string')
            ->end();
        $this->http->setUp();

But you are right, we should have a convenient API to do so. Let me think about it.

@michaelherold
Copy link
Author

Awesome! Thank you - I missed the callback functionality.

@lstrojny
Copy link
Contributor

Was hard to find without reading the code so far. I finally got around adding some documentation. Have a look here, maybe you can find some more gems: https://github.com/InterNations/http-mock/blob/master/doc/index.md

@lstrojny
Copy link
Contributor

Have a look at #31! Feedback welcome

@lstrojny
Copy link
Contributor

Merged #31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants