1
0
mirror of https://github.com/danog/amp.git synced 2024-11-27 04:24:42 +01:00

Add tests for Promisor::update()

This commit is contained in:
Daniel Lowrey 2015-02-05 23:44:11 -05:00
parent 99e38762a7
commit b1a5d113a8
2 changed files with 45 additions and 0 deletions

View File

@ -88,4 +88,27 @@ class FutureTest extends \PHPUnit_Framework_TestCase {
yield $promisor->promise();
});
}
public function testUpdate() {
$updatable = 0;
(new NativeReactor)->run(function() use (&$updatable) {
$i = 0;
$promisor = new Future;
$updater = function($reactor, $watcherId) use ($promisor, &$i) {
$promisor->update(++$i);
if ($i === 3) {
$reactor->cancel($watcherId);
// reactor run loop should now be able to exit
}
};
$promise = $promisor->promise();
$promise->watch(function($updateData) use (&$updatable) {
$updatable += $updateData;
});
yield 'repeat' => [$updater, $msDelay = 10];
});
$this->assertSame(6, $updatable);
}
}

View File

@ -72,4 +72,26 @@ class PrivateFutureTest extends \PHPUnit_Framework_TestCase {
yield $promisor->promise();
});
}
public function testUpdate() {
$updatable = 0;
(new NativeReactor)->run(function() use (&$updatable) {
$i = 0;
$promisor = new PrivateFuture;
$updater = function($reactor, $watcherId) use ($promisor, &$i) {
$promisor->update(++$i);
if ($i === 3) {
$reactor->cancel($watcherId);
// reactor run loop should now be able to exit
}
};
$promise = $promisor->promise();
$promise->watch(function($updateData) use (&$updatable) {
$updatable += $updateData;
});
yield 'repeat' => [$updater, $msDelay = 10];
});
$this->assertSame(6, $updatable);
}
}