-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExtensionTest.php
More file actions
47 lines (35 loc) · 1018 Bytes
/
ExtensionTest.php
File metadata and controls
47 lines (35 loc) · 1018 Bytes
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
42
43
44
45
46
47
<?php declare(strict_types=1);
namespace Versary\EffectSystem;
use PHPUnit\Framework\TestCase;
class ExtensionTest extends TestCase {
function my_gen() {
yield 1;
yield 2;
yield 3;
}
public function test_cloning() {
$gen = $this->my_gen();
$gen->next();
$this->assertEquals(2, $gen->current());
// call the function from my PHP extension
$new = clone_gen($gen);
$this->assertEquals(2, $new->current());
// advance the original generator
$gen->next();
// the original generator has advanced
$this->assertEquals(3, $gen->current());
// the new one hasn't
$this->assertEquals(2, $new->current());
$new->next();
$this->assertEquals(3, $gen->current());
$this->assertEquals(3, $new->current());
}
}
function empty_gen() {
if (false) yield 1;
}
function clone_gen($gen) {
$new = empty_gen();
clone_generator($gen, $new);
return $new;
}