Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jonnybarnes's avatar

I can’t test a POST request in lumen

I have a route that can receive POST requests. Currently, if the parameter foo is not set the app returns a 400 error, and if the parameter foo is set to an unknown value a 501 error is returned. This works when I manually hit the route with curl.

I can’t get this to work in my unit test, setting an unknown value for “foo” still results in a 400 response. This is how I‘m doing it:

$this->call('POST', '/', ['foo' => 'uknown']);

Anyone any ideas?

EDIT: seems laracasts doesn’t like the backtick character

0 likes
4 replies
bashy's avatar

Shouldn't this be in "testing" category?

jonnybarnes's avatar

oh dear, didn't realise there was a testing category.

bobbybouwmann's avatar

How is your route setup? And since you are testing you probably have an output log somewhere so you can see the error messages. A 400 response doesn't really help here, we need to see the real error here!

jonnybarnes's avatar

So explicitly I’m trying to test this method (there will be more options added to the switch in due course):

public function checkMode(Request $request)
{
    if (null !== $request->input('hub_mode')) {
        switch ($request->input('hub_mode')) {
            case 'publish':
                $t = new TopicsController();
                $t->update($request);
                break;
                
            default:
                return (new Response('I don’t know this value for <code>hub.mode</code>', 501));
                break;
        }
    } else {
        return (new Response('<code>hub.mode</code> must be set', 400));
    }
}

Please or to participate in this conversation.