1415869a4f1e92a005d000c32cb71fd523e7027a
[yaffs-website] / vendor / symfony / dependency-injection / Tests / Argument / RewindableGeneratorTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\DependencyInjection\Tests\Argument;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
16
17 class RewindableGeneratorTest extends TestCase
18 {
19     public function testImplementsCountable()
20     {
21         $this->assertInstanceOf(\Countable::class, new RewindableGenerator(function () {
22             yield 1;
23         }, 1));
24     }
25
26     public function testCountUsesProvidedValue()
27     {
28         $generator = new RewindableGenerator(function () {
29             yield 1;
30         }, 3);
31
32         $this->assertCount(3, $generator);
33     }
34
35     public function testCountUsesProvidedValueAsCallback()
36     {
37         $called = 0;
38         $generator = new RewindableGenerator(function () {
39             yield 1;
40         }, function () use (&$called) {
41             ++$called;
42
43             return 3;
44         });
45
46         $this->assertSame(0, $called, 'Count callback is called lazily');
47         $this->assertCount(3, $generator);
48
49         count($generator);
50
51         $this->assertSame(1, $called, 'Count callback is called only once');
52     }
53 }