-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from henriquemoody/handlers
Centralize handlers for signals and PHP errors
- Loading branch information
Showing
16 changed files
with
163 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...rocess/Control/Signal/AbstractHandler.php → src/Arara/Process/Handler/SignalAbstract.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Arara\Process\Handler; | ||
|
||
use Arara\Process\Action\Action; | ||
use Arara\Process\Context; | ||
use Arara\Process\Control; | ||
|
||
class SignalAlarm extends SignalAbstract | ||
{ | ||
protected $action; | ||
protected $context; | ||
|
||
public function __construct(Control $control, Action $action, array $context) | ||
{ | ||
$this->action = $action; | ||
$this->context = $context; | ||
|
||
parent::__construct($control); | ||
} | ||
|
||
public function __invoke($signal) | ||
{ | ||
$this->context['finishTime'] = time(); | ||
$this->action->trigger(Action::EVENT_TIMEOUT, $this->control, $this->context); | ||
$this->control->quit(3); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...a/Process/Control/Signal/ChildHandler.php → src/Arara/Process/Handler/SignalChild.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ocess/Control/Signal/InterruptHandler.php → ...Arara/Process/Handler/SignalInterrupt.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ra/Process/Control/Signal/QuitHandler.php → src/Arara/Process/Handler/SignalQuit.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ocess/Control/Signal/TerminateHandler.php → ...Arara/Process/Handler/SignalTerminate.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__); | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
...ss/Control/Signal/AbstractHandlerTest.php → ...ra/Process/Handler/SignalAbstractTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Arara\Process\Handler; | ||
|
||
function time() | ||
{ | ||
if ( isset($GLOBALS['time'])) { | ||
return $GLOBALS['time']; | ||
} | ||
|
||
return \time(); | ||
} | ||
|
||
use Arara\Process\Action\Action; | ||
|
||
/** | ||
* @covers Arara\Process\Handler\SignalAlarm | ||
*/ | ||
class SignalAlarmTest extends \TestCase | ||
{ | ||
|
||
const TIMESTAMP = 1230192830; | ||
|
||
protected function init() | ||
{ | ||
$GLOBALS['time'] = self::TIMESTAMP; | ||
} | ||
|
||
protected function finish() | ||
{ | ||
unset($GLOBALS['time']); | ||
} | ||
|
||
public function testShouldHandleAlarm() | ||
{ | ||
$control = $this | ||
->getMockBuilder('Arara\Process\Control') | ||
->setMethods(array('quit')) | ||
->getMock(); | ||
|
||
$control | ||
->expects($this->once()) | ||
->method('quit') | ||
->with(3); | ||
|
||
$action = $this | ||
->getMockBuilder('Arara\Process\Action\Action') | ||
->setMethods(array('execute', 'trigger')) | ||
->getMock(); | ||
|
||
$action | ||
->expects($this->once()) | ||
->method('trigger') | ||
->with(Action::EVENT_TIMEOUT, $control, array('finishTime' => self::TIMESTAMP)); | ||
|
||
$handler = new SignalAlarm($control, $action, array()); | ||
$handler(SIGALRM); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters