1
0
mirror of https://github.com/danog/amp.git synced 2024-12-03 09:57:51 +01:00
amp/test/LoopTest.php

59 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace Amp\Test;
use Amp\Loop;
use PHPUnit\Framework\TestCase;
2018-06-18 20:00:01 +02:00
class LoopTest extends TestCase
{
public function testDelayWithNegativeDelay()
{
$this->expectException(\Error::class);
2018-06-18 20:00:01 +02:00
Loop::delay(-1, function () {
});
}
2018-06-18 20:00:01 +02:00
public function testRepeatWithNegativeInterval()
{
$this->expectException(\Error::class);
2018-06-18 20:00:01 +02:00
Loop::repeat(-1, function () {
});
}
2017-03-15 08:40:58 +01:00
2018-06-18 20:00:01 +02:00
public function testOnReadable()
{
2017-03-15 08:40:58 +01:00
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");
2017-03-15 08:40:58 +01:00
Loop::onReadable($ends[1], function () {
$this->assertTrue(true);
Loop::stop();
});
});
}
2018-06-18 20:00:01 +02:00
public function testOnWritable()
{
2017-03-15 08:40:58 +01:00
Loop::run(function () {
Loop::onWritable(STDOUT, function () {
$this->assertTrue(true);
Loop::stop();
});
});
}
2018-06-18 20:00:01 +02:00
public function testGet()
{
2017-03-15 08:40:58 +01:00
$this->assertInstanceOf(Loop\Driver::class, Loop::get());
}
2018-06-18 20:00:01 +02:00
public function testGetInto()
{
2017-03-15 08:40:58 +01:00
$this->assertSame(Loop::get()->getInfo(), Loop::getInfo());
}
}