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

Bondacom's avatar

[PHPUnit] No exceptions shown when test fails

PHPUnit is working fine, tests fail when they have to, but I can't see the exception that was thrown when that happens. My tests/RoutingTest class has

class RoutingTest extends TestCase {

    public function test_it_shows_dashboard()
    {
        $this->call('GET', '/');
        
        $this->assertResponseOk();
    }
}

But, since my routes file is empty, it should fail. As I said, that's working fine. In fact, the response I when running gulp (which runs mix.phpUnit()) is

[19:38:43] Using gulpfile ~/Code/Interviews/Site/gulpfile.js
[19:38:43] Starting 'default'...
[19:38:43] Starting 'phpunit'...
[19:38:44] Finished 'default' after 514 ms
[19:38:44] 

       *** Debug Cmd: ./vendor/bin/phpunit --colors --debug ***

[19:38:44] PHPUnit 4.5.0 by Sebastian Bergmann and contributors.

Configuration read from /home/vagrant/Code/Interviews/Site/phpunit.xml


Starting test 'RoutingTest::test_it_shows_dashboard'.
F

Time: 603 ms, Memory: 11.00Mb

There was 1 failure:

1) RoutingTest::test_it_shows_dashboard
Failed asserting that 404 matches expected 200.

/home/vagrant/Code/Interviews/Site/tests/RoutingTest.php:10

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
[19:38:44] { [Error: Command failed: ] killed: false, code: 1, signal: null }
[19:38:44] gulp-notify: [Red!]  
[19:38:44] Finished 'phpunit' after 1.2 s

So, my questions is why am I not seeing a message with the NotFoundHttpException within PHPUnit, like I see Jeffrey gets? Important fact: my OS is Linux (Ubuntu 14).

0 likes
1 reply
hamzapurra's avatar

Hi,

To fix the above issue, I kind of hacked my way by adding

Log::useFiles('php://stderr');

to the top of the routes.php file; this makes Laravel log the exceptions onto the console instead of storage/laravel.log.

Hope that helps.

Please or to participate in this conversation.