1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace Wikibase\JsonDumpReader\Tests\Integration; |
6
|
|
|
|
7
|
|
|
use JsonDumpData; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Wikibase\JsonDumpReader\JsonDumpFactory; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @covers \Wikibase\JsonDumpReader\JsonDumpFactory |
13
|
|
|
* |
14
|
|
|
* @licence GNU GPL v2+ |
15
|
|
|
* @author Jeroen De Dauw < [email protected] > |
16
|
|
|
*/ |
17
|
|
|
class JsonDumpFactoryTest extends TestCase { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var JsonDumpFactory |
21
|
|
|
*/ |
22
|
|
|
private $factory; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var JsonDumpData |
26
|
|
|
*/ |
27
|
|
|
private $dumpData; |
28
|
|
|
|
29
|
|
|
public function setUp() { |
30
|
|
|
$this->factory = new JsonDumpFactory(); |
31
|
|
|
$this->dumpData = new JsonDumpData(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testGzDumpReaderCanReadGzFile() { |
35
|
|
|
$reader = $this->factory->newGzDumpReader( $this->dumpData->getFiveEntitiesGzDumpPath() ); |
36
|
|
|
|
37
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
38
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
39
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
40
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
41
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
42
|
|
|
$this->assertNull( $reader->nextJsonLine() ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testBz2DumpReaderCanReadBz2File() { |
46
|
|
|
if ( !function_exists( 'bzopen' ) ) { |
47
|
|
|
self::markTestSkipped( 'bz2 is not installed' ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$reader = $this->factory->newBz2DumpReader( $this->dumpData->getFiveEntitiesBz2DumpPath() ); |
51
|
|
|
|
52
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
53
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
54
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
55
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
56
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
57
|
|
|
$this->assertNull( $reader->nextJsonLine() ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testExtractedDumpReaderCanReadJsonFile() { |
61
|
|
|
$reader = $this->factory->newExtractedDumpReader( $this->dumpData->getFiveEntitiesDumpPath() ); |
62
|
|
|
|
63
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
64
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
65
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
66
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
67
|
|
|
$this->assertJson( $reader->nextJsonLine() ); |
68
|
|
|
$this->assertNull( $reader->nextJsonLine() ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testStringDumpIteratorWithGzReader() { |
72
|
|
|
$iterator = $this->factory->newStringDumpIterator( |
73
|
|
|
$this->factory->newGzDumpReader( $this->dumpData->getFiveEntitiesGzDumpPath() ) |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$this->assertContainsOnly( 'string', $iterator ); |
77
|
|
|
$this->assertCount( 5, $iterator ); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testObjectDumpIteratorWithBz2Reader() { |
81
|
|
|
if ( !function_exists( 'bzopen' ) ) { |
82
|
|
|
self::markTestSkipped( 'bz2 is not installed' ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$iterator = $this->factory->newObjectDumpIterator( |
86
|
|
|
$this->factory->newBz2DumpReader( $this->dumpData->getFiveEntitiesBz2DumpPath() ) |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
foreach ( $iterator as $json ) { |
90
|
|
|
$this->assertInternalType( 'array', $json ); |
91
|
|
|
$this->assertArrayHasKey( 'id', $json ); |
92
|
|
|
} |
93
|
|
|
$this->assertCount( 5, $iterator ); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testGzReaderInitialPosition() { |
97
|
|
|
$reader = $this->factory->newGzDumpReader( $this->dumpData->getFiveEntitiesGzDumpPath() ); |
98
|
|
|
|
99
|
|
|
$reader->nextJsonLine(); |
100
|
|
|
$reader->nextJsonLine(); |
101
|
|
|
$reader->nextJsonLine(); |
102
|
|
|
|
103
|
|
|
$newReader = $this->factory->newGzDumpReader( |
104
|
|
|
$this->dumpData->getFiveEntitiesGzDumpPath(), |
105
|
|
|
$reader->getPosition() |
106
|
|
|
); |
107
|
|
|
|
108
|
|
|
$this->assertJson( $newReader->nextJsonLine() ); |
109
|
|
|
$this->assertJson( $newReader->nextJsonLine() ); |
110
|
|
|
$this->assertNull( $newReader->nextJsonLine() ); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: