From 33a59e61d2e5d53f45ba37d2f474c29e701df5f5 Mon Sep 17 00:00:00 2001 From: Luke Kuzmish Date: Sat, 8 Nov 2025 07:16:57 -0500 Subject: [PATCH 1/4] memoize result of eventsAreCached --- src/Illuminate/Foundation/Application.php | 6 ++- .../Foundation/FoundationApplicationTest.php | 48 ++++++++++++++----- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index ab90e663f6a1..9062393b54c7 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -1350,7 +1350,11 @@ 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 e41fc9320a35..799db5967847 100755 --- a/tests/Foundation/FoundationApplicationTest.php +++ b/tests/Foundation/FoundationApplicationTest.php @@ -9,6 +9,7 @@ use Illuminate\Foundation\Events\LocaleUpdated; use Illuminate\Support\ServiceProvider; use Mockery as m; +use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\TestCase; use stdClass; use Symfony\Component\HttpKernel\Exception\HttpException; @@ -620,22 +621,35 @@ 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')); + } } class ApplicationBasicServiceProviderStub extends ServiceProvider @@ -770,3 +784,15 @@ public function terminate() return self::$counter++; } } + +class FileExistsFake +{ + public string $pathRequested; + + public function exists(string $path): bool + { + $this->pathRequested = $path; + + return false; + } +} From 7267ece61db231a83c53a4f660821bc6552791e4 Mon Sep 17 00:00:00 2001 From: Luke Kuzmish <42181698+cosmastech@users.noreply.github.com> Date: Sat, 8 Nov 2025 14:56:13 -0500 Subject: [PATCH 2/4] Update FoundationApplicationTest.php --- tests/Foundation/FoundationApplicationTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Foundation/FoundationApplicationTest.php b/tests/Foundation/FoundationApplicationTest.php index 61c73a5957de..028048d70794 100755 --- a/tests/Foundation/FoundationApplicationTest.php +++ b/tests/Foundation/FoundationApplicationTest.php @@ -649,6 +649,7 @@ public function test_events_are_cached_checks_filesystem_if_not_set() $this->assertStringContainsString('events.php', $files->pathRequested); $this->assertTrue($app->bound('events.cached')); $this->assertFalse($app->make('events.cached')); + } public function testCoreContainerAliasesAreRegisteredByDefault(): void { From d01313c9975cf5bd735d8d12de669aebbb9f9974 Mon Sep 17 00:00:00 2001 From: Luke Kuzmish <42181698+cosmastech@users.noreply.github.com> Date: Sat, 8 Nov 2025 15:01:39 -0500 Subject: [PATCH 3/4] Update FoundationApplicationTest.php --- tests/Foundation/FoundationApplicationTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Foundation/FoundationApplicationTest.php b/tests/Foundation/FoundationApplicationTest.php index 028048d70794..c9f8230e3098 100755 --- a/tests/Foundation/FoundationApplicationTest.php +++ b/tests/Foundation/FoundationApplicationTest.php @@ -9,7 +9,6 @@ use Illuminate\Foundation\Events\LocaleUpdated; use Illuminate\Support\ServiceProvider; use Mockery as m; -use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\TestCase; use stdClass; use Symfony\Component\HttpKernel\Exception\HttpException; From cb737a1378b7bc2b379933287dd80c1d17f9dcf9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 9 Nov 2025 08:35:11 -0600 Subject: [PATCH 4/4] Update Application.php --- src/Illuminate/Foundation/Application.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 2e2324d506c8..1a4de5ac328b 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -1354,7 +1354,9 @@ public function eventsAreCached() return (bool) $this->make('events.cached'); } - return $this->instance('events.cached', $this['files']->exists($this->getCachedEventsPath())); + return $this->instance( + 'events.cached', $this['files']->exists($this->getCachedEventsPath()) + ); } /**