1
0
mirror of https://github.com/danog/amp.git synced 2024-11-27 12:35:02 +01:00
amp/test/PauseTest.php

29 lines
689 B
PHP
Raw Normal View History

2016-08-18 05:25:54 +02:00
<?php declare(strict_types = 1);
2015-07-21 04:24:51 +02:00
namespace Amp\Test;
2016-07-19 07:05:40 +02:00
use Amp;
2015-07-21 04:24:51 +02:00
use Amp\Pause;
2016-07-19 07:05:40 +02:00
use Interop\Async\Loop;
2015-07-21 04:24:51 +02:00
class PauseTest extends \PHPUnit_Framework_TestCase {
2016-07-19 07:05:40 +02:00
public function testPause() {
$time = 100;
$value = "test";
$start = microtime(true);
Loop::execute(function () use (&$result, $time, $value) {
$awaitable = new Pause($time, $value);
$callback = function ($exception, $value) use (&$result) {
$result = $value;
};
$awaitable->when($callback);
2015-07-21 04:28:51 +02:00
});
2016-07-19 07:05:40 +02:00
$this->assertLessThanOrEqual($time, microtime(true) - $start);
$this->assertSame($value, $result);
2015-07-21 04:28:51 +02:00
}
2015-07-21 04:24:51 +02:00
}