1
0
mirror of https://github.com/danog/amp.git synced 2024-11-26 20:15:00 +01:00

Add test for loop accessor

This commit is contained in:
Niklas Keller 2017-03-15 08:40:58 +01:00
parent 01c58ae90e
commit ea67e113b2
3 changed files with 41 additions and 0 deletions

View File

@ -358,4 +358,6 @@ final class Loop {
// Default factory, don't move this a file loaded by the composer "files" autoload mechanism, otherwise custom
// implementations might have issues setting a default loop, because it's overridden by us then.
// @codeCoverageIgnoreStart
Loop::set((new DriverFactory)->create());
// @codeCoverageIgnoreEnd

View File

@ -2,6 +2,7 @@
namespace Amp\Test\Loop;
use Amp\Loop;
use Amp\Loop\Driver;
use PHPUnit\Framework\TestCase;
@ -27,6 +28,15 @@ class DriverStateTest extends TestCase {
$this->assertSame($value, $this->loop->getState("foobar"));
}
/**
* @test
* @dataProvider provideValues
*/
public function getsPreviouslySetValueViaAccessor($value) {
Loop::setState("foobar", $value);
$this->assertSame($value, Loop::getState("foobar"));
}
public function provideValues() {
return [
["string"],

View File

@ -17,4 +17,33 @@ class LoopTest extends TestCase {
Loop::repeat(-1, function () {});
}
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());
}
}