ARTICLE AD BOX
I'm searching for a way to get the HTTP response code in Codeception without actually verifying it in API tests (end-to-end).
Composer.json:
"codeception/codeception": ">=5.1.2", "codeception/module-phpbrowser": ">=3.0.1", "codeception/module-asserts": ">=3.0.0", "codeception/module-rest": ">=3.3.2",In my test I have two possible response codes. The API call returns 200 if the object was created and 409 if the object already exists (was pushed multiple times). So the API behavior is correct. In my Codeception tests for certain environments I simply do not know if the object already exists, so I have to check if it is either 200 or 409. Both are acceptable, it cannot be changed.
I have tried this but it makes the test fail in certain cases - even if the HTTP response code is 200 or 409:
$found = false; foreach($responseCodeExpected as $rce) { try{ $t->canSeeResponseCodeIs($rce); $found = true; break; } catch (\Throwable $t) { continue; } } if(!$found) { throw new RuntimeException("No matching response code found in the provided array."); }Looks like the issue is triggered by $t->canSeeResponseCodeIs($rce);, if this is called on the wrong response code, that means a test failure.
How to just get the HTTP response code?
