Summer Sale! All accounts are 50% off this week.

thomasdiluccio's avatar

Make real HTTP requests in the testing environment

Hi, I'm working on the integration of Blackfire performance tests within our Laravel integration tests.

At the end of the end, I wish we could have something as:

$response = $this->get('/test/foo');
$response->assertBlackfire();

A real profile should be triggered and all the matching assertions defined in the Blackfire conf file evaluated.

To do so, I need to make a real request, with Guzzle by instance, so that the Blackfire probe could detect and instrument the request. But, I need to stay within the testing environment, not to mess with real data.

Do you see any possibilities of doing so?

Thanks

0 likes
5 replies
Tray2's avatar

If you have set up a testing database you should be good.

thomasdiluccio's avatar

@Tray2 Not quite, maybe. If I stick with the actual behavior of $this->get('/test/foo');, I will indeed stay within the testing environment. But I won't make an actual HTTP request, and the Blackfire probe won't detect and instrument it. We are just passing stuff directly to the kernel already boot-up.

What I like to do is to override this with a middleware so as to make a full request transforming $this->get('/test/foo'); into Http::get('https://my.domain.or.localhost/test/foo');

Yet, I cannot execute the latter request forcing Laravel to use the testing environment.

martinbean's avatar

@thomasdiluccio And if you look at that example, it’s testing internal things like number of SQL queries executed. That doesn’t mean you should be making real HTTP requests in your test suite.

But none yet with the functional tests of Laravel https://laravel.com/docs/8.x/testing

Laravel’s test framework is built around PHPUnit. It’s not a completely separate entity. It’s just PHPUnit with a few helper methods.

Please or to participate in this conversation.