Closed jcbwlkr closed 7 years ago
Ah, yes - this is indeed related to how Bullet gets/sets the current Request
object. I will have to take a deeper look at this. As far as mocking php://input
- I am not sure, but you may be able to register a custom stream handler for php
(if you are allowed to override the built-ins).
That's worth looking in to. Another idea would be to have some class whose sole purpose is to provide the contents of php://input
. You could mock that and expect that it's only called once. I'm not sure where that would be injected so there might need to be some refactoring.
I switched this back to a raw defined
check in my fix for #43. It might also fix this issue. The permanent solution here is a breaking one - to force the Bullet\Request
to be injected into Bullet\App
as a dependency so it never creates it's own request object on demand at all.
This issue no longer seems to present, closing it.
Depending on how your app is ran, the raw body of a request might not be available inside your routes. The problem is that
\Bullet\App
instantiates a new\Bullet\Request
which consumes the contents ofphp://input
which, as is mentioned in the comments, can only be read once.Here's the setup. Given that I have this app:
And my client code looks like this:
I should get the following output
But instead I get
Digging in to the issue it seems that the problem is that when I call
$app->path
to define my route, the app internally calls$this->request()->isHHVM()
which defines a new\Bullet\Request
. That instance of request consumesphp://input
so the instance I define inecho $app->run(new \Bullet\Request());
doesn't see the raw request.If I instantiate a
\Bullet\Request
before I define my app then it gets the raw body. Or if I change the last line of my server code toecho $app->run($app->request());
I can use the instance that has the raw body.Honestly, I'm not sure how to test this. Is it possible to inject up in to
php://input
or mock it somehow?