diff --git a/test/FutureTest.php b/test/FutureTest.php index 4540b42..242efcd 100644 --- a/test/FutureTest.php +++ b/test/FutureTest.php @@ -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); + } } diff --git a/test/PrivateFutureTest.php b/test/PrivateFutureTest.php index 5d866e1..d73c541 100644 --- a/test/PrivateFutureTest.php +++ b/test/PrivateFutureTest.php @@ -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); + } }