File: RewindableGeneratorTest.php

package info (click to toggle)
php-laravel-framework 8.83.26%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,444 kB
  • sloc: php: 167,609; sh: 162; makefile: 46
file content (41 lines) | stat: -rw-r--r-- 913 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

namespace Illuminate\Tests\Container;

use Illuminate\Container\RewindableGenerator;
use PHPUnit\Framework\TestCase;

class RewindableGeneratorTest extends TestCase
{
    public function testCountUsesProvidedValue()
    {
        $generator = new RewindableGenerator(function () {
            yield 'foo';
        }, 999);

        $this->assertCount(999, $generator);
    }

    public function testCountUsesProvidedValueAsCallback()
    {
        $called = 0;

        $generator = new RewindableGenerator(function () {
            yield 'foo';
        }, function () use (&$called) {
            $called++;

            return 500;
        });

        // the count callback is called lazily
        $this->assertSame(0, $called);

        $this->assertCount(500, $generator);

        count($generator);

        // the count callback is called only once
        $this->assertSame(1, $called);
    }
}