[Solved][CakePHP3] How to test ajax actions?

Hi,

I’m currently writing tests for controllers. Some of the actions checks if the request is an ajax one or throws an exception, with if ($this->request->is('ajax')) {}.

How can I test this actions ?

I read almost everywhere that the test have to change the headers but I have no idea on how to achieve this with PHPUnit 5.5

Your ideas are more than welcome.

In the book Setting up the Request
You should set the header
X-Requested-With: XMLHttpRequest

1 Like

Wow, thank you!
I skipped this part…