Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rodosabbath's avatar

API Tests with PHP Pest. Is it the intended behavior for the requests not be shown in server logs?

Hello guys, just started working with Pest and testing.

I've defined a test to check my clients API and it runs smoothly as I expect:

it('returns clientes correctly', function () {
    $response = $this->get('api/clients');
    $response->assertStatus(200);
});

Feature/ClientsTest.php on line 3

   PASS  Tests\Feature\ClientsTest
  ✓ it returns clientes correctly                                                                                                                                                          0.28s  

  Tests:    1 passed (1 assertions)
  Duration: 0.54s

I went to further monitor this and noticed my Apache logs do not log anything after the test pass, though when making the request from a client like Postman/Insomnia it logs normally.

Is this correct when testing? Does it use an internal mecanism for it?

At the same time, I checked my MariaDB logs and it indeed makes a retrieval to the clients table. Since I have more HTTP methods to be tested this concerned me a little.

Appreciate any feedback. Cheers.

0 likes
2 replies
martinbean's avatar
Level 80

@rodosabbath Yes, it’s intended behaviour for the requests to not appear in your server logs, because HTTP requests aren’t actually being made. When running tests, an instance of the Laravel application is booted and the request just passed through the router. Essentially:

$laravel = new Laravel();
$response = $laravel->handle($request);

(That’s not the actual code, but demonstrates kinda how it’s handled.)

Because real HTTP requests aren’t made during test cases, this is the reason you shouldn’t perform multiple requests in a single test case, as the Laravel framework isn’t cleared between requests in test cases, so you may end up with weird, state-related bugs if you do perform multiple requests in a single test case:

public function test_bad_case(): void
{
    // Don't do this...
    $response1 = $this->get('/foo');
    $response2 = $this->get('/foo');
}
1 like
rodosabbath's avatar

@martinbean Thanks a lot for the detailed response. Now it made it clear for me.

Appreciate your time, cheers!

1 like

Please or to participate in this conversation.