1
0
mirror of https://github.com/danog/amp.git synced 2024-11-27 04:24:42 +01:00
amp/test/SuccessTest.php
2016-08-12 16:58:53 -05:00

59 lines
1.4 KiB
PHP

<?php
namespace Amp\Test;
use Amp\Success;
use Interop\Async\Awaitable;
use Interop\Async\Loop;
class SuccessTest extends \PHPUnit_Framework_TestCase {
/**
* @expectedException \Error
*/
public function testConstructWithNonException() {
$failure = new Success($this->getMockBuilder(Awaitable::class)->getMock());
}
public function testWhen() {
$value = "Resolution value";
$invoked = 0;
$callback = function ($exception, $value) use (&$invoked, &$result) {
++$invoked;
$result = $value;
};
$success = new Success($value);
$success->when($callback);
$this->assertSame(1, $invoked);
$this->assertSame($value, $result);
}
/**
* @depends testWhen
*/
public function testWhenThrowingForwardsToLoopHandlerOnSuccess() {
Loop::execute(function () use (&$invoked) {
$invoked = 0;
$expected = new \Exception;
Loop::setErrorHandler(function ($exception) use (&$invoked, $expected) {
++$invoked;
$this->assertSame($expected, $exception);
});
$callback = function () use ($expected) {
throw $expected;
};
$success = new Success;
$success->when($callback);
});
$this->assertSame(1, $invoked);
}
}