Welcome Guest, Not a member yet? Register   Sign In
HTTP Feature Testing PUT not sending data
#1

Hello,

I am trying to write a unit test for an update endpoint using PUT method.

Normally I receive the data in the controller with getRawInput, however when the unit test sends it, this is empty.

The unit test code is as following:

PHP Code:
$result $this->withSession($this->testSession)->put('accounts/'.$lastId, [
            "username" => "testuser",
            "password" => "testpassword",
            "is_enabled" => 1,  
        
]); 

The update endpoint looks like this:



PHP Code:
public function update($id null)
{
  
        $data 
$this->request->getRawInput();
        if(count($data) == 0)
        {
            return $this->failNotFound("raw input is empty");
        }




It will return with the failNotFound because the raw input array is empty.

I am doing the similar request for POST to the create function and there it does work and send the data.

Does the PUT request have other requirements or am I doing something wrong?
Reply
#2

(This post was last modified: 01-06-2021, 05:05 AM by iRedds.)

(01-05-2021, 08:55 PM)gvandenbosch Wrote: Does the PUT request have other requirements or am I doing something wrong?

As far as I understand the code, tests in version 4.0.4 do not support placing data in the request body.
This means that you cannot use method getRawInput() for tests.

But the functional is already in the development branch.
Reply
#3

Thank you, I managed to get it working by manually applying this commit:

https://github.com/codeigniter4/CodeIgni...10981ff363
Reply




Theme © iAndrew 2016 - Forum software by © MyBB