-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8c5b32
commit d2f3df1
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Devlop\Buffer\Tests; | ||
|
||
use Devlop\Buffer\Buffer; | ||
use Generator; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class YieldTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function yield_method_should_return_generator() : void | ||
{ | ||
$this->assertInstanceOf( | ||
Generator::class, | ||
Buffer::yield([], 2, fn () => null), | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function yield_method_should_yield_each_input_value() : void | ||
{ | ||
$items = [ | ||
'value1', | ||
'value2', | ||
'value3', | ||
]; | ||
|
||
$callback = function ($items) : Generator { | ||
foreach ($items as $item) { | ||
yield $item; | ||
} | ||
}; | ||
|
||
$index = 0; | ||
|
||
$yieldedValues = 0; | ||
|
||
foreach (Buffer::yield($items, 2, $callback) as $item) { | ||
$this->assertEquals( | ||
$items[$index++], | ||
$item, | ||
); | ||
|
||
$yieldedValues++; | ||
} | ||
|
||
$this->assertGreaterThan(0, $yieldedValues, 'No values was yielded'); | ||
} | ||
} |