Completed
Push — master ( d01339...b9998b )
by Jeroen De
02:51
created

Bz2JsonImportCommandTest::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.4286
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
3
namespace Tests\Queryr\Replicator\Importer\Console;
4
5
use Queryr\Replicator\Cli\Command\Bz2JsonImportCommand;
6
use Symfony\Component\Console\Tester\CommandTester;
7
use Tests\Queryr\Replicator\Integration\TestEnvironment;
8
9
/**
10
 * @covers Queryr\Replicator\Cli\Command\Bz2JsonImportCommand
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class Bz2JsonImportCommandTest extends \PHPUnit_Framework_TestCase {
16
17
	public function setUp() {
18
		if ( !function_exists( 'bzopen' ) ) {
19
			$this->markTestSkipped( 'bzip2 library not installed' );
20
		}
21
	}
22
23
	public function testEntityIdInOutput() {
24
		$output = $this->getOutputForArgs( [
25
			'file' => 'tests/data/simple/five-entities.json.bz2'
26
		] );
27
28
		$this->assertContains( 'Q1', $output );
29
		$this->assertContains( 'Q8', $output );
30
		$this->assertContains( 'P16', $output );
31
		$this->assertContains( 'P19', $output );
32
		$this->assertContains( 'P22', $output );
33
34
		$this->assertContains( 'Entity imported', $output );
35
	}
36
37
	private function getOutputForArgs( array $args ) {
38
		$commandTester = $this->newCommandTester();
39
40
		$commandTester->execute( $args );
41
42
		return $commandTester->getDisplay();
43
	}
44
45
	private function newCommandTester() {
46
		$command = new Bz2JsonImportCommand();
47
		$command->setServiceFactory( TestEnvironment::newInstance()->getFactory() );
48
49
		return new CommandTester( $command );
50
	}
51
52
	public function testMaxArgumentIsRespected() {
53
		$output = $this->getOutputForArgs( [
54
			'file' => 'tests/data/simple/five-entities.json.bz2',
55
			'--max' => '3'
56
		] );
57
58
		$this->assertContains( 'Q1', $output );
59
		$this->assertContains( 'Q8', $output );
60
		$this->assertContains( 'P16', $output );
61
		$this->assertNotContains( 'P19', $output );
62
		$this->assertNotContains( 'P22', $output );
63
	}
64
65
}