|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Wikibase\JsonDumpReader; |
|
4
|
|
|
|
|
5
|
|
|
use JsonDumpData; |
|
6
|
|
|
use Wikibase\JsonDumpReader\JsonDumpFactory; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @covers Wikibase\JsonDumpReader\JsonDumpFactory |
|
10
|
|
|
* |
|
11
|
|
|
* @licence GNU GPL v2+ |
|
12
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
13
|
|
|
*/ |
|
14
|
|
|
class JsonDumpFactoryTest extends \PHPUnit_Framework_TestCase { |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var JsonDumpFactory |
|
18
|
|
|
*/ |
|
19
|
|
|
private $factory; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var JsonDumpData |
|
23
|
|
|
*/ |
|
24
|
|
|
private $dumpData; |
|
25
|
|
|
|
|
26
|
|
|
public function setUp() { |
|
27
|
|
|
$this->factory = new JsonDumpFactory(); |
|
28
|
|
|
$this->dumpData = new JsonDumpData(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testGzDumpReaderCanReadGzFile() { |
|
32
|
|
|
$reader = $this->factory->newGzDumpReader( $this->dumpData->getFiveEntitiesGzDumpPath() ); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
|
35
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
|
36
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
|
37
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
|
38
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
|
39
|
|
|
$this->assertNull( $reader->nextJsonLine() ); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testBz2DumpReaderCanReadBz2File() { |
|
43
|
|
|
$reader = $this->factory->newBz2DumpReader( $this->dumpData->getFiveEntitiesBz2DumpPath() ); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
|
46
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
|
47
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
|
48
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
|
49
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
|
50
|
|
|
$this->assertNull( $reader->nextJsonLine() ); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testExtractedDumpReaderCanReadJsonFile() { |
|
54
|
|
|
$reader = $this->factory->newExtractedDumpReader( $this->dumpData->getFiveEntitiesDumpPath() ); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
|
57
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
|
58
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
|
59
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
|
60
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
|
61
|
|
|
$this->assertNull( $reader->nextJsonLine() ); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testStringDumpIteratorWithGzReader() { |
|
65
|
|
|
$iterator = $this->factory->newStringDumpIterator( |
|
66
|
|
|
$this->factory->newGzDumpReader( $this->dumpData->getFiveEntitiesGzDumpPath() ) |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertContainsOnly( 'string', $iterator ); |
|
70
|
|
|
$this->assertCount( 5, $iterator ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testObjectDumpIteratorWithBz2Reader() { |
|
74
|
|
|
$iterator = $this->factory->newObjectDumpIterator( |
|
75
|
|
|
$this->factory->newBz2DumpReader( $this->dumpData->getFiveEntitiesBz2DumpPath() ) |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
foreach ( $iterator as $json ) { |
|
79
|
|
|
$this->assertInternalType( 'array', $json ); |
|
80
|
|
|
$this->assertArrayHasKey( 'id', $json ); |
|
81
|
|
|
} |
|
82
|
|
|
$this->assertCount( 5, $iterator ); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function testGzReaderInitialPosition() { |
|
86
|
|
|
$reader = $this->factory->newGzDumpReader( $this->dumpData->getFiveEntitiesGzDumpPath() ); |
|
87
|
|
|
|
|
88
|
|
|
$reader->nextJsonLine(); |
|
89
|
|
|
$reader->nextJsonLine(); |
|
90
|
|
|
$reader->nextJsonLine(); |
|
91
|
|
|
|
|
92
|
|
|
$newReader = $this->factory->newGzDumpReader( |
|
93
|
|
|
$this->dumpData->getFiveEntitiesGzDumpPath(), |
|
94
|
|
|
$reader->getPosition() |
|
95
|
|
|
); |
|
96
|
|
|
|
|
97
|
|
|
$this->assertJson( $newReader->nextJsonLine() ); |
|
98
|
|
|
$this->assertJson( $newReader->nextJsonLine() ); |
|
99
|
|
|
$this->assertNull( $newReader->nextJsonLine() ); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
} |