-
Notifications
You must be signed in to change notification settings - Fork 195
Description
PHPUnit 9.6.22
ci-phpunit-test 3.0.4 via composer
php 7.4
Doc Reference
Problem: When I run this test
/**
* Testing retrieval of Courses via API call w/o Authorization Header
* Should return a JSON object with message
*/
public function test_call_courses_wo_auth_header()
{
$output = $this->request('GET', 'api/v1/courses');
// Tried:
// ob_start();
// $this->request('GET', 'api/v1/courses');
// $output = ob_get_clean();
// Same result
// Tried:
// $output = var_export($this->request('GET', 'api/v1/courses'), TRUE);
// Same result
$this->assertResponseCode(400);
$exp_json_resp = '{
"status": "errors",
"code": "400",
"messages": [
"Authorization Header Missing"
]
}';
$this->assertSame($exp_json_resp, $output);
$arr_response = json_decode($output);
$this->assertIsArray($arr_response);
$this->assertArrayHasKey('status', $arr_response);
$this->assertArrayHasKey('code', $arr_response);
$this->assertArrayHasKey('messages', $arr_response);
$this->assertSame('errors', $arr_response['status']);
$this->assertSame('400', $arr_response['code']);
$this->assertIsArray($arr_response, $arr_response['messages']);
$this->assertSame('Authorization Header Missing', $arr_response['messages'][0]);
}
I get this response and no other tests run
PHPUnit 9.6.22 by Sebastian Bergmann and contributors.
Warning: No code coverage driver available
{
"status": "errors",
"code": "400",
"messages": [
"Authorization Header Missing"
]
}
It is like the response is not going to the variable but directly to stdout. The same thing happens when I include the --stderr switch in the cli call.
$this->request() calls to other controllers seem to be working fine.
I don't know if this is a ci-phpunit-test issue or something I am doing wrong. I don't understand why a request returning a JSON string returns different from returning an HTML page.
Any assistance is appreciated.