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

Make error handling a bit more friendly #35381

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Illuminate/Foundation/Bootstrap/HandleExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public function bootstrap(Application $app)

$this->app = $app;

error_reporting(-1);
if (! $app->environment('production')) {
error_reporting(-1);
}
Comment on lines +45 to +47
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly thought about removing this line but it exists since forever - for a reason which I couldn't find in the history.


set_error_handler([$this, 'handleError']);

Expand Down
52 changes: 52 additions & 0 deletions tests/Foundation/Bootstrap/HandleExceptionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Illuminate\Tests\Foundation\Bootstrap;

use const E_ALL;
use function error_reporting;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Bootstrap\HandleExceptions;
use Mockery as m;
use PHPUnit\Framework\TestCase;

/**
* This test is set to run in isolation to avoid messing up with the test environment and affecting other tests.
*
* @runInSeparateProcess
*/
class HandleExceptionsTest extends TestCase
{
/** @var Application */
private $app;

/** @before */
public function configureApp(): void
{
$this->app = m::mock(Application::class);
$this->app->allows()->environment('testing')->andReturns(false);
}

/** @test */
public function errorReportingShouldNotBeAffectedOnProduction(): void
{
error_reporting(E_ALL);

$this->app->allows()->environment('production')->andReturns(true);

(new HandleExceptions())->bootstrap($this->app);

self::assertSame(E_ALL, error_reporting());
}

/** @test */
public function errorReportingShouldBeOverriddenForOtherEnvironmentSoPeopleCanFindBugsEarlier(): void
{
error_reporting(E_ALL);

$this->app->allows()->environment('production')->andReturns(false);

(new HandleExceptions())->bootstrap($this->app);

self::assertSame(-1, error_reporting());
}
}