1--TEST--
2Observer: Generator with manual traversal
3--EXTENSIONS--
4zend_test
5--INI--
6zend_test.observer.enabled=1
7zend_test.observer.show_output=1
8zend_test.observer.observe_all=1
9zend_test.observer.show_return_value=1
10--FILE--
11<?php
12function fooResults() {
13    echo 'Starting generator' . PHP_EOL;
14    $i = 0;
15    while (true) {
16        if (yield $i++) break;
17    }
18}
19
20function doSomething() {
21    $generator = fooResults();
22
23    while($generator->current() !== NULL) {
24        echo $generator->current() . PHP_EOL;
25        if ($generator->current() === 5) {
26            $generator->send('Boop');
27        }
28        $generator->next();
29    }
30
31    return 'Done';
32}
33
34echo doSomething() . PHP_EOL;
35?>
36--EXPECTF--
37<!-- init '%s' -->
38<file '%s'>
39  <!-- init doSomething() -->
40  <doSomething>
41    <!-- init Generator::current() -->
42    <Generator::current>
43      <!-- init fooResults() -->
44      <fooResults>
45Starting generator
46      </fooResults:0>
47    </Generator::current:0>
48    <Generator::current>
49    </Generator::current:0>
500
51    <Generator::current>
52    </Generator::current:0>
53    <!-- init Generator::next() -->
54    <Generator::next>
55      <fooResults>
56      </fooResults:1>
57    </Generator::next:NULL>
58    <Generator::current>
59    </Generator::current:1>
60    <Generator::current>
61    </Generator::current:1>
621
63    <Generator::current>
64    </Generator::current:1>
65    <Generator::next>
66      <fooResults>
67      </fooResults:2>
68    </Generator::next:NULL>
69    <Generator::current>
70    </Generator::current:2>
71    <Generator::current>
72    </Generator::current:2>
732
74    <Generator::current>
75    </Generator::current:2>
76    <Generator::next>
77      <fooResults>
78      </fooResults:3>
79    </Generator::next:NULL>
80    <Generator::current>
81    </Generator::current:3>
82    <Generator::current>
83    </Generator::current:3>
843
85    <Generator::current>
86    </Generator::current:3>
87    <Generator::next>
88      <fooResults>
89      </fooResults:4>
90    </Generator::next:NULL>
91    <Generator::current>
92    </Generator::current:4>
93    <Generator::current>
94    </Generator::current:4>
954
96    <Generator::current>
97    </Generator::current:4>
98    <Generator::next>
99      <fooResults>
100      </fooResults:5>
101    </Generator::next:NULL>
102    <Generator::current>
103    </Generator::current:5>
104    <Generator::current>
105    </Generator::current:5>
1065
107    <Generator::current>
108    </Generator::current:5>
109    <!-- init Generator::send() -->
110    <Generator::send>
111      <fooResults>
112      </fooResults:NULL>
113    </Generator::send:NULL>
114    <Generator::next>
115    </Generator::next:NULL>
116    <Generator::current>
117    </Generator::current:NULL>
118  </doSomething:'Done'>
119Done
120</file '%s'>
121