GeneratorTest::testCannotUseAndRewind()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * @licence GNU GPL v2+
9
 * @author Jeroen De Dauw < [email protected] >
10
 */
11
class GeneratorTest extends TestCase {
12
13
	private function helloGenerator() {
14
		yield "hello";
15
		yield "world";
16
	}
17
18
	public function testCannotIterateTwice() {
19
		$generator = $this->helloGenerator();
20
21
		iterator_to_array( $generator );
22
23
		$this->expectException( 'Exception' );
24
		iterator_to_array( $generator ); // boom!
25
	}
26
27
	public function testCannotUseAndRewind() {
28
		if ( defined( 'HHVM_VERSION' ) ) {
29
			$this->markTestSkipped( 'Yay HHVM!' );
30
		}
31
32
		$generator = $this->helloGenerator();
33
34
		$generator->next();
35
36
		$this->expectException( 'Exception' );
37
		$generator->rewind(); // boom!
38
	}
39
40
}
41
42