Replies: 1 comment 2 replies
-
Not sure we have a recommended solution for this just yet. From what I recall, the last time we looked at integrating the Codeception REST module, we ran into some issues we never found a good solution for, hence this workaround. I can't recall the specifics, but maybe @nfourtythree does. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
what is the recommended way to setup codeception tests for API / RESTful controller actions? I was able to setup codeception tests for Craft CMS and know a bit about fixtures, unit tests and stuff like that.
What I don´t get is how I can make calls / requests against the test instance .. as we know, we need to copy the project config into the test folder, tests are executed with the test project config, using a different database than the usual project config and so on. My goal is to setup test cases for JSON Responses.
When using codeception and following their recommended setup for REST tests (https://codeception.com/docs/modules/REST), I can make requests like this
My codeception configuration looks like this
I don´t get which url I should use to fire those requests against the test instance. As far as I understand, making an actual request leaves the test context completely -> the usual instance is receiving those requests without the testing context..
As far as I understand, one way is to make no real request but calling the controller actions directly like Craft Commerce does (https://github.com/craftcms/commerce/blob/develop/tests/unit/controllers/CartTest.php)
While this seems to work as expected, my question remains -> Is this the recommended way to test controller actions? Is there any option to make "real" HTTP requests / utilizing the HTTP features of codeception? Are there any downsides (besides creating a request object by hand) of calling the controller actions directly?
I hope I could express my problem understandably.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions