From f62a571e00adcb8ac530b7a66d0a867933208e87 Mon Sep 17 00:00:00 2001 From: "Ralph J. Smit" <59207045+ralphjsmit@users.noreply.github.com> Date: Thu, 1 Sep 2022 19:17:41 +0200 Subject: [PATCH 1/2] Make Applicaiton macroable --- src/Illuminate/Foundation/Application.php | 3 +++ tests/Foundation/FoundationApplicationTest.php | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 196c7da68f09..b3f43006f0df 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -21,6 +21,7 @@ use Illuminate\Support\Env; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Str; +use Illuminate\Support\Traits\Macroable; use RuntimeException; use Symfony\Component\HttpFoundation\Request as SymfonyRequest; use Symfony\Component\HttpFoundation\Response as SymfonyResponse; @@ -30,6 +31,8 @@ class Application extends Container implements ApplicationContract, CachesConfiguration, CachesRoutes, HttpKernelInterface { + use Macroable; + /** * The Laravel framework version. * diff --git a/tests/Foundation/FoundationApplicationTest.php b/tests/Foundation/FoundationApplicationTest.php index d96cf62311eb..cdd3b5197d61 100755 --- a/tests/Foundation/FoundationApplicationTest.php +++ b/tests/Foundation/FoundationApplicationTest.php @@ -7,6 +7,7 @@ use Illuminate\Foundation\Application; use Illuminate\Foundation\Bootstrap\RegisterFacades; use Illuminate\Foundation\Events\LocaleUpdated; +use Illuminate\Support\Facades\App; use Illuminate\Support\ServiceProvider; use Mockery as m; use PHPUnit\Framework\TestCase; @@ -499,6 +500,23 @@ public function testEnvPathsAreAbsoluteInWindows() $_SERVER['APP_EVENTS_CACHE'] ); } + + /** @test */ + public function testMacroable(): void + { + $app = new Application; + $app['env'] = 'foo'; + + $app->macro('foo', function() { + return $this->environment('foo'); + }); + + $this->assertTrue($app->foo()); + + $app['env'] = 'bar'; + + $this->assertFalse($app->foo()); + } } class ApplicationBasicServiceProviderStub extends ServiceProvider From 425aaa40c49cea69dba591e5af68b11c39fe1a74 Mon Sep 17 00:00:00 2001 From: "Ralph J. Smit" <59207045+ralphjsmit@users.noreply.github.com> Date: Thu, 1 Sep 2022 19:18:36 +0200 Subject: [PATCH 2/2] Update FoundationApplicationTest.php --- tests/Foundation/FoundationApplicationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Foundation/FoundationApplicationTest.php b/tests/Foundation/FoundationApplicationTest.php index cdd3b5197d61..f22c81c59f37 100755 --- a/tests/Foundation/FoundationApplicationTest.php +++ b/tests/Foundation/FoundationApplicationTest.php @@ -515,7 +515,7 @@ public function testMacroable(): void $app['env'] = 'bar'; - $this->assertFalse($app->foo()); + $this->assertFalse($app->foo()); } }