Skip to content

Commit

Permalink
Create PHP error handler class
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquemoody committed Nov 5, 2014
1 parent 18b8923 commit 956a0c2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/Arara/Process/Child.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,9 @@ protected function setHandlerAlarm(array $context)
*
* @return void
*/
protected function setPhpErrorHandler()
protected function setHandlerErrorException()
{
set_error_handler(
function ($severity, $message, $filename, $line) {
throw new ErrorException($message, 0, $severity, $filename, $line);
},
E_ALL & ~E_NOTICE
);
set_error_handler(new Handler\ErrorException(), E_ALL & ~E_NOTICE);
}

/**
Expand Down Expand Up @@ -194,7 +189,7 @@ public function start()
);

$this->setHandlerAlarm($context);
$this->setPhpErrorHandler();
$this->setHandlerErrorException();
$this->run($context);
restore_error_handler();
}
Expand Down
11 changes: 11 additions & 0 deletions src/Arara/Process/Handler/ErrorException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Arara\Process\Handler;

class ErrorException
{
public function __invoke($severity, $message, $filename, $line)
{
throw new \ErrorException($message, 0, $severity, $filename, $line);
}
}
21 changes: 21 additions & 0 deletions tests/Arara/Process/Handler/ErrorExceptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Arara\Process\Handler;

use Arara\Process\Control;

/**
* @covers Arara\Process\Handler\ErrorException
*/
class ErrorExceptionTest extends \TestCase
{
/**
* @expectedException ErrorException
* @expectedExceptionMessage Some message
*/
public function testShouldThrowsErrorExceptionWhenCalled()
{
$handler = new ErrorException();
$handler(E_ERROR, 'Some message', __FILE__, __LINE__);
}
}

0 comments on commit 956a0c2

Please sign in to comment.