1
0
mirror of https://github.com/danog/amp.git synced 2024-12-11 17:09:40 +01:00
amp/test/AllTest.php
Aaron Piotrowski 7612ef3f1e
Drop direct conversion of React promises
React promises are still supported using Amp\Promise\adapt().
2020-10-30 10:19:12 -05:00

56 lines
1.2 KiB
PHP

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