mirror of
https://github.com/danog/amp.git
synced 2024-11-27 04:24:42 +01:00
fe88413a17
This commit removes Humbug, as it's no longer maintained and not compatible with PHPUnit 6.
63 lines
1.3 KiB
PHP
63 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Amp\Test;
|
|
|
|
use Amp;
|
|
use Amp\Deferred;
|
|
use Amp\Failure;
|
|
use Amp\Pause;
|
|
use Amp\Success;
|
|
use Amp\Loop;
|
|
|
|
class WaitTest extends \PHPUnit\Framework\TestCase {
|
|
public function testWaitOnSuccessfulPromise() {
|
|
$value = 1;
|
|
|
|
$promise = new Success($value);
|
|
|
|
$result = Amp\wait($promise);
|
|
|
|
$this->assertSame($value, $result);
|
|
}
|
|
|
|
public function testWaitOnFailedPromise() {
|
|
$exception = new \Exception();
|
|
|
|
$promise = new Failure($exception);
|
|
|
|
try {
|
|
$result = Amp\wait($promise);
|
|
} catch (\Exception $e) {
|
|
$this->assertSame($exception, $e);
|
|
return;
|
|
}
|
|
|
|
$this->fail('Rejection exception should be thrown from wait().');
|
|
}
|
|
|
|
/**
|
|
* @depends testWaitOnSuccessfulPromise
|
|
*/
|
|
public function testWaitOnPendingPromise() {
|
|
Loop::run(function () {
|
|
$value = 1;
|
|
|
|
$promise = new Pause(100, $value);
|
|
|
|
$result = Amp\wait($promise);
|
|
|
|
$this->assertSame($value, $result);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @expectedException \Error
|
|
* @expectedExceptionMessage Loop stopped without resolving promise
|
|
*/
|
|
public function testPromiseWithNoResolutionPathThrowsException() {
|
|
$promise = new Deferred;
|
|
|
|
$result = Amp\wait($promise->promise());
|
|
}
|
|
}
|