Welcome Guest, Not a member yet? Register   Sign In
Testing a controller that has validation: getVar don't work
#3

(03-01-2023, 12:30 AM)kenjis Wrote: I think using getPost() is better when you use POST requests.
Why do you need to use getVar()?

Ah, $this->validate() uses getVar()!

1. use $this->validateData() https://codeigniter4.github.io/CodeIgnit...lidatedata
2. set 'request' in the test.
PHP Code:
        $request->setGlobal('request', [
            'user_id' => '1',
            'type'  => 'test',
            'description' => 'This is a test!',
        ]); 

For now I setted 'request' in the test and it works! But I'll change all validations to use 'validateData' because seem to me the right way to solve this.

Thanks!
Reply


Messages In This Thread
RE: Testing a controller that has validation: getVar don't work - by evandroagnes - 03-01-2023, 02:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB