2018-10-05 21:06:27 +02:00
|
|
|
<?php
|
|
|
|
|
2020-05-13 17:15:21 +02:00
|
|
|
namespace Amp\Test\Iterator;
|
2018-10-05 21:06:27 +02:00
|
|
|
|
|
|
|
use Amp\Iterator;
|
2020-05-13 17:15:21 +02:00
|
|
|
use Amp\Test\BaseTest;
|
2018-10-05 21:06:27 +02:00
|
|
|
use function Amp\Promise\wait;
|
|
|
|
|
2020-05-13 17:15:21 +02:00
|
|
|
class ToArrayTest extends BaseTest
|
2018-10-05 21:06:27 +02:00
|
|
|
{
|
2018-11-25 16:58:42 +01:00
|
|
|
public function testNonEmpty()
|
2018-10-05 21:06:27 +02:00
|
|
|
{
|
|
|
|
$iterator = Iterator\fromIterable(["abc", "foo", "bar"], 5);
|
2018-11-25 16:58:42 +01:00
|
|
|
$this->assertSame(["abc", "foo", "bar"], wait(Iterator\toArray($iterator)));
|
2018-10-05 21:06:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testEmpty()
|
|
|
|
{
|
|
|
|
$iterator = Iterator\fromIterable([], 5);
|
2018-11-25 16:58:42 +01:00
|
|
|
$this->assertSame([], wait(Iterator\toArray($iterator)));
|
2018-10-05 21:06:27 +02:00
|
|
|
}
|
|
|
|
}
|