Robert-Jan's avatar

Test with PSR ServerRequestInterface has empty body

I have a TestCase with the following test:

public function test_password_grant_token_request()
    {
        $this->json('POST', '/authentication/token', [
            'grant_type'    => 'password',
            'client_id'     => 'test',
            'client_secret' => 'test',
            'username'      => 'test1@example.com',
            'password'      => 'Test1234'
        ])
        ->assertResponseOk()
        ->seeJsonStructure([
            'token_type',
            'expires_in',
            'access_token',
            'refresh_token'
        ]);
    }

I make use of the PHP OAuth 2.0 Server witch uses PSR7-compatible HTTP requests and responses. A dd() during a normal request gives the following response:

Zend\Diactoros\ServerRequest {#212
  -attributes: []
  -cookieParams: []
  -parsedBody: array:5 [
    "grant_type" => "password"
    "client_id" => "test"
    "client_secret" => "test"
    "username" => "test1@example.com"
    "password" => "Test1234"
  ]
  ...
]

But when i run the test i got the following response from the dd() in my console:

Zend\Diactoros\ServerRequest {#322
  -attributes: []
  -cookieParams: []
  -parsedBody: []
  ...
]

I don't know how to get the test to work with the PSR7 ServerRequest. Does anyone encountered this problem and have a solution for my? Thanks in advance!

0 likes
1 reply
Robert-Jan's avatar

Does someone have the solution for me? I am new with tests and am eager to get this working.

Please or to participate in this conversation.