1
0
mirror of https://github.com/danog/amp.git synced 2024-12-03 09:57:51 +01:00
amp/test/AllTest.php
Niklas Keller 2f778fe069 Use revolt
Removes deprecated APIs.
2021-03-26 22:34:32 +01:00

56 lines
1.2 KiB
PHP

<?php
namespace Amp\Test;
use Amp\PHPUnit\AsyncTestCase;
use Amp\Promise;
use Amp\Success;
use function Amp\asyncValue;
use function Amp\await;
class AllTest extends AsyncTestCase
{
public function testEmptyArray(): void
{
self::assertSame([], await(Promise\all([])));
}
public function testSuccessfulPromisesArray(): void
{
$promises = [new Success(1), new Success(2), new Success(3)];
self::assertSame([1, 2, 3], await(Promise\all($promises)));
}
public function testPendingPromiseArray(): void
{
$promises = [
asyncValue(20, 1),
asyncValue(30, 2),
asyncValue(10, 3),
];
self::assertSame([1, 2, 3], await(Promise\all($promises)));
}
public function testArrayKeysPreserved(): void
{
$expected = ['one' => 1, 'two' => 2, 'three' => 3];
$promises = [
'one' => asyncValue(20, 1),
'two' => asyncValue(30, 2),
'three' => asyncValue(10, 3),
];
self::assertEquals($expected, await(Promise\all($promises)));
}
public function testNonPromise(): void
{
$this->expectException(\TypeError::class);
Promise\all([1]);
}
}