diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index e19d75520b9c..1a4de5ac328b 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -1350,7 +1350,13 @@ public function getCachedRoutesPath() */ public function eventsAreCached() { - return $this['files']->exists($this->getCachedEventsPath()); + if ($this->bound('events.cached')) { + return (bool) $this->make('events.cached'); + } + + return $this->instance( + 'events.cached', $this['files']->exists($this->getCachedEventsPath()) + ); } /** diff --git a/tests/Foundation/FoundationApplicationTest.php b/tests/Foundation/FoundationApplicationTest.php index c6cc5d54a7a2..c9f8230e3098 100755 --- a/tests/Foundation/FoundationApplicationTest.php +++ b/tests/Foundation/FoundationApplicationTest.php @@ -620,23 +620,36 @@ public function test_routes_are_cached() public function test_routes_are_not_cached_by_instance_falls_back_to_file() { $app = new Application(); - $files = new class - { - public string $pathRequested; - - public function exists(string $path): bool - { - $this->pathRequested = $path; - - return false; - } - }; + $files = new FileExistsFake; $app->instance('files', $files); $this->assertFalse($app->routesAreCached()); $this->assertStringContainsString('routes-v7.php', $files->pathRequested); } + public function test_events_are_cached_uses_container_instance() + { + $app = new Application(); + $app->instance('events.cached', true); + $files = new FileExistsFake; + $app->instance('files', $files); + + $this->assertTrue($app->eventsAreCached()); + $this->assertFalse(isset($files->pathRequested)); + } + + public function test_events_are_cached_checks_filesystem_if_not_set() + { + $app = new Application(); + $files = new FileExistsFake; + $app->instance('files', $files); + + $this->assertFalse($app->eventsAreCached()); + $this->assertStringContainsString('events.php', $files->pathRequested); + $this->assertTrue($app->bound('events.cached')); + $this->assertFalse($app->make('events.cached')); + } + public function testCoreContainerAliasesAreRegisteredByDefault(): void { $app = new Application(); @@ -782,3 +795,15 @@ public function terminate() return self::$counter++; } } + +class FileExistsFake +{ + public string $pathRequested; + + public function exists(string $path): bool + { + $this->pathRequested = $path; + + return false; + } +}