示例#1
0
 function run_hook($i)
 {
     $retval = ClassTrigger::call_trigger('trigger', $i);
     $sum = $i;
     foreach ($retval as $r) {
         $sum += $r;
     }
     return $sum;
 }
function not_abort($t)
{
    ClassTrigger::add_trigger('trigger', '_exec');
    ClassTrigger::add_trigger('trigger', '_abort');
    ClassTrigger::add_trigger('trigger', '_not_exec');
    $triggers = ClassTrigger::get_trigger('trigger');
    $t->is(count($triggers), 3);
    $retval = ClassTrigger::call_trigger('trigger', 2);
    $t->is(count($retval), 3);
    $t->is($retval[0], 4);
    $t->is($retval[1], false);
    $t->is($retval[2], 2);
}
function add_multi_trigger($t)
{
    ClassTrigger::add_trigger('multi_trigger', '_multiply');
    ClassTrigger::add_trigger('multi_trigger', '_dimidiate');
    $triggers = ClassTrigger::get_trigger('multi_trigger');
    $t->is(count($triggers), 2);
    $t->ok(is_callable($triggers[0]['callback']));
    $t->ok(is_callable($triggers[1]['callback']));
    $retval = ClassTrigger::call_trigger('multi_trigger', 2);
    $t->is(count($retval), 2);
    $t->is($retval[0], 4);
    $t->is($retval[1], 1);
    ClassTrigger::clear_trigger('multi_trigger');
    $triggers = ClassTrigger::get_trigger('multi_trigger');
    $t->is(count($triggers), 0);
}
示例#4
0
function add_closure($t)
{
    if (version_compare(PHP_VERSION, '5.3.0') < 0) {
        $t->skip('test requires PHP 5.0.0 or later');
        return;
    }
    ClassTrigger::add_trigger('dimidiate', function ($i) {
        return $i / 2;
    });
    $triggers = ClassTrigger::get_trigger('dimidiate');
    $t->is(count($triggers), 1);
    $t->ok(is_callable($triggers[0]['callback']));
    $retval = ClassTrigger::call_trigger('dimidiate', 2);
    $t->is(count($retval), 1);
    $t->is($retval[0], 1);
    $retval = ClassTrigger::call_trigger('dimidiate', 3);
    $t->is(count($retval), 1);
    $t->is($retval[0], 1.5);
    ClassTrigger::clear_trigger('dimidiate');
    $triggers = ClassTrigger::get_trigger('dimidiate');
    $t->is(count($triggers), 0);
}