2016-12-29 14:09:49 -06:00
|
|
|
<?php
|
2016-08-16 16:39:25 -05:00
|
|
|
|
2015-07-20 22:24:51 -04:00
|
|
|
namespace Amp\Test;
|
|
|
|
|
2016-07-19 00:05:40 -05:00
|
|
|
use Amp;
|
2015-07-20 22:24:51 -04:00
|
|
|
use Amp\Pause;
|
2017-01-07 13:47:45 +01:00
|
|
|
use AsyncInterop\Loop;
|
2015-07-20 22:24:51 -04:00
|
|
|
|
|
|
|
class PauseTest extends \PHPUnit_Framework_TestCase {
|
2016-07-19 00:05:40 -05:00
|
|
|
public function testPause() {
|
|
|
|
$time = 100;
|
|
|
|
$value = "test";
|
|
|
|
$start = microtime(true);
|
|
|
|
|
|
|
|
Loop::execute(function () use (&$result, $time, $value) {
|
2016-11-14 13:59:21 -06:00
|
|
|
$promise = new Pause($time, $value);
|
2016-07-19 00:05:40 -05:00
|
|
|
|
|
|
|
$callback = function ($exception, $value) use (&$result) {
|
|
|
|
$result = $value;
|
|
|
|
};
|
|
|
|
|
2016-11-14 13:59:21 -06:00
|
|
|
$promise->when($callback);
|
2015-07-20 22:28:51 -04:00
|
|
|
});
|
2016-07-19 00:05:40 -05:00
|
|
|
|
|
|
|
$this->assertLessThanOrEqual($time, microtime(true) - $start);
|
|
|
|
$this->assertSame($value, $result);
|
2015-07-20 22:28:51 -04:00
|
|
|
}
|
2015-07-20 22:24:51 -04:00
|
|
|
}
|