Completed
Push — master ( f1a924...85530c )
by mw
07:12
created

testRecursiveIteration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
3
namespace SMW\Notifications\Iterators\Tests;
4
5
use SMW\Notifications\Iterators\ChildlessRecursiveIterator;
6
use RecursiveIteratorIterator;
7
8
/**
9
 * @covers \SMW\Notifications\Iterators\ChildlessRecursiveIterator
10
 * @group semantic-notifications
11
 *
12
 * @license GNU GPL v2+
13
 * @since 1.0
14
 *
15
 * @author mwjames
16
 */
17
class ChildlessRecursiveIteratorTest extends \PHPUnit_Framework_TestCase {
18
19
	public function testCanConstruct() {
20
21
		$this->assertInstanceOf(
22
			ChildlessRecursiveIterator::class,
23
			new ChildlessRecursiveIterator( array() )
24
		);
25
	}
26
27
	public function testInvalidIteratorThrowsException() {
28
29
		$this->setExpectedException( 'RuntimeException' );
30
		$instance = new ChildlessRecursiveIterator( 2 );
0 ignored issues
show
Unused Code introduced by
$instance is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
31
	}
32
33
	public function testStandardaIteration() {
34
35
		$instance = new ChildlessRecursiveIterator( array( 'Foo' ) );
36
37
		foreach ( $instance as $value ) {
38
			$this->assertSame(
39
				'Foo',
40
				$value
41
			);
42
		}
43
	}
44
45
	public function testRecursiveIteration() {
46
47
		$instance = new RecursiveIteratorIterator(
48
			new ChildlessRecursiveIterator( array( 'Foo' ) )
49
		);
50
51
		foreach ( $instance as $value ) {
52
			$this->assertSame(
53
				'Foo',
54
				$value
55
			);
56
		}
57
	}
58
59
}
60