testInvalidIteratorThrowsException()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SMW\Notifications\Iterators\Tests;
4
5
use SMW\Notifications\Iterators\ChildlessRecursiveIterator;
6
use RecursiveIteratorIterator;
7
use SMW\Tests\PHPUnitCompat;
8
9
/**
10
 * @covers \SMW\Notifications\Iterators\ChildlessRecursiveIterator
11
 * @group semantic-notifications
12
 *
13
 * @license GNU GPL v2+
14
 * @since 1.0
15
 *
16
 * @author mwjames
17
 */
18
class ChildlessRecursiveIteratorTest extends \PHPUnit_Framework_TestCase {
19
20
	use PHPUnitCompat;
21
22
	public function testCanConstruct() {
23
24
		$this->assertInstanceOf(
25
			ChildlessRecursiveIterator::class,
26
			new ChildlessRecursiveIterator( array() )
27
		);
28
	}
29
30
	public function testInvalidIteratorThrowsException() {
31
32
		$this->setExpectedException( 'RuntimeException' );
33
		$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...
34
	}
35
36
	public function testStandardaIteration() {
37
38
		$instance = new ChildlessRecursiveIterator( array( 'Foo' ) );
39
40
		foreach ( $instance as $value ) {
41
			$this->assertSame(
42
				'Foo',
43
				$value
44
			);
45
		}
46
	}
47
48
	public function testRecursiveIteration() {
49
50
		$instance = new RecursiveIteratorIterator(
51
			new ChildlessRecursiveIterator( array( 'Foo' ) )
52
		);
53
54
		foreach ( $instance as $value ) {
55
			$this->assertSame(
56
				'Foo',
57
				$value
58
			);
59
		}
60
	}
61
62
}
63