for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Slince\Process\Tests;
use PHPUnit\Framework\TestCase;
use Slince\Process\SignalHandler;
class SignalHandlerTest extends TestCase
{
public static function setUpBeforeClass()
if (!function_exists('pcntl_async_signals')) {
declare(ticks = 1);
}
public function testRegister()
$signalHandler = SignalHandler::getInstance();
$username = '';
$signalHandler->register(SIGUSR1, function() use(&$username){
$username = 'foo';
});
posix_kill(getmypid(), SIGUSR1);
usleep(100);
$this->assertEquals('foo', $username);
public function testRegisterMultiSignal()
$counter = 0;
$signalHandler->register([SIGUSR1, SIGUSR2], function() use(&$counter){
$counter ++;
posix_kill(getmypid(), SIGUSR2);
$this->assertEquals(2, $counter);
public function testGetHandler()
$handler = function(){
$this->username = 'foo';
username
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
};
$signalHandler->register(SIGUSR1, $handler);
$handler1 = $signalHandler->getHandler(SIGUSR1);
$this->assertTrue($handler === $handler1);
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: