Skip to content

Commit

Permalink
[9.x] Make Application macroable (#43966)
Browse files Browse the repository at this point in the history
* Make Applicaiton macroable

* Update FoundationApplicationTest.php
  • Loading branch information
ralphjsmit authored Sep 1, 2022
1 parent 3b6c7ad commit 1c1766f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +31,8 @@

class Application extends Container implements ApplicationContract, CachesConfiguration, CachesRoutes, HttpKernelInterface
{
use Macroable;

/**
* The Laravel framework version.
*
Expand Down
18 changes: 18 additions & 0 deletions tests/Foundation/FoundationApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1c1766f

Please sign in to comment.