New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REST] Set response headers in hive for unit tests #258
Comments
For validating headers in a mocked run, you can simply use $f3->set('QUIET',TRUE);
$f3->route('GET /test',function($f3){
header("Content-Type: application/json");
echo json_encode(['foo'=>'bar']);
});
$f3->mock('GET /test');
$headers = headers_list();
header_remove();
$f3->set('QUIET',false);
header("Content-Type: text");
var_dump($headers);
var_dump($f3->get('RESPONSE')); We use this method in the framework unit tests as well. |
Hi @ikkez, and thanks for your response. But I've found this thread that seems to be a good workaround: sebastianbergmann/phpunit#720 I'll try the |
Erf, it could have worked if only another error has not arised: sebastianbergmann/phpunit#2739 So the only way to make it work I found was using PHPUnit's I'm closing this issue. |
Just like you can retrieve response data through
$f3->get('RESPONSE')
, it should be possible to retrieve headers with$f3->get('RESPONSE_HEADERS')
(for example) in order to validate their content with unit tests.Also, as a side note, that probably means that F3 should never call the
header()
function directly, but instead push headers to this reserved stack. In normal run, the headers would eventually then be sent viaheader()
, but in simulated run (\Base::mock()
) these data would be made available for validation in the test case.I'm afraid to open a PR with such huge, possibily breaking change, so I'll be happy to get feedback from the community first. (maybe it has already been discussed?)
The text was updated successfully, but these errors were encountered: