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

PeterF's avatar

Laravel Logging during unit tests

Hi All. I am running vscode, and my unit tests that run in that environment, don't seem to have logging working. I am not sure if its a phpunit setting that is swallowing my Log::debug statements, or my vscode unit test runner.... everything is in valet, and logging works fine for everything else, its just debuging my unit tests when they dont do what I expect, the logging in my project code, once called through the unit testing framework, just ignores the Log statements... are they going somewhere weird that I just haven't looked, or are they being silently discarded?

0 likes
4 replies
tykus's avatar

Are you using Log Fake? Or do you a specific logging configuration for testing environment?

PeterF's avatar

@tykus I have a standard set of Log values in my .env.testing that I have in my normal .env so I thought it would go to the normal log file. Is there a faker built in somewhere for unit testing that I need to find and configure?

tykus's avatar

@PeterF when you say Unit Testing; does your test class use PHPUnit\Framework\TestCase or Tests\TestCase parent class? The PHPUnit parent class does not boot the framework, so logging is not available.

PeterF's avatar

@tykus it extends the Tests\TestCase and I even have a

protected function setUp(): void
    {
        parent::setUp();
    }

to be sure.....

Please or to participate in this conversation.