Skip to content

Commit

Permalink
add test for AsyncLoopBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
sj-i committed Sep 23, 2021
1 parent 22c7bb0 commit c8d0625
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/Lib/Loop/AsyncLoopBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* This file is part of the sj-i/php-profiler package.
*
* (c) sji <sji@sj-i.dev>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace PhpProfiler\Lib\Loop;

use PhpProfiler\Lib\Loop\AsyncLoopMiddleware\CallableMiddlewareAsync;
use PHPUnit\Framework\TestCase;

class AsyncLoopBuilderTest extends TestCase
{
public function testBuild(): void
{
$builder = new AsyncLoopBuilder();
$new_builder = $builder->addProcess(CallableMiddlewareAsync::class, [
function () {
yield 1;
yield 2;
yield 3;
}
]);
$loop = $new_builder->build();
$result = $loop->invoke();
$this->assertSame(1, $result->current());
$result->next();
$this->assertSame(2, $result->current());
$result->next();
$this->assertSame(3, $result->current());
$result->next();
$this->assertSame(1, $result->current());
$result->next();
$this->assertSame(2, $result->current());
$result->next();
$this->assertSame(3, $result->current());

$this->assertNotSame($builder, $new_builder);
}
}

0 comments on commit c8d0625

Please sign in to comment.