Passed
Push — master ( 079aca...05e9ba )
by Jeroen De
04:40
created

Bz2DumpReaderTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 47
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 2
A assertFindsEntity() 0 5 1
A testGivenInvalidPath_exceptionIsThrown() 0 5 1
A testGivenFileWithNoEntities_nullIsReturned() 0 5 1
A testGivenFileWithFiveEntities_fiveEntityAreFound() 0 10 1
A testRewind() 0 8 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Wikibase\JsonDumpReader\Tests\Unit\Reader;
6
7
use PHPUnit\Framework\TestCase;
8
use Wikibase\JsonDumpReader\Reader\Bz2DumpReader;
9
10
/**
11
 * @covers \Wikibase\JsonDumpReader\Reader\Bz2DumpReader
12
 *
13
 * @licence GNU GPL v2+
14
 * @author Jeroen De Dauw < [email protected] >
15
 */
16
class Bz2DumpReaderTest extends TestCase {
17
18
	public function setUp() {
19
		if ( !function_exists( 'bzopen' ) ) {
20
			self::markTestSkipped( 'bz2 is not installed' );
21
		}
22
	}
23
24
	private function assertFindsEntity( Bz2DumpReader $reader, $expectedId ) {
25
		$line = $reader->nextJsonLine();
26
		$this->assertJson( $line );
27
		$this->assertContains( $expectedId, $line );
28
	}
29
30
	public function testGivenInvalidPath_exceptionIsThrown() {
31
		$this->expectException( 'RuntimeException' );
32
		$reader = new Bz2DumpReader( __DIR__ . '/../../data/does-not-exist.json.bz2' );
33
		$reader->nextJsonLine();
34
	}
35
36
	public function testGivenFileWithNoEntities_nullIsReturned() {
37
		$reader = new Bz2DumpReader( ( new \JsonDumpData() )->getEmptyBz2DumpPath() );
38
39
		$this->assertNull( $reader->nextJsonLine() );
40
	}
41
42
	public function testGivenFileWithFiveEntities_fiveEntityAreFound() {
43
		$reader = new Bz2DumpReader( ( new \JsonDumpData() )->getFiveEntitiesBz2DumpPath() );
44
45
		$this->assertFindsEntity( $reader, 'Q1' );
46
		$this->assertFindsEntity( $reader, 'Q8' );
47
		$this->assertFindsEntity( $reader, 'P16' );
48
		$this->assertFindsEntity( $reader, 'P19' );
49
		$this->assertFindsEntity( $reader, 'P22' );
50
		$this->assertNull( $reader->nextJsonLine() );
51
	}
52
53
	public function testRewind() {
54
		$reader = new Bz2DumpReader( ( new \JsonDumpData() )->getFiveEntitiesBz2DumpPath() );
55
56
		$this->assertFindsEntity( $reader, 'Q1' );
57
		$this->assertFindsEntity( $reader, 'Q8' );
58
		$reader->rewind();
59
		$this->assertFindsEntity( $reader, 'Q1' );
60
	}
61
62
}