Skip to content

Commit 59a123a

Browse files
Merge pull request #773 from DvdGiessen/unregister_shutdown_function
Disable shutdown function when not registered
2 parents 51afe14 + db0f04f commit 59a123a

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/Whoops/Run.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@ public function handleShutdown()
507507
// to the exception handler. Pass that information along.
508508
$this->canThrowExceptions = false;
509509

510+
// If we are not currently registered, we should not do anything
511+
if (!$this->isRegistered) {
512+
return;
513+
}
514+
510515
$error = $this->system->getLastError();
511516
if ($error && Misc::isLevelFatal($error['type'])) {
512517
// If there was a fatal error,

tests/Whoops/RunTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
use Mockery as m;
1313
use RuntimeException;
1414
use Whoops\Handler\Handler;
15+
use Whoops\Handler\HandlerInterface;
16+
use Whoops\Handler\PrettyPageHandler;
1517
use Whoops\Exception\Frame;
18+
use Whoops\Util\SystemFacade;
1619

1720
class RunTest extends TestCase
1821
{
@@ -571,4 +574,36 @@ public function testClearFrameFilters()
571574
$this->assertEmpty($run->getFrameFilters());
572575
$this->assertInstanceOf("Whoops\\RunInterface", $run);
573576
}
577+
578+
public function testShutdownHandlerDoesNotRunIfUnregistered()
579+
{
580+
$system = m::mock('Whoops\Util\SystemFacade');
581+
582+
$run = new Run($system);
583+
$run->writeToOutput(false);
584+
$run->allowQuit(false);
585+
586+
$fatalError = [
587+
'type' => E_ERROR,
588+
'message' => 'Simulated fatal error for shutdown',
589+
'file' => 'somefile.php',
590+
'line' => 10,
591+
];
592+
$system->shouldReceive('getLastError')->andReturn($fatalError)->byDefault();
593+
594+
$mockHandler = m::mock('Whoops\Handler\HandlerInterface');
595+
$mockHandler->shouldNotReceive('handle');
596+
$mockHandler->shouldNotReceive('setRun');
597+
$mockHandler->shouldNotReceive('setInspector');
598+
$mockHandler->shouldNotReceive('setException');
599+
$run->pushHandler($mockHandler);
600+
601+
$run->unregister();
602+
603+
ob_start();
604+
$run->handleShutdown();
605+
$output = ob_get_clean();
606+
607+
$this->assertEquals('', $output, "Output buffer should be empty.");
608+
}
574609
}

0 commit comments

Comments
 (0)