mirror of
https://github.com/danog/amp.git
synced 2025-01-22 13:21:16 +01:00
fe88413a17
This commit removes Humbug, as it's no longer maintained and not compatible with PHPUnit 6.
59 lines
1.4 KiB
PHP
59 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Amp\Test;
|
|
|
|
use Amp\Loop;
|
|
use Amp\Success;
|
|
use Amp\Promise;
|
|
|
|
class SuccessTest extends \PHPUnit\Framework\TestCase {
|
|
/**
|
|
* @expectedException \Error
|
|
*/
|
|
public function testConstructWithNonException() {
|
|
$failure = new Success($this->getMockBuilder(Promise::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::run(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);
|
|
}
|
|
}
|