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

bfuze's avatar
Level 1

Cannot redeclare l() when running multiple tests

I'm working on an Laravel 8 application, recently upgraded from L5. I created a simple Http test case with one test which ran without issue. When I added a second test to the same testcase I received the following error:

PHP Fatal error: Cannot redeclare l() (previously declared in /var/www/html/web/bootstrap/app.php:4) in /var/www/html/web/bootstrap/app.php on line 4 PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /var/www/html/web/vendor/laravel/framework/src/Illuminate/Container/Container.php:1089 Stack trace: #0 /var/www/html/web/vendor/laravel/framework/src/Illuminate/Container/Container.php(886): Illuminate\Container\Container->notInstantiable('Illuminate\Cont...') #1 /var/www/html/web/vendor/laravel/framework/src/Illuminate/Container/Container.php(758): Illuminate\Container\Container->build('Illuminate\Cont...') #2 /var/www/html/web/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(851): Illuminate\Container\Container->resolve('Illuminate\Cont...', Array, true) #3 /var/www/html/web/vendor/laravel/framework/src/Illuminate/Container/Container.php(694): Illuminate\Foundation\Application->resolve('Illuminate\Cont...', Array) #4 /var/www/html/web/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(836): Illuminate\Container\Container->make( in /var/www/html/web/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 1089

  • I'm running the test using php artisan from within a DDev container.
  • The options I'm using are --testsuite and --stop-on-failure.
  • I am using RefreshDatabase trait, but the error occcurs with or without this trait.
  • I get the same error when running the test using vendor/bin/phpunit.
  • To rule out something within the test code, I replaced test code with $this->assertTrue(TRUE).
  • I verified it still happens with/without xdebug enabled.
  • I ran similar tests on a new Laravel 8 installation and did not receive any errors, so it seems to be unique to this project.
  • This project has a bunch of old migrations, so my theory is that one of them is doing something odd, but the trace does not provide any way of tracking this down.
  • I tried overriding the createApplication method, where the application bootstrapping occurs, but this produced other container initialization errors.
  • I tried the --parallel option, but it says this option is invalid, so perhaps its only available for L9.

Look for suggestions on how to debug this further or work-arounds.

Thanks.

0 likes
6 replies
tykus's avatar

@bfuze

When I added a second test to the same testcase I received the following error:

Maybe you can share the test examples?

bfuze's avatar
Level 1

@sinnbeck That was it! I thought those debugging functions were part of the core application code (like dd()), but someone must've added those and now I recall the correct convention was to use function_exists() checks. Awesome! Thanks so much!!

Please or to participate in this conversation.