| Total Complexity | 5 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 13 | class FactoryResultTest extends ResultTest |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @test |
||
| 17 | */ |
||
| 18 | public function it_uses_factory_callback_to_create_result(): void |
||
| 19 | { |
||
| 20 | $result = new FactoryResult([$this, 'factory'], new ArrayResult(\range(0, 30))); |
||
| 21 | $results = \iterator_to_array($result); |
||
| 22 | $this->assertSame('factory 0', $results[0]); |
||
| 23 | |||
| 24 | $results = \iterator_to_array($result->take(10, 10)); |
||
| 25 | $this->assertSame('factory 10', $results[0]); |
||
| 26 | } |
||
| 27 | |||
| 28 | public function factory($result): string |
||
| 29 | { |
||
| 30 | return 'factory '.$result; |
||
| 31 | } |
||
| 32 | |||
| 33 | protected function createResultWithItems(int $count): Result |
||
| 34 | { |
||
| 35 | $array = []; |
||
| 36 | |||
| 37 | for ($i = 1; $i <= $count; ++$i) { |
||
| 38 | $array[] = 'value '.$i; |
||
| 39 | } |
||
| 40 | |||
| 41 | return new FactoryResult([$this, 'factory'], new ArrayResult($array)); |
||
| 42 | } |
||
| 43 | |||
| 44 | protected function getExpectedValueAtPosition(int $position) |
||
| 47 | } |
||
| 48 | } |
||
| 49 |