2018-11-26 19:36:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Amp\Test;
|
|
|
|
|
|
|
|
use Amp\Deferred;
|
|
|
|
use Amp\Promise;
|
|
|
|
|
2019-05-14 21:37:08 +02:00
|
|
|
class WrapTest extends BaseTest
|
2018-11-26 19:36:46 +01:00
|
|
|
{
|
|
|
|
public function testSuccess()
|
|
|
|
{
|
|
|
|
$deferred = new Deferred();
|
|
|
|
|
|
|
|
$promise = Promise\wrap($deferred->promise(), function () {
|
|
|
|
return 2;
|
|
|
|
});
|
|
|
|
|
|
|
|
$deferred->resolve(1);
|
|
|
|
|
|
|
|
$result = Promise\wait($promise);
|
|
|
|
|
|
|
|
$this->assertSame(2, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Exception
|
|
|
|
* @expectedExceptionMessage bar
|
|
|
|
*/
|
|
|
|
public function testFailure()
|
|
|
|
{
|
|
|
|
$deferred = new Deferred();
|
|
|
|
|
|
|
|
$promise = Promise\wrap($deferred->promise(), function () {
|
|
|
|
throw new \Exception('bar');
|
|
|
|
});
|
|
|
|
|
|
|
|
$deferred->fail(new \Exception('foo'));
|
|
|
|
|
|
|
|
Promise\wait($promise);
|
|
|
|
}
|
|
|
|
}
|