Completed
Push — master ( 28ce47...c81113 )
by Jeroen De
03:24 queued 53s
created

Bz2DumpReaderTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

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
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' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

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.

Loading history...
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
}