mirror of
https://github.com/danog/amp.git
synced 2024-11-27 04:24:42 +01:00
66 lines
1.3 KiB
PHP
66 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Amp\Test;
|
|
|
|
use Amp;
|
|
use Amp\Failure;
|
|
use Amp\Future;
|
|
use Amp\Pause;
|
|
use Amp\Success;
|
|
use Interop\Async\Loop;
|
|
|
|
class WaitTest extends \PHPUnit_Framework_TestCase {
|
|
public function testWaitOnSuccessfulAwaitable()
|
|
{
|
|
$value = 1;
|
|
|
|
$awaitable = new Success($value);
|
|
|
|
$result = Amp\wait($awaitable);
|
|
|
|
$this->assertSame($value, $result);
|
|
}
|
|
|
|
public function testWaitOnFailedAwaitable()
|
|
{
|
|
$exception = new \Exception();
|
|
|
|
$awaitable = new Failure($exception);
|
|
|
|
try {
|
|
$result = Amp\wait($awaitable);
|
|
} catch (\Exception $e) {
|
|
$this->assertSame($exception, $e);
|
|
return;
|
|
}
|
|
|
|
$this->fail('Rejection exception should be thrown from wait().');
|
|
}
|
|
|
|
/**
|
|
* @depends testWaitOnSuccessfulAwaitable
|
|
*/
|
|
public function testWaitOnPendingAwaitable()
|
|
{
|
|
Loop::execute(function () {
|
|
$value = 1;
|
|
|
|
$awaitable = new Pause(100, $value);
|
|
|
|
$result = Amp\wait($awaitable);
|
|
|
|
$this->assertSame($value, $result);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @expectedException \Error
|
|
*/
|
|
public function testAwaitableWithNoResolutionPathThrowsException()
|
|
{
|
|
$awaitable = new Future;
|
|
|
|
$result = Amp\wait($awaitable);
|
|
}
|
|
}
|