mirror of
https://github.com/danog/amp.git
synced 2024-11-27 04:24:42 +01:00
fe88413a17
This commit removes Humbug, as it's no longer maintained and not compatible with PHPUnit 6.
74 lines
1.9 KiB
PHP
74 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Amp\Test;
|
|
|
|
use Amp\Pause;
|
|
use Amp\Loop;
|
|
|
|
class PauseTest extends \PHPUnit\Framework\TestCase {
|
|
public function testPause() {
|
|
$time = 100;
|
|
$value = "test";
|
|
$start = microtime(true);
|
|
|
|
Loop::run(function () use (&$result, $time, $value) {
|
|
$promise = new Pause($time, $value);
|
|
|
|
$callback = function ($exception, $value) use (&$result) {
|
|
$result = $value;
|
|
};
|
|
|
|
$promise->when($callback);
|
|
});
|
|
|
|
$this->assertGreaterThanOrEqual($time, (microtime(true) - $start) * 1000);
|
|
$this->assertSame($value, $result);
|
|
}
|
|
|
|
public function testUnreference() {
|
|
$time = 100;
|
|
$value = "test";
|
|
$start = microtime(true);
|
|
|
|
$invoked = false;
|
|
Loop::run(function () use (&$invoked, $time, $value) {
|
|
$promise = new Pause($time, $value);
|
|
$promise->unreference();
|
|
|
|
$callback = function ($exception, $value) use (&$invoked) {
|
|
$invoked = true;
|
|
};
|
|
|
|
$promise->when($callback);
|
|
});
|
|
|
|
$this->assertLessThanOrEqual($time, (microtime(true) - $start) * 1000);
|
|
$this->assertFalse($invoked);
|
|
}
|
|
|
|
/**
|
|
* @depends testUnreference
|
|
*/
|
|
public function testReference() {
|
|
$time = 100;
|
|
$value = "test";
|
|
$start = microtime(true);
|
|
|
|
$invoked = false;
|
|
Loop::run(function () use (&$invoked, $time, $value) {
|
|
$promise = new Pause($time, $value);
|
|
$promise->unreference();
|
|
$promise->reference();
|
|
|
|
$callback = function ($exception, $value) use (&$invoked) {
|
|
$invoked = true;
|
|
};
|
|
|
|
$promise->when($callback);
|
|
});
|
|
|
|
$this->assertGreaterThanOrEqual($time, (microtime(true) - $start) * 1000);
|
|
$this->assertTrue($invoked);
|
|
}
|
|
}
|