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..f22c81c59f37 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