-
How can one correctly pass parameters as I've been struggling to get this working as following: it('asserts response code + result', function () {
// Initialize data
$request = ['parameter' => 'foo'];
$response = ['code' => 200, 'result' => 'bar'];
$headers = ['Content-Type' => 'application/x-www-form-urlencoded'];
// Test case
$test_response = $this->post('api/endpoint', $request, $headers);
$test_response->assertStatus(200)->assertJson($response);
}); The API I'm working within my example, Original issue: #615 |
Beta Was this translation helpful? Give feedback.
Answered by
Rikj000
Nov 28, 2022
Replies: 1 comment
-
I hope there is a better way to do this, it('/api/endpoint route asserts status code 200 + expected response', function () {
// Initialize the POST data
$_POST = ['parameter' => 'foo'];
// Initialize the expected response data
$expected_response = ['code' => 200, 'result' => 'bar'];
// Run the test case
$test_response = $this->post('/api/endpoint', $_POST);
$test_response->assertStatus(200)->assertJson($expected_response);
}); Recommendations for improvements are very welcome! 🙂 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Rikj000
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I hope there is a better way to do this,
but for now I've managed to work around the issue,
through directly initializing the
$_POST
parameter inside theit()
function:Recommendations for improvements are very welcome! 🙂