Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add App::isDebug() method to detect debug mode #39755

Merged
merged 4 commits into from Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Illuminate/Foundation/Application.php
Expand Up @@ -631,6 +631,16 @@ public function runningUnitTests()
return $this->bound('env') && $this['env'] === 'testing';
}

/**
* Determine if the application is running with debug mode enabled.
*
* @return bool
*/
public function hasDebugModeEnabled()
{
return (bool) $this['config']->get('app.debug');
}

/**
* Register all of the configured providers.
*
Expand Down
14 changes: 14 additions & 0 deletions tests/Foundation/FoundationApplicationTest.php
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Tests\Foundation;

use Illuminate\Config\Repository;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Bootstrap\RegisterFacades;
Expand Down Expand Up @@ -239,6 +240,19 @@ public function testEnvironmentHelpers()
$this->assertFalse($testing->isProduction());
}

public function testDebugHelper()
{
$debugOff = new Application;
$debugOff['config'] = new Repository(['app' => ['debug' => false]]);

$this->assertFalse($debugOff->hasDebugModeEnabled());

$debugOn = new Application;
$debugOn['config'] = new Repository(['app' => ['debug' => true]]);

$this->assertTrue($debugOn->hasDebugModeEnabled());
}

public function testMethodAfterLoadingEnvironmentAddsClosure()
{
$app = new Application;
Expand Down