Welcome Guest, Not a member yet? Register   Sign In
Testing controller method
#1
Lightbulb 

Hi guys,

I am making some unit tests on my app, and i couldn't find how to test methods of the controllers.

I added some methods in the BaseController and i want to check the returned value of some of my methods.

I don't really need to call any specific uri.

Can anyone help me please?

Thanks.
Reply
#2

Just more details, i need to test the controller with a specific url query
Reply
#3

Create an object of BaseController,
and run a method you want to test,
and check the result.
Reply
#4

@kenjis , thank you
I did it in that way but I couldn’t get the url query
I could set the body but not the query
Reply
#5

You have to set URI by your self.
But it is a bit complicated task.

Why don't you use withURI() in ControllerTestTrait?
https://codeigniter4.github.io/CodeIgnit...er-methods
Reply
#6

"kenjis", i have tried with that way too, but i don't know how to access to the controller methods?
Reply
#7

CodeIgniter has built in controller testing capability that should be just what you need. This will test the controller itself only, skipping the HTTP layer, the controller filters, etc, but if you wanted to test the whole stack, we do have tools for full HTTP testing also.
Reply
#8

@kilishan, in need to test a returned value of one of the method of the controller. And just need a specific to set a specific query param in the url.
I have tried to test the controller with the the controller trait, or just make an instance of the controller if a new custom request in the initController method.
I can get the body of the request correctly (with $this->request->getJSON()), but not the url query (with $this->request->getGet()) even if i set it in the uri object of the request.
My function works in the application but looks like i cannot get by testing.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB