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

Bz2JsonImportCommandTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 4
dl 0
loc 51
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 2
A testEntityIdInOutput() 0 13 1
A getOutputForArgs() 0 7 1
A newCommandTester() 0 6 1
A testMaxArgumentIsRespected() 0 12 1
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
}