Welcome Guest, Not a member yet? Register   Sign In
How can I send JSON When using FeatureTestCase?
#1

(This post was last modified: 08-03-2020, 05:41 PM by cbw0916.)

API Document example

Create member

Code:
POST /members HTTP/1.1
Host: localhost
Content-Type: application/json

{
    "name" : "mike",
    "age" : 30
}

MemberController.php
PHP Code:
<?php
class MemberController extends Controller
{
    function create()
    {
        $data $this->reqest->getJSON();  // <-- parse JSON
        // codes..
    }




In this case, I want to make test function like this
PHP Code:
<?php
class MemberTest extends FeatureTestCase
{
    public function testCreateMember() {
        $body = [
            'name' => 'mike',
            'age' => 30,
        ];
        $result $this->post('member/v2/organs'$body);
        // codes..
    }


It doesn't work.
How can I send JSON when FeatureTestCase ?
Reply
#2

Your MemberController is not extending the Controller class.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(08-03-2020, 09:28 AM)InsiteFX Wrote: Your MemberController is not extending the Controller class.
I just didn't write this. Actually extending Controller class.
So, It doesn't matter.
Reply
#4

Use `withBodyFormat()`.

See https://codeigniter4.github.io/CodeIgnit...he-request
Reply




Theme © iAndrew 2016 - Forum software by © MyBB