Skip to content

Commit 1c1766f

Browse files
authored
[9.x] Make Application macroable (#43966)
* Make Applicaiton macroable * Update FoundationApplicationTest.php
1 parent 3b6c7ad commit 1c1766f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Illuminate/Foundation/Application.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Illuminate\Support\Env;
2222
use Illuminate\Support\ServiceProvider;
2323
use Illuminate\Support\Str;
24+
use Illuminate\Support\Traits\Macroable;
2425
use RuntimeException;
2526
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
2627
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
@@ -30,6 +31,8 @@
3031

3132
class Application extends Container implements ApplicationContract, CachesConfiguration, CachesRoutes, HttpKernelInterface
3233
{
34+
use Macroable;
35+
3336
/**
3437
* The Laravel framework version.
3538
*

tests/Foundation/FoundationApplicationTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Foundation\Application;
88
use Illuminate\Foundation\Bootstrap\RegisterFacades;
99
use Illuminate\Foundation\Events\LocaleUpdated;
10+
use Illuminate\Support\Facades\App;
1011
use Illuminate\Support\ServiceProvider;
1112
use Mockery as m;
1213
use PHPUnit\Framework\TestCase;
@@ -499,6 +500,23 @@ public function testEnvPathsAreAbsoluteInWindows()
499500
$_SERVER['APP_EVENTS_CACHE']
500501
);
501502
}
503+
504+
/** @test */
505+
public function testMacroable(): void
506+
{
507+
$app = new Application;
508+
$app['env'] = 'foo';
509+
510+
$app->macro('foo', function() {
511+
return $this->environment('foo');
512+
});
513+
514+
$this->assertTrue($app->foo());
515+
516+
$app['env'] = 'bar';
517+
518+
$this->assertFalse($app->foo());
519+
}
502520
}
503521

504522
class ApplicationBasicServiceProviderStub extends ServiceProvider

0 commit comments

Comments
 (0)