I am running phpUnit tests using Laravel Framework Version 9.52.20. The tests work just fine in my local environment and in my CI/CD pipeline. But when I try to run the same tests in my dev environment it throws this error repeatedly:
Call to undefined function Illuminate\Foundation\laravel_cloud()
at vendor/laravel/framework/src/Illuminate/Foundation/Application.php:237
233▕ * @return void
234▕ */
235▕ protected function registerLaravelCloudServices()
236▕ {
➜ 237▕ if (! laravel_cloud()) {
238▕ return;
239▕ }
240▕
241▕ $this['events']->listen(
I can see this function being defined in vendor/laravel/framework/src/Illuminate/Support/helpers.php
if (! function_exists('laravel_cloud')) {
/**
* Determine if the application is running on Laravel Cloud.
*
* @return bool
*/
function laravel_cloud()
{
return ($_ENV['LARAVEL_CLOUD'] ?? false) === '1' ||
($_SERVER['LARAVEL_CLOUD'] ?? false) === '1';
}
}
The oddity is that my phpUnit tests run just fine in my local environment and in my CI/CD pipeline. It is only in my separate dev environment that I experience this issue.
Additional Information
My Tests namespace uses a trait named CreatesApplication() to set up my test environment. Should I manually reference the Illuminate/Support/helpers class in my TestCase class in order to make this function available to the phpUnit tests? I had assumed that the Laravel framework would have automatically included such a dependency. But that doesn't explain why this particular environment has the problem while other identical environments do not.
Let me know if you have run into this situation also, and how you were able to fix this reference error.
Addendum
I went into artisan tinker and queried the runtime environment to see if the laravel_cloud function was defined. It said it was:
~$ php artisan tinker
Psy Shell v0.12.7 (PHP 8.3.19 — cli) by Justin Hileman
> function_exists('my_fake_function');
= false
> function_exists('laravel_cloud');
= true
It looks like the laravel_cloud function is defined and available to the Laravel engine in general. However, something about my environment is causing the phpUnit runtime to not find that function within the list of global environment functions.