mirror of
https://github.com/danog/amp.git
synced 2024-12-11 17:09:40 +01:00
c12828081f
This has been an edge case potentially hiding some exceptions. The tests have been refactored to error if the loop has watchers leaking from one test to another test.
42 lines
777 B
PHP
42 lines
777 B
PHP
<?php
|
|
|
|
namespace Amp\Test;
|
|
|
|
use Amp\Deferred;
|
|
use Amp\Promise;
|
|
|
|
class WrapTest extends BaseTest
|
|
{
|
|
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);
|
|
}
|
|
}
|