1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 13:21:16 +01:00
amp/test/SuccessTest.php

59 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2016-07-12 11:20:06 -05:00
namespace Amp\Test;
use Amp\Loop;
2016-07-12 11:20:06 -05:00
use Amp\Success;
use Amp\Promise;
2016-07-12 11:20:06 -05:00
class SuccessTest extends \PHPUnit\Framework\TestCase {
2016-07-12 11:20:06 -05:00
/**
* @expectedException \Error
2016-07-12 11:20:06 -05:00
*/
public function testConstructWithNonException() {
2016-11-14 13:59:21 -06:00
$failure = new Success($this->getMockBuilder(Promise::class)->getMock());
2016-07-12 11:20:06 -05:00
}
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) {
2016-07-12 11:20:06 -05:00
$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);
}
}