2017-03-12 21:02:26 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Amp\Test;
|
|
|
|
|
|
|
|
use Amp\Loop;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class LoopTest extends TestCase {
|
|
|
|
public function testDelayWithNegativeDelay() {
|
2017-03-14 18:44:44 +01:00
|
|
|
$this->expectException(\Error::class);
|
2017-03-12 21:02:26 +01:00
|
|
|
|
|
|
|
Loop::delay(-1, function () {});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRepeatWithNegativeInterval() {
|
2017-03-14 18:44:44 +01:00
|
|
|
$this->expectException(\Error::class);
|
2017-03-12 21:02:26 +01:00
|
|
|
|
|
|
|
Loop::repeat(-1, function () {});
|
|
|
|
}
|
2017-03-15 08:40:58 +01:00
|
|
|
|
|
|
|
public function testOnReadable() {
|
|
|
|
Loop::run(function () {
|
|
|
|
$ends = stream_socket_pair(\stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
|
|
|
|
fwrite($ends[0], "trigger readability watcher");
|
|
|
|
|
|
|
|
Loop::onReadable($ends[1], function () {
|
|
|
|
$this->assertTrue(true);
|
|
|
|
Loop::stop();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOnWritable() {
|
|
|
|
Loop::run(function () {
|
|
|
|
Loop::onWritable(STDOUT, function () {
|
|
|
|
$this->assertTrue(true);
|
|
|
|
Loop::stop();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGet() {
|
|
|
|
$this->assertInstanceOf(Loop\Driver::class, Loop::get());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetInto() {
|
|
|
|
$this->assertSame(Loop::get()->getInfo(), Loop::getInfo());
|
|
|
|
}
|
2017-04-24 15:39:08 +02:00
|
|
|
}
|