Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 711 Vote(s) - 3.43 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get Lumen response content as string?

#1
What I'm trying is to get the response content as string from an unit test with Lumen response:

```php
class MovieQueryTest extends TestCase
{
use DatabaseMigrations;

public function testCanSearch()
{
Movie::create([
'name' => 'Fast & Furious 8',
'alias' => 'Fast and Furious 8',
'year' => 2016
]);

$response = $this->post('/graphql', [
'query' => '{movies(search: "Fast & Furious"){data{name}}}'
]);

$response->getContent(); // Error: Call to undefined method MovieQueryTest::getContent()
$response->getOriginalContent(); // Error: Call to undefined method MovieQueryTest::getOriginalContent()
$response->content; // ErrorException: Undefined property: MovieQueryTest::$content
}
}
```

But I'm unable to figure out how to get the response content.

I don't want to use the Lumen `TestCase->seeJson()` method.

I just need to get the response content.
Reply

#2
The `$response` also contains a `response` field on which you need to call `getContent()`, therefore you first need to extract that and then call `getContent()`, so in your code this would become:


public function testCanSearch()
{
Movie::create([
'name' => 'Fast & Furious 8',
'alias' => 'Fast and Furious 8',
'year' => 2016
]);

$response = $this->post('/graphql', [
'query' => '{movies(search: "Fast & Furious"){data{name}}}'
]);

$extractedResponse = $response->response; // Extract the response object
$responseContent = $extractedResponse->getContent(); // Extract the content from the response object

$responseContent = $response->response->getContent(); // Alternative one-liner

}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through