mirror of
https://github.com/danog/amp.git
synced 2024-11-30 04:29:08 +01:00
Separate functions into Promise and Stream namespaces
This commit is contained in:
parent
ea67e113b2
commit
a927b3cb06
@ -65,7 +65,7 @@ final class Coroutine implements Promise {
|
||||
|
||||
if (\is_array($yielded)) {
|
||||
try {
|
||||
$yielded = all($yielded);
|
||||
$yielded = Promise\all($yielded);
|
||||
} catch (UnionTypeError $e) {
|
||||
throw new InvalidYieldError(
|
||||
$this->generator,
|
||||
@ -77,7 +77,7 @@ final class Coroutine implements Promise {
|
||||
);
|
||||
}
|
||||
} else if ($yielded instanceof ReactPromise) {
|
||||
$yielded = adapt($yielded);
|
||||
$yielded = Promise\adapt($yielded);
|
||||
} else {
|
||||
throw new InvalidYieldError(
|
||||
$this->generator,
|
||||
@ -109,7 +109,7 @@ final class Coroutine implements Promise {
|
||||
|
||||
if (\is_array($yielded)) {
|
||||
try {
|
||||
$yielded = all($yielded);
|
||||
$yielded = Promise\all($yielded);
|
||||
} catch (UnionTypeError $e) {
|
||||
throw new InvalidYieldError(
|
||||
$this->generator,
|
||||
@ -121,7 +121,7 @@ final class Coroutine implements Promise {
|
||||
);
|
||||
}
|
||||
} else if ($yielded instanceof ReactPromise) {
|
||||
$yielded = adapt($yielded);
|
||||
$yielded = Promise\adapt($yielded);
|
||||
} else {
|
||||
throw new InvalidYieldError(
|
||||
$this->generator,
|
||||
|
@ -6,7 +6,7 @@ use Amp\Failure;
|
||||
use Amp\Loop;
|
||||
use Amp\Promise;
|
||||
use React\Promise\PromiseInterface as ReactPromise;
|
||||
use function Amp\adapt;
|
||||
use function Amp\Promise\adapt;
|
||||
|
||||
/**
|
||||
* Trait used by Promise implementations. Do not use this trait in your code, instead compose your class from one of
|
||||
|
@ -7,7 +7,7 @@ use Amp\Loop;
|
||||
use Amp\Promise;
|
||||
use Amp\Success;
|
||||
use React\Promise\PromiseInterface as ReactPromise;
|
||||
use function Amp\adapt;
|
||||
use function Amp\Promise\adapt;
|
||||
|
||||
/**
|
||||
* Trait used by Stream implementations. Do not use this trait in your code, instead compose your class from one of
|
||||
|
@ -35,7 +35,7 @@ class LazyPromise implements Promise {
|
||||
$this->promise = $provider();
|
||||
|
||||
if ($this->promise instanceof ReactPromise) {
|
||||
$this->promise = adapt($this->promise);
|
||||
$this->promise = Promise\adapt($this->promise);
|
||||
}
|
||||
|
||||
if (!$this->promise instanceof Promise) {
|
||||
|
@ -6,7 +6,7 @@ use Amp\Coroutine;
|
||||
use Amp\Promise;
|
||||
use Amp\Internal\Watcher;
|
||||
use React\Promise\PromiseInterface as ReactPromise;
|
||||
use function Amp\rethrow;
|
||||
use function Amp\Promise\rethrow;
|
||||
|
||||
/**
|
||||
* Event loop driver which implements all basic operations to allow interoperability.
|
||||
|
@ -6,7 +6,7 @@ use Amp\Coroutine;
|
||||
use Amp\Promise;
|
||||
use Amp\Internal\Watcher;
|
||||
use React\Promise\PromiseInterface as ReactPromise;
|
||||
use function Amp\rethrow;
|
||||
use function Amp\Promise\rethrow;
|
||||
|
||||
class EvDriver extends Driver {
|
||||
/** @var \EvSignal[]|null */
|
||||
|
@ -6,7 +6,7 @@ use Amp\Coroutine;
|
||||
use Amp\Promise;
|
||||
use Amp\Internal\Watcher;
|
||||
use React\Promise\PromiseInterface as ReactPromise;
|
||||
use function Amp\rethrow;
|
||||
use function Amp\Promise\rethrow;
|
||||
|
||||
class EventDriver extends Driver {
|
||||
/** @var \Event[]|null */
|
||||
|
@ -6,7 +6,7 @@ use Amp\Coroutine;
|
||||
use Amp\Promise;
|
||||
use Amp\Internal\Watcher;
|
||||
use React\Promise\PromiseInterface as ReactPromise;
|
||||
use function Amp\rethrow;
|
||||
use function Amp\Promise\rethrow;
|
||||
|
||||
class NativeDriver extends Driver {
|
||||
/** @var resource[] */
|
||||
|
@ -6,7 +6,7 @@ use Amp\Coroutine;
|
||||
use Amp\Promise;
|
||||
use Amp\Internal\Watcher;
|
||||
use React\Promise\PromiseInterface as ReactPromise;
|
||||
use function Amp\rethrow;
|
||||
use function Amp\Promise\rethrow;
|
||||
|
||||
class UvDriver extends Driver {
|
||||
/** @var resource A uv_loop resource created with uv_loop_new() */
|
||||
|
1367
lib/functions.php
1367
lib/functions.php
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
use Amp;
|
||||
use Amp\Failure;
|
||||
use Amp\Success;
|
||||
use Amp\Promise;
|
||||
@ -48,7 +47,7 @@ class AdaptTest extends \PHPUnit\Framework\TestCase {
|
||||
})
|
||||
);
|
||||
|
||||
$promise = Amp\adapt($mock);
|
||||
$promise = Promise\adapt($mock);
|
||||
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
}
|
||||
@ -61,7 +60,7 @@ class AdaptTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$promise = new PromiseMock(new Success($value));
|
||||
|
||||
$promise = Amp\adapt($promise);
|
||||
$promise = Promise\adapt($promise);
|
||||
|
||||
$promise->when(function ($exception, $value) use (&$result) {
|
||||
$result = $value;
|
||||
@ -78,7 +77,7 @@ class AdaptTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$promise = new PromiseMock(new Failure($exception));
|
||||
|
||||
$promise = Amp\adapt($promise);
|
||||
$promise = Promise\adapt($promise);
|
||||
|
||||
$promise->when(function ($exception, $value) use (&$reason) {
|
||||
$reason = $exception;
|
||||
@ -91,13 +90,13 @@ class AdaptTest extends \PHPUnit\Framework\TestCase {
|
||||
* @expectedException \Error
|
||||
*/
|
||||
public function testScalarValue() {
|
||||
Amp\adapt(1);
|
||||
Promise\adapt(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Error
|
||||
*/
|
||||
public function testNonThenableObject() {
|
||||
Amp\adapt(new \stdClass);
|
||||
Promise\adapt(new \stdClass);
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
use Amp;
|
||||
use Amp\Pause;
|
||||
use Amp\Promise;
|
||||
use Amp\Success;
|
||||
use Amp\Loop;
|
||||
|
||||
@ -13,7 +13,7 @@ class AllTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\all([])->when($callback);
|
||||
Promise\all([])->when($callback);
|
||||
|
||||
$this->assertSame([], $result);
|
||||
}
|
||||
@ -25,7 +25,7 @@ class AllTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\all($promises)->when($callback);
|
||||
Promise\all($promises)->when($callback);
|
||||
|
||||
$this->assertSame([1, 2, 3], $result);
|
||||
}
|
||||
@ -42,7 +42,7 @@ class AllTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\all($promises)->when($callback);
|
||||
Promise\all($promises)->when($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals([1, 2, 3], $result);
|
||||
@ -62,7 +62,7 @@ class AllTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\all($promises)->when($callback);
|
||||
Promise\all($promises)->when($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
@ -72,6 +72,6 @@ class AllTest extends \PHPUnit\Framework\TestCase {
|
||||
* @expectedException \Amp\UnionTypeError
|
||||
*/
|
||||
public function testNonPromise() {
|
||||
Amp\all([1]);
|
||||
Promise\all([1]);
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
use Amp;
|
||||
use Amp\Failure;
|
||||
use Amp\Pause;
|
||||
use Amp\Promise;
|
||||
use Amp\Success;
|
||||
use Amp\Loop;
|
||||
|
||||
@ -14,7 +14,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\any([])->when($callback);
|
||||
Promise\any([])->when($callback);
|
||||
|
||||
$this->assertSame([[], []], $result);
|
||||
}
|
||||
@ -26,7 +26,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\any($promises)->when($callback);
|
||||
Promise\any($promises)->when($callback);
|
||||
|
||||
$this->assertEquals([[], [1, 2, 3]], $result);
|
||||
}
|
||||
@ -39,7 +39,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\any($promises)->when($callback);
|
||||
Promise\any($promises)->when($callback);
|
||||
|
||||
$this->assertEquals([[$exception, $exception, $exception], []], $result);
|
||||
}
|
||||
@ -52,7 +52,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\any($promises)->when($callback);
|
||||
Promise\any($promises)->when($callback);
|
||||
|
||||
$this->assertEquals([[1 => $exception], [0 => 1, 2 => 3]], $result);
|
||||
}
|
||||
@ -69,7 +69,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\any($promises)->when($callback);
|
||||
Promise\any($promises)->when($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals([[], [1, 2, 3]], $result);
|
||||
@ -93,7 +93,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\any($promises)->when($callback);
|
||||
Promise\any($promises)->when($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
@ -103,6 +103,6 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
* @expectedException \Amp\UnionTypeError
|
||||
*/
|
||||
public function testNonPromise() {
|
||||
Amp\any([1]);
|
||||
Promise\any([1]);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
use Amp;
|
||||
use Amp\Failure;
|
||||
use Amp\Success;
|
||||
use Amp\Promise;
|
||||
@ -20,7 +19,7 @@ class CaptureTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$promise = new Success($value);
|
||||
|
||||
$promise = Amp\capture($promise, \Exception::class, $callback);
|
||||
$promise = Promise\capture($promise, \Exception::class, $callback);
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$callback = function ($exception, $value) use (&$result) {
|
||||
@ -45,7 +44,7 @@ class CaptureTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$promise = new Failure($exception);
|
||||
|
||||
$promise = Amp\capture($promise, \Exception::class, $callback);
|
||||
$promise = Promise\capture($promise, \Exception::class, $callback);
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$callback = function ($exception, $value) use (&$result) {
|
||||
@ -73,7 +72,7 @@ class CaptureTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$promise = new Failure($exception);
|
||||
|
||||
$promise = Amp\capture($promise, \Exception::class, $callback);
|
||||
$promise = Promise\capture($promise, \Exception::class, $callback);
|
||||
|
||||
$callback = function ($exception, $value) use (&$reason) {
|
||||
$reason = $exception;
|
||||
@ -100,7 +99,7 @@ class CaptureTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$promise = new Failure($exception);
|
||||
|
||||
$promise = Amp\capture($promise, \RuntimeException::class, $callback);
|
||||
$promise = Promise\capture($promise, \RuntimeException::class, $callback);
|
||||
|
||||
$callback = function ($exception, $value) use (&$reason) {
|
||||
$reason = $exception;
|
||||
@ -127,7 +126,7 @@ class CaptureTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$promise = reject($exception);
|
||||
|
||||
$promise = Amp\capture($promise, \Exception::class, $callback);
|
||||
$promise = Promise\capture($promise, \Exception::class, $callback);
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$callback = function ($exception, $value) use (&$result) {
|
||||
@ -142,7 +141,7 @@ class CaptureTest extends \PHPUnit\Framework\TestCase {
|
||||
}
|
||||
|
||||
public function testNonPromise() {
|
||||
$this->expectException(Amp\UnionTypeError::class);
|
||||
Amp\capture(42, \Error::class, function () {});
|
||||
$this->expectException(\Amp\UnionTypeError::class);
|
||||
Promise\capture(42, \Error::class, function () {});
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
use Amp;
|
||||
use Amp\Loop;
|
||||
use Amp\Producer;
|
||||
use Amp\Stream;
|
||||
@ -24,12 +23,12 @@ class ConcatTest extends \PHPUnit\Framework\TestCase {
|
||||
*/
|
||||
public function testConcat(array $streams, array $expected) {
|
||||
$streams = \array_map(function (array $stream): Stream {
|
||||
return Amp\stream($stream);
|
||||
return Stream\fromIterable($stream);
|
||||
}, $streams);
|
||||
|
||||
$stream = Amp\concat($streams);
|
||||
$stream = Stream\concat($streams);
|
||||
|
||||
Amp\each($stream, function ($value) use ($expected) {
|
||||
Stream\map($stream, function ($value) use ($expected) {
|
||||
static $i = 0;
|
||||
$this->assertSame($expected[$i++], $value);
|
||||
});
|
||||
@ -49,7 +48,7 @@ class ConcatTest extends \PHPUnit\Framework\TestCase {
|
||||
throw $exception;
|
||||
});
|
||||
|
||||
$stream = Amp\concat([Amp\stream(\range(1, 5)), $producer, Amp\stream(\range(7, 10))]);
|
||||
$stream = Stream\concat([Stream\fromIterable(\range(1, 5)), $producer, Stream\fromIterable(\range(7, 10))]);
|
||||
|
||||
$stream->listen(function ($value) use (&$results) {
|
||||
$results[] = $value;
|
||||
@ -70,6 +69,6 @@ class ConcatTest extends \PHPUnit\Framework\TestCase {
|
||||
* @expectedException \Amp\UnionTypeError
|
||||
*/
|
||||
public function testNonStream() {
|
||||
Amp\concat([1]);
|
||||
Stream\concat([1]);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
use Amp;
|
||||
use Amp\Coroutine;
|
||||
use Amp\Failure;
|
||||
use Amp\InvalidYieldError;
|
||||
@ -504,7 +503,7 @@ class CoroutineTest extends TestCase {
|
||||
}
|
||||
|
||||
public function testCoroutineFunction() {
|
||||
$callable = Amp\coroutine(function () {
|
||||
$callable = \Amp\coroutine(function () {
|
||||
yield;
|
||||
});
|
||||
|
||||
@ -517,7 +516,7 @@ class CoroutineTest extends TestCase {
|
||||
public function testCoroutineFunctionWithCallbackReturningPromise() {
|
||||
$value = 1;
|
||||
$promise = new Success($value);
|
||||
$callable = Amp\coroutine(function ($value) {
|
||||
$callable = \Amp\coroutine(function ($value) {
|
||||
return $value;
|
||||
});
|
||||
|
||||
@ -540,7 +539,7 @@ class CoroutineTest extends TestCase {
|
||||
*/
|
||||
public function testCoroutineFunctionWithNonGeneratorCallback() {
|
||||
$value = 1;
|
||||
$callable = Amp\coroutine(function ($value) {
|
||||
$callable = \Amp\coroutine(function ($value) {
|
||||
return $value;
|
||||
});
|
||||
|
||||
@ -563,7 +562,7 @@ class CoroutineTest extends TestCase {
|
||||
*/
|
||||
public function testCoroutineFunctionWithThrowingCallback() {
|
||||
$exception = new \Exception;
|
||||
$callable = Amp\coroutine(function () use ($exception) {
|
||||
$callable = \Amp\coroutine(function () use ($exception) {
|
||||
throw $exception;
|
||||
});
|
||||
|
||||
@ -585,7 +584,7 @@ class CoroutineTest extends TestCase {
|
||||
* @depends testCoroutineFunction
|
||||
*/
|
||||
public function testCoroutineFunctionWithSuccessReturnCallback() {
|
||||
$callable = Amp\coroutine(function () {
|
||||
$callable = \Amp\coroutine(function () {
|
||||
return new Success(42);
|
||||
});
|
||||
|
||||
@ -604,7 +603,7 @@ class CoroutineTest extends TestCase {
|
||||
}
|
||||
|
||||
public function testCoroutineFunctionWithReactPromise() {
|
||||
$callable = Amp\coroutine(function () {
|
||||
$callable = \Amp\coroutine(function () {
|
||||
return new FulfilledReactPromise(42);
|
||||
});
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
use Amp;
|
||||
use Amp\Producer;
|
||||
use Amp\Stream;
|
||||
use Amp\Emitter;
|
||||
@ -14,7 +13,7 @@ class FilterTest extends \PHPUnit\Framework\TestCase {
|
||||
Loop::run(function () use (&$invoked){
|
||||
$emitter = new Emitter;
|
||||
|
||||
$stream = Amp\filter($emitter->stream(), function ($value) use (&$invoked) {
|
||||
$stream = Stream\filter($emitter->stream(), function ($value) use (&$invoked) {
|
||||
$invoked = true;
|
||||
});
|
||||
|
||||
@ -38,7 +37,7 @@ class FilterTest extends \PHPUnit\Framework\TestCase {
|
||||
}
|
||||
});
|
||||
|
||||
$stream = Amp\filter($producer, function ($value) use (&$count) {
|
||||
$stream = Stream\filter($producer, function ($value) use (&$count) {
|
||||
++$count;
|
||||
return $value & 1;
|
||||
});
|
||||
@ -69,7 +68,7 @@ class FilterTest extends \PHPUnit\Framework\TestCase {
|
||||
}
|
||||
});
|
||||
|
||||
$stream = Amp\filter($producer, function () use ($exception) {
|
||||
$stream = Stream\filter($producer, function () use ($exception) {
|
||||
throw $exception;
|
||||
});
|
||||
|
||||
@ -93,7 +92,7 @@ class FilterTest extends \PHPUnit\Framework\TestCase {
|
||||
Loop::run(function () use (&$invoked, &$reason, &$exception){
|
||||
$emitter = new Emitter;
|
||||
|
||||
$stream = Amp\filter($emitter->stream(), function ($value) use (&$invoked) {
|
||||
$stream = Stream\filter($emitter->stream(), function ($value) use (&$invoked) {
|
||||
$invoked = true;
|
||||
});
|
||||
|
||||
|
@ -6,6 +6,7 @@ use Amp;
|
||||
use Amp\Failure;
|
||||
use Amp\MultiReasonException;
|
||||
use Amp\Pause;
|
||||
use Amp\Promise;
|
||||
use Amp\Success;
|
||||
use Amp\Loop;
|
||||
|
||||
@ -15,7 +16,7 @@ class FirstTest extends \PHPUnit\Framework\TestCase {
|
||||
* @expectedExceptionMessage No promises provided
|
||||
*/
|
||||
public function testEmptyArray() {
|
||||
Amp\first([]);
|
||||
Promise\first([]);
|
||||
}
|
||||
|
||||
public function testSuccessfulPromisesArray() {
|
||||
@ -25,7 +26,7 @@ class FirstTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\first($promises)->when($callback);
|
||||
Promise\first($promises)->when($callback);
|
||||
|
||||
$this->assertSame(1, $result);
|
||||
}
|
||||
@ -38,7 +39,7 @@ class FirstTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
Amp\first($promises)->when($callback);
|
||||
Promise\first($promises)->when($callback);
|
||||
|
||||
$this->assertInstanceOf(MultiReasonException::class, $reason);
|
||||
$this->assertEquals([$exception, $exception, $exception], $reason->getReasons());
|
||||
@ -52,7 +53,7 @@ class FirstTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\first($promises)->when($callback);
|
||||
Promise\first($promises)->when($callback);
|
||||
|
||||
$this->assertSame(3, $result);
|
||||
}
|
||||
@ -69,7 +70,7 @@ class FirstTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\first($promises)->when($callback);
|
||||
Promise\first($promises)->when($callback);
|
||||
});
|
||||
|
||||
$this->assertSame(3, $result);
|
||||
@ -79,6 +80,6 @@ class FirstTest extends \PHPUnit\Framework\TestCase {
|
||||
* @expectedException \Amp\UnionTypeError
|
||||
*/
|
||||
public function testNonPromise() {
|
||||
Amp\first([1]);
|
||||
Promise\first([1]);
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,9 @@
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
use Amp;
|
||||
use Amp\Pause;
|
||||
use Amp\Promise;
|
||||
use Amp\Stream;
|
||||
use Amp\Loop;
|
||||
|
||||
class IntervalTest extends \PHPUnit\Framework\TestCase {
|
||||
@ -11,14 +12,14 @@ class IntervalTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
public function testInterval() {
|
||||
$count = 3;
|
||||
$stream = Amp\interval(self::TIMEOUT, $count);
|
||||
$stream = Stream\interval(self::TIMEOUT, $count);
|
||||
|
||||
$i = 0;
|
||||
$stream = Amp\each($stream, function ($value) use (&$i) {
|
||||
$stream = Stream\map($stream, function ($value) use (&$i) {
|
||||
$this->assertSame(++$i, $value);
|
||||
});
|
||||
|
||||
Amp\wait($stream);
|
||||
Promise\wait($stream);
|
||||
|
||||
$this->assertSame($count, $i);
|
||||
}
|
||||
@ -30,7 +31,7 @@ class IntervalTest extends \PHPUnit\Framework\TestCase {
|
||||
$invoked = 0;
|
||||
$count = 5;
|
||||
Loop::run(function () use (&$invoked, $count) {
|
||||
$stream = Amp\interval(self::TIMEOUT, $count);
|
||||
$stream = Stream\interval(self::TIMEOUT, $count);
|
||||
|
||||
$stream->listen(function () use (&$invoked) {
|
||||
++$invoked;
|
||||
@ -46,6 +47,6 @@ class IntervalTest extends \PHPUnit\Framework\TestCase {
|
||||
* @expectedExceptionMessage The number of times to emit must be a positive value
|
||||
*/
|
||||
public function testInvalidCount() {
|
||||
Amp\interval(self::TIMEOUT, -1);
|
||||
Stream\interval(self::TIMEOUT, -1);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
use Amp;
|
||||
use Amp\Loop;
|
||||
use Amp\Producer;
|
||||
use Amp\Stream;
|
||||
@ -24,12 +23,12 @@ class MergeTest extends \PHPUnit\Framework\TestCase {
|
||||
*/
|
||||
public function testMerge(array $streams, array $expected) {
|
||||
$streams = \array_map(function (array $stream): Stream {
|
||||
return Amp\stream($stream);
|
||||
return Stream\fromIterable($stream);
|
||||
}, $streams);
|
||||
|
||||
$stream = Amp\merge($streams);
|
||||
$stream = Stream\merge($streams);
|
||||
|
||||
Amp\each($stream, function ($value) use ($expected) {
|
||||
Stream\map($stream, function ($value) use ($expected) {
|
||||
static $i = 0;
|
||||
$this->assertSame($expected[$i++], $value);
|
||||
});
|
||||
@ -48,7 +47,7 @@ class MergeTest extends \PHPUnit\Framework\TestCase {
|
||||
throw $exception;
|
||||
});
|
||||
|
||||
$stream = Amp\merge([$producer, Amp\stream(\range(1, 5))]);
|
||||
$stream = Stream\merge([$producer, Stream\fromIterable(\range(1, 5))]);
|
||||
|
||||
$callback = function ($exception, $value) use (&$reason) {
|
||||
$reason = $exception;
|
||||
@ -64,6 +63,6 @@ class MergeTest extends \PHPUnit\Framework\TestCase {
|
||||
* @expectedException \Amp\UnionTypeError
|
||||
*/
|
||||
public function testNonStream() {
|
||||
Amp\merge([1]);
|
||||
Stream\merge([1]);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
use Amp;
|
||||
use Amp\Failure;
|
||||
use Amp\Success;
|
||||
use Amp\Promise;
|
||||
@ -20,7 +19,7 @@ class PipeTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$promise = new Success($value);
|
||||
|
||||
$promise = Amp\pipe($promise, $callback);
|
||||
$promise = Promise\pipe($promise, $callback);
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$callback = function ($exception, $value) use (&$result) {
|
||||
@ -44,7 +43,7 @@ class PipeTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$promise = new Failure($exception);
|
||||
|
||||
$promise = Amp\pipe($promise, $callback);
|
||||
$promise = Promise\pipe($promise, $callback);
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$callback = function ($exception, $value) use (&$reason) {
|
||||
@ -71,7 +70,7 @@ class PipeTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$promise = new Success($value);
|
||||
|
||||
$promise = Amp\pipe($promise, $callback);
|
||||
$promise = Promise\pipe($promise, $callback);
|
||||
|
||||
$callback = function ($exception, $value) use (&$reason) {
|
||||
$reason = $exception;
|
||||
@ -97,7 +96,7 @@ class PipeTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$promise = resolve($value);
|
||||
|
||||
$promise = Amp\pipe($promise, $callback);
|
||||
$promise = Promise\pipe($promise, $callback);
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$callback = function ($exception, $value) use (&$result) {
|
||||
@ -111,7 +110,7 @@ class PipeTest extends \PHPUnit\Framework\TestCase {
|
||||
}
|
||||
|
||||
public function testNonPromise() {
|
||||
$this->expectException(Amp\UnionTypeError::class);
|
||||
Amp\pipe(42, function () {});
|
||||
$this->expectException(\Amp\UnionTypeError::class);
|
||||
Promise\pipe(42, function () {});
|
||||
}
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ class ProducerTest extends TestCase {
|
||||
throw $exception;
|
||||
});
|
||||
|
||||
Amp\wait($producer);
|
||||
Amp\Promise\wait($producer);
|
||||
});
|
||||
} catch (\Exception $caught) {
|
||||
$this->assertSame($exception, $caught);
|
||||
|
@ -2,20 +2,19 @@
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
use Amp;
|
||||
use Amp\Deferred;
|
||||
use Amp\Failure;
|
||||
use Amp\Loop;
|
||||
use Amp\Pause;
|
||||
use Amp\Success;
|
||||
use Amp\Promise;
|
||||
use Amp\Success;
|
||||
|
||||
class MapTest extends \PHPUnit\Framework\TestCase {
|
||||
class PromiseMapTest extends \PHPUnit\Framework\TestCase {
|
||||
public function testEmptyArray() {
|
||||
$values = [];
|
||||
$invoked = false;
|
||||
|
||||
$result = Amp\map(function () use (&$invoked) {
|
||||
$result = Promise\map(function () use (&$invoked) {
|
||||
$invoked = true;
|
||||
}, $values);
|
||||
|
||||
@ -33,13 +32,13 @@ class MapTest extends \PHPUnit\Framework\TestCase {
|
||||
return $value - 1;
|
||||
};
|
||||
|
||||
$result = Amp\map($callback, $promises);
|
||||
$result = Promise\map($callback, $promises);
|
||||
|
||||
$this->assertTrue(\is_array($result));
|
||||
|
||||
foreach ($result as $key => $promise) {
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
$this->assertSame($key, Amp\wait($promise));
|
||||
$this->assertSame($key, Promise\wait($promise));
|
||||
}
|
||||
|
||||
$this->assertSame(\count($promises), $count);
|
||||
@ -63,7 +62,7 @@ class MapTest extends \PHPUnit\Framework\TestCase {
|
||||
return $value - 1;
|
||||
};
|
||||
|
||||
$result = Amp\map($callback, $promises);
|
||||
$result = Promise\map($callback, $promises);
|
||||
|
||||
$this->assertTrue(\is_array($result));
|
||||
|
||||
@ -73,7 +72,7 @@ class MapTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
foreach ($result as $key => $promise) {
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
$this->assertSame($key, Amp\wait($promise));
|
||||
$this->assertSame($key, Promise\wait($promise));
|
||||
}
|
||||
|
||||
$this->assertSame(\count($promises), $count);
|
||||
@ -90,7 +89,7 @@ class MapTest extends \PHPUnit\Framework\TestCase {
|
||||
return $value - 1;
|
||||
};
|
||||
|
||||
$result = Amp\map($callback, $promises);
|
||||
$result = Promise\map($callback, $promises);
|
||||
|
||||
$this->assertTrue(\is_array($result));
|
||||
|
||||
@ -115,7 +114,7 @@ class MapTest extends \PHPUnit\Framework\TestCase {
|
||||
throw $exception;
|
||||
};
|
||||
|
||||
$result = Amp\map($callback, $promises);
|
||||
$result = Promise\map($callback, $promises);
|
||||
|
||||
foreach ($result as $key => $promise) {
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
@ -123,7 +122,7 @@ class MapTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
foreach ($result as $key => $promise) {
|
||||
try {
|
||||
Amp\wait($promise);
|
||||
Promise\wait($promise);
|
||||
} catch (\Exception $reason) {
|
||||
$this->assertSame($exception, $reason);
|
||||
}
|
||||
@ -144,7 +143,7 @@ class MapTest extends \PHPUnit\Framework\TestCase {
|
||||
return $value1 + $value2;
|
||||
};
|
||||
|
||||
$result = Amp\map($callback, $promises1, $promises2);
|
||||
$result = Promise\map($callback, $promises1, $promises2);
|
||||
|
||||
foreach ($result as $key => $promise) {
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
@ -152,7 +151,7 @@ class MapTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
foreach ($result as $promise) {
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
$this->assertSame(4, Amp\wait($promise));
|
||||
$this->assertSame(4, Promise\wait($promise));
|
||||
}
|
||||
|
||||
$this->assertSame(3, $count);
|
||||
@ -173,10 +172,10 @@ class MapTest extends \PHPUnit\Framework\TestCase {
|
||||
return $value1 + $value2;
|
||||
};
|
||||
|
||||
$result = Amp\map($callback, $promises1, $promises2);
|
||||
$result = Promise\map($callback, $promises1, $promises2);
|
||||
|
||||
foreach ($result as $promise) {
|
||||
$this->assertSame(4, Amp\wait($promise));
|
||||
$this->assertSame(4, Promise\wait($promise));
|
||||
}
|
||||
|
||||
$this->assertSame(3, $count);
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
use Amp;
|
||||
use Amp\Failure;
|
||||
use Amp\Loop;
|
||||
use Amp\Promise;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use function React\Promise\reject;
|
||||
|
||||
@ -16,7 +16,7 @@ class RethrowTest extends TestCase {
|
||||
Loop::run(function () use ($exception) {
|
||||
$promise = new Failure($exception);
|
||||
|
||||
Amp\rethrow($promise);
|
||||
Promise\rethrow($promise);
|
||||
});
|
||||
} catch (\Exception $reason) {
|
||||
$this->assertSame($exception, $reason);
|
||||
@ -36,7 +36,7 @@ class RethrowTest extends TestCase {
|
||||
Loop::run(function () use ($exception) {
|
||||
$promise = reject($exception);
|
||||
|
||||
Amp\rethrow($promise);
|
||||
Promise\rethrow($promise);
|
||||
});
|
||||
} catch (\Exception $reason) {
|
||||
$this->assertSame($exception, $reason);
|
||||
@ -47,7 +47,7 @@ class RethrowTest extends TestCase {
|
||||
}
|
||||
|
||||
public function testNonPromise() {
|
||||
$this->expectException(Amp\UnionTypeError::class);
|
||||
Amp\rethrow(42);
|
||||
$this->expectException(\Amp\UnionTypeError::class);
|
||||
Promise\rethrow(42);
|
||||
}
|
||||
}
|
||||
|
@ -2,20 +2,16 @@
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
use Amp;
|
||||
use Amp\Failure;
|
||||
use Amp\MultiReasonException;
|
||||
use Amp\Pause;
|
||||
use Amp\Promise;
|
||||
use Amp\Success;
|
||||
use Amp\Loop;
|
||||
|
||||
class SomeTest extends \PHPUnit\Framework\TestCase {
|
||||
/**
|
||||
* @expectedException \Error
|
||||
* @expectedExceptionMessage No promises provided
|
||||
*/
|
||||
public function testEmptyArray() {
|
||||
Amp\some([]);
|
||||
$this->assertSame([[], []], Promise\wait(Promise\some([])));
|
||||
}
|
||||
|
||||
public function testSuccessfulPromisesArray() {
|
||||
@ -25,7 +21,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\some($promises)->when($callback);
|
||||
Promise\some($promises)->when($callback);
|
||||
|
||||
$this->assertSame([[], [1, 2, 3]], $result);
|
||||
}
|
||||
@ -38,7 +34,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
Amp\some($promises)->when($callback);
|
||||
Promise\some($promises)->when($callback);
|
||||
|
||||
$this->assertInstanceOf(MultiReasonException::class, $reason);
|
||||
$this->assertEquals([$exception, $exception, $exception], $reason->getReasons());
|
||||
@ -52,7 +48,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\some($promises)->when($callback);
|
||||
Promise\some($promises)->when($callback);
|
||||
|
||||
$this->assertSame([[0 => $exception, 1 => $exception], [2 => 3]], $result);
|
||||
}
|
||||
@ -69,7 +65,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\some($promises)->when($callback);
|
||||
Promise\some($promises)->when($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals([[], [0 => 1, 1 => 2, 2 => 3]], $result);
|
||||
@ -89,7 +85,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Amp\some($promises)->when($callback);
|
||||
Promise\some($promises)->when($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
@ -99,6 +95,6 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
|
||||
* @expectedException \Error
|
||||
*/
|
||||
public function testNonPromise() {
|
||||
Amp\some([1]);
|
||||
Promise\some([1]);
|
||||
}
|
||||
}
|
||||
|
@ -2,17 +2,17 @@
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
use Amp;
|
||||
use Amp\Failure;
|
||||
use Amp\Pause;
|
||||
use Amp\Stream;
|
||||
use Amp\Success;
|
||||
use Amp\Loop;
|
||||
|
||||
class StreamTest extends \PHPUnit\Framework\TestCase {
|
||||
class StreamFromIterableTest extends \PHPUnit\Framework\TestCase {
|
||||
public function testSuccessfulPromises() {
|
||||
$results = [];
|
||||
Loop::run(function () use (&$results) {
|
||||
$stream = Amp\stream([new Success(1), new Success(2), new Success(3)]);
|
||||
$stream = Stream\fromIterable([new Success(1), new Success(2), new Success(3)]);
|
||||
|
||||
$stream->listen(function ($value) use (&$results) {
|
||||
$results[] = $value;
|
||||
@ -25,7 +25,7 @@ class StreamTest extends \PHPUnit\Framework\TestCase {
|
||||
public function testFailedPromises() {
|
||||
$exception = new \Exception;
|
||||
Loop::run(function () use (&$reason, $exception) {
|
||||
$stream = Amp\stream([new Failure($exception), new Failure($exception)]);
|
||||
$stream = Stream\fromIterable([new Failure($exception), new Failure($exception)]);
|
||||
|
||||
$callback = function ($exception, $value) use (&$reason) {
|
||||
$reason = $exception;
|
||||
@ -41,7 +41,7 @@ class StreamTest extends \PHPUnit\Framework\TestCase {
|
||||
$exception = new \Exception;
|
||||
$results = [];
|
||||
Loop::run(function () use (&$results, &$reason, $exception) {
|
||||
$stream = Amp\stream([new Success(1), new Success(2), new Failure($exception), new Success(4)]);
|
||||
$stream = Stream\fromIterable([new Success(1), new Success(2), new Failure($exception), new Success(4)]);
|
||||
|
||||
$stream->listen(function ($value) use (&$results) {
|
||||
$results[] = $value;
|
||||
@ -61,7 +61,7 @@ class StreamTest extends \PHPUnit\Framework\TestCase {
|
||||
public function testPendingPromises() {
|
||||
$results = [];
|
||||
Loop::run(function () use (&$results) {
|
||||
$stream = Amp\stream([new Pause(30, 1), new Pause(10, 2), new Pause(20, 3), new Success(4)]);
|
||||
$stream = Stream\fromIterable([new Pause(30, 1), new Pause(10, 2), new Pause(20, 3), new Success(4)]);
|
||||
|
||||
$stream->listen(function ($value) use (&$results) {
|
||||
$results[] = $value;
|
||||
@ -80,7 +80,7 @@ class StreamTest extends \PHPUnit\Framework\TestCase {
|
||||
}
|
||||
})();
|
||||
|
||||
$stream = Amp\stream($generator);
|
||||
$stream = Stream\fromIterable($generator);
|
||||
|
||||
$stream->listen(function ($value) use (&$results) {
|
||||
$results[] = $value;
|
||||
@ -95,7 +95,7 @@ class StreamTest extends \PHPUnit\Framework\TestCase {
|
||||
* @dataProvider provideInvalidStreamArguments
|
||||
*/
|
||||
public function testInvalid($arg) {
|
||||
Amp\stream($arg);
|
||||
Stream\fromIterable($arg);
|
||||
}
|
||||
|
||||
public function provideInvalidStreamArguments() {
|
@ -8,13 +8,13 @@ use Amp\Stream;
|
||||
use Amp\Emitter;
|
||||
use Amp\Loop;
|
||||
|
||||
class EachTest extends \PHPUnit\Framework\TestCase {
|
||||
class StreamMapTest extends \PHPUnit\Framework\TestCase {
|
||||
public function testNoValuesEmitted() {
|
||||
$invoked = false;
|
||||
Loop::run(function () use (&$invoked){
|
||||
$emitter = new Emitter;
|
||||
|
||||
$stream = Amp\each($emitter->stream(), function ($value) use (&$invoked) {
|
||||
$stream = Stream\map($emitter->stream(), function ($value) use (&$invoked) {
|
||||
$invoked = true;
|
||||
});
|
||||
|
||||
@ -39,7 +39,7 @@ class EachTest extends \PHPUnit\Framework\TestCase {
|
||||
return $final;
|
||||
});
|
||||
|
||||
$stream = Amp\each($producer, function ($value) use (&$count) {
|
||||
$stream = Stream\map($producer, function ($value) use (&$count) {
|
||||
++$count;
|
||||
return $value + 1;
|
||||
}, function ($value) use (&$invoked) {
|
||||
@ -73,7 +73,7 @@ class EachTest extends \PHPUnit\Framework\TestCase {
|
||||
}
|
||||
});
|
||||
|
||||
$stream = Amp\each($producer, function () use ($exception) {
|
||||
$stream = Stream\map($producer, function () use ($exception) {
|
||||
throw $exception;
|
||||
});
|
||||
|
||||
@ -106,7 +106,7 @@ class EachTest extends \PHPUnit\Framework\TestCase {
|
||||
}
|
||||
});
|
||||
|
||||
$stream = Amp\each($producer, function ($value) use (&$count) {
|
||||
$stream = Stream\map($producer, function ($value) use (&$count) {
|
||||
++$count;
|
||||
return $value + 1;
|
||||
}, function ($value) use ($exception) {
|
||||
@ -135,7 +135,7 @@ class EachTest extends \PHPUnit\Framework\TestCase {
|
||||
Loop::run(function () use (&$invoked, &$reason, &$exception){
|
||||
$emitter = new Emitter;
|
||||
|
||||
$stream = Amp\each($emitter->stream(), function ($value) use (&$invoked) {
|
||||
$stream = Stream\map($emitter->stream(), function ($value) use (&$invoked) {
|
||||
$invoked = true;
|
||||
});
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
use Amp;
|
||||
use Amp\Failure;
|
||||
use Amp\Loop;
|
||||
use Amp\Pause;
|
||||
@ -17,7 +16,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$promise = new Success($value);
|
||||
|
||||
$promise = Amp\timeout($promise, 100);
|
||||
$promise = Promise\timeout($promise, 100);
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$callback = function ($exception, $value) use (&$result) {
|
||||
@ -36,7 +35,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$promise = new Failure($exception);
|
||||
|
||||
$promise = Amp\timeout($promise, 100);
|
||||
$promise = Promise\timeout($promise, 100);
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$callback = function ($exception, $value) use (&$reason) {
|
||||
@ -58,7 +57,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
|
||||
Loop::run(function () use (&$result, $value) {
|
||||
$promise = new Pause(50, $value);
|
||||
|
||||
$promise = Amp\timeout($promise, 100);
|
||||
$promise = Promise\timeout($promise, 100);
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$callback = function ($exception, $value) use (&$result) {
|
||||
@ -78,7 +77,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
|
||||
Loop::run(function () use (&$reason) {
|
||||
$promise = new Pause(200);
|
||||
|
||||
$promise = Amp\timeout($promise, 100);
|
||||
$promise = Promise\timeout($promise, 100);
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$callback = function ($exception, $value) use (&$reason) {
|
||||
@ -88,7 +87,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
|
||||
$promise->when($callback);
|
||||
});
|
||||
|
||||
$this->assertInstanceOf(Amp\TimeoutException::class, $reason);
|
||||
$this->assertInstanceOf(\Amp\TimeoutException::class, $reason);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,7 +99,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$promise = resolve($value);
|
||||
|
||||
$promise = Amp\timeout($promise, 100);
|
||||
$promise = Promise\timeout($promise, 100);
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$callback = function ($exception, $value) use (&$result) {
|
||||
@ -114,7 +113,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
|
||||
}
|
||||
|
||||
public function testNonPromise() {
|
||||
$this->expectException(Amp\UnionTypeError::class);
|
||||
Amp\timeout(42, 42);
|
||||
$this->expectException(\Amp\UnionTypeError::class);
|
||||
Promise\timeout(42, 42);
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
namespace Amp\Test;
|
||||
|
||||
use Amp;
|
||||
use Amp\Deferred;
|
||||
use Amp\Failure;
|
||||
use Amp\Pause;
|
||||
use Amp\Promise;
|
||||
use Amp\Success;
|
||||
use Amp\Loop;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@ -17,7 +17,7 @@ class WaitTest extends TestCase {
|
||||
|
||||
$promise = new Success($value);
|
||||
|
||||
$result = Amp\wait($promise);
|
||||
$result = Promise\wait($promise);
|
||||
|
||||
$this->assertSame($value, $result);
|
||||
}
|
||||
@ -28,7 +28,7 @@ class WaitTest extends TestCase {
|
||||
$promise = new Failure($exception);
|
||||
|
||||
try {
|
||||
$result = Amp\wait($promise);
|
||||
$result = Promise\wait($promise);
|
||||
} catch (\Exception $e) {
|
||||
$this->assertSame($exception, $e);
|
||||
return;
|
||||
@ -46,7 +46,7 @@ class WaitTest extends TestCase {
|
||||
|
||||
$promise = new Pause(100, $value);
|
||||
|
||||
$result = Amp\wait($promise);
|
||||
$result = Promise\wait($promise);
|
||||
|
||||
$this->assertSame($value, $result);
|
||||
});
|
||||
@ -59,7 +59,7 @@ class WaitTest extends TestCase {
|
||||
public function testPromiseWithNoResolutionPathThrowsException() {
|
||||
$promise = new Deferred;
|
||||
|
||||
$result = Amp\wait($promise->promise());
|
||||
$result = Promise\wait($promise->promise());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,13 +70,13 @@ class WaitTest extends TestCase {
|
||||
|
||||
$promise = resolve($value);
|
||||
|
||||
$result = Amp\wait($promise);
|
||||
$result = Promise\wait($promise);
|
||||
|
||||
$this->assertSame($value, $result);
|
||||
}
|
||||
|
||||
public function testNonPromise() {
|
||||
$this->expectException(Amp\UnionTypeError::class);
|
||||
Amp\wait(42);
|
||||
$this->expectException(\Amp\UnionTypeError::class);
|
||||
Promise\wait(42);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user