testMaxArgumentIsRespected()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Tests\Queryr\Replicator\Importer\Console;
4
5
use PHPUnit\Framework\TestCase;
6
use Queryr\Replicator\Cli\Command\GzJsonImportCommand;
7
use Symfony\Component\Console\Tester\CommandTester;
8
use Tests\Queryr\Replicator\Integration\TestEnvironment;
9
10
/**
11
 * @covers \Queryr\Replicator\Cli\Command\GzJsonImportCommand
12
 *
13
 * @licence GNU GPL v2+
14
 * @author Jeroen De Dauw < [email protected] >
15
 */
16
class GzJsonImportCommandTest extends TestCase {
17
18
	public function testEntityIdInOutput() {
19
		$output = $this->getOutputForArgs( [
20
			'file' => 'tests/data/simple/five-entities.json.gz'
21
		] );
22
23
		$this->assertContains( 'Q1', $output );
24
		$this->assertContains( 'Q8', $output );
25
		$this->assertContains( 'P16', $output );
26
		$this->assertContains( 'P19', $output );
27
		$this->assertContains( 'P22', $output );
28
29
		$this->assertContains( 'Entity imported', $output );
30
	}
31
32
	private function getOutputForArgs( array $args ) {
33
		$commandTester = $this->newCommandTester();
34
35
		$commandTester->execute( $args );
36
37
		return $commandTester->getDisplay();
38
	}
39
40
	private function newCommandTester() {
41
		$command = new GzJsonImportCommand();
42
		$command->setServiceFactory( TestEnvironment::newInstance()->getFactory() );
43
44
		return new CommandTester( $command );
45
	}
46
47
	public function testMaxArgumentIsRespected() {
48
		$output = $this->getOutputForArgs( [
49
			'file' => 'tests/data/simple/five-entities.json.gz',
50
			'--max' => '3'
51
		] );
52
53
		$this->assertContains( 'Q1', $output );
54
		$this->assertContains( 'Q8', $output );
55
		$this->assertContains( 'P16', $output );
56
		$this->assertNotContains( 'P19', $output );
57
		$this->assertNotContains( 'P22', $output );
58
	}
59
60
	public function testWhenUsingMaxContinueParamIsOutput() {
61
		$output = $this->getOutputForArgs( [
62
			'file' => 'tests/data/simple/five-entities.json.gz',
63
			'--max' => '3'
64
		] );
65
66
		$this->assertContains( '--continue', $output );
67
	}
68
69
	public function testGzCommandContinuation() {
70
		$output = $this->getOutputForArgs( [
71
			'file' => 'tests/data/simple/five-entities.json.gz',
72
			'--continue' => '66668'
73
		] );
74
75
		$this->assertNotContains( 'Q1', $output );
76
		$this->assertNotContains( 'Q8', $output );
77
		$this->assertContains( 'P16', $output );
78
		$this->assertContains( 'P19', $output );
79
		$this->assertContains( 'P22', $output );
80
	}
81
82
}