blob: bd56e345598d94243102ff4f08631a1b409523a2 (
plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
<?php
namespace SMW\Tests\Iterators;
use SMW\Iterators\ResultIterator;
use SMW\Tests\PHPUnitCompat;
/**
* @covers \SMW\Iterators\ResultIterator
* @group semantic-mediawiki
*
* @license GNU GPL v2+
* @since 2.5
*
* @author mwjames
*/
class ResultIteratorTest extends \PHPUnit_Framework_TestCase {
use PHPUnitCompat;
public function testCanConstruct() {
$this->assertInstanceOf(
ResultIterator::class,
new ResultIterator( [] )
);
}
public function testInvalidConstructorArgumentThrowsException() {
$this->setExpectedException( 'RuntimeException' );
$instance = new ResultIterator( 2 );
}
public function testdoIterateOnArray() {
$result = [
1, 42
];
$instance = new ResultIterator( $result );
$this->assertCount(
2,
$instance
);
foreach ( $instance as $key => $value ) {
$this->assertEquals(
$result[$key],
$value
);
}
}
public function testdoSeekOnArray() {
$result = [
1, 42, 1001
];
$instance = new ResultIterator( $result );
$instance->seek( 1 );
$this->assertEquals(
42,
$instance->current()
);
}
public function testdoIterateOnResultWrapper() {
$resultWrapper = $this->getMockBuilder( '\ResultWrapper' )
->disableOriginalConstructor()
->getMock();
$resultWrapper->expects( $this->once() )
->method( 'numRows' )
->will( $this->returnValue( 1 ) );
$resultWrapper->expects( $this->atLeastOnce() )
->method( 'current' )
->will( $this->returnValue( 42 ) );
$instance = new ResultIterator( $resultWrapper );
$this->assertCount(
1,
$instance
);
foreach ( $instance as $key => $value ) {
$this->assertEquals(
42,
$value
);
}
}
}
|