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

Bz2DumpReaderTest::setUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
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
}