Skip to content

Commit

Permalink
[8.x] Add App::isDebug() method to detect debug mode (#39755)
Browse files Browse the repository at this point in the history
* add App::isDebug() method to detect debug mode

Like App::isLocal(), isProduction(), runningInConsole(), isLocale(), etc. it makes sense to have a method on the Container to detect debug mode.

I struggled with the method name, but isDebug() sort of matches most of the methods with similar functionality. I also like:

* debugMode()
* debugEnabled()
* debugModeEnabled()
* inDebugMode()

* add isDebug() unit test

* Update Application.php

* Update FoundationApplicationTest.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
joelmellon and taylorotwell committed Nov 25, 2021
1 parent 8aa1387 commit c978893
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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

0 comments on commit c978893

Please sign in to comment.