1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Wikibase\JsonDumpReader\Reader; |
4
|
|
|
|
5
|
|
|
use Wikibase\JsonDumpReader\Reader\Bz2DumpReader; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers Wikibase\JsonDumpReader\Reader\Bz2DumpReader |
9
|
|
|
* |
10
|
|
|
* @licence GNU GPL v2+ |
11
|
|
|
* @author Jeroen De Dauw < [email protected] > |
12
|
|
|
*/ |
13
|
|
|
class Bz2DumpReaderTest extends \PHPUnit_Framework_TestCase { |
14
|
|
|
|
15
|
|
|
public function setUp() { |
16
|
|
|
if ( !function_exists( 'bzopen' ) ) { |
17
|
|
|
self::markTestSkipped( 'bz2 is not installed' ); |
18
|
|
|
} |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
private function assertFindsEntity( Bz2DumpReader $reader, $expectedId ) { |
22
|
|
|
$line = $reader->nextJsonLine(); |
23
|
|
|
$this->assertJson( $line ); |
24
|
|
|
$this->assertContains( $expectedId, $line ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testGivenInvalidPath_exceptionIsThrown() { |
28
|
|
|
$this->setExpectedException( 'RuntimeException' ); |
|
|
|
|
29
|
|
|
$reader = new Bz2DumpReader( __DIR__ . '/../../data/does-not-exist.json.bz2' ); |
30
|
|
|
$reader->nextJsonLine(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testGivenFileWithNoEntities_nullIsReturned() { |
34
|
|
|
$reader = new Bz2DumpReader( ( new \JsonDumpData() )->getEmptyBz2DumpPath() ); |
35
|
|
|
|
36
|
|
|
$this->assertNull( $reader->nextJsonLine() ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testGivenFileWithFiveEntities_fiveEntityAreFound() { |
40
|
|
|
$reader = new Bz2DumpReader( ( new \JsonDumpData() )->getFiveEntitiesBz2DumpPath() ); |
41
|
|
|
|
42
|
|
|
$this->assertFindsEntity( $reader, 'Q1' ); |
43
|
|
|
$this->assertFindsEntity( $reader, 'Q8' ); |
44
|
|
|
$this->assertFindsEntity( $reader, 'P16' ); |
45
|
|
|
$this->assertFindsEntity( $reader, 'P19' ); |
46
|
|
|
$this->assertFindsEntity( $reader, 'P22' ); |
47
|
|
|
$this->assertNull( $reader->nextJsonLine() ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testRewind() { |
51
|
|
|
$reader = new Bz2DumpReader( ( new \JsonDumpData() )->getFiveEntitiesBz2DumpPath() ); |
52
|
|
|
|
53
|
|
|
$this->assertFindsEntity( $reader, 'Q1' ); |
54
|
|
|
$this->assertFindsEntity( $reader, 'Q8' ); |
55
|
|
|
$reader->rewind(); |
56
|
|
|
$this->assertFindsEntity( $reader, 'Q1' ); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
} |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.