testMaxArgumentIsRespected()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
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\JsonDumpImportCommand;
7
use Symfony\Component\Console\Tester\CommandTester;
8
use Tests\Queryr\Replicator\Integration\TestEnvironment;
9
10
/**
11
 * @covers \Queryr\Replicator\Cli\Command\JsonDumpImportCommand
12
 *
13
 * @licence GNU GPL v2+
14
 * @author Jeroen De Dauw < [email protected] >
15
 */
16
class JsonDumpImportCommandTest extends TestCase {
17
18
	public function testEntityIdInOutput() {
19
		$output = $this->getOutputForArgs( [
20
			'file' => 'tests/data/simple/five-entities.json'
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 JsonDumpImportCommand();
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',
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
		$this->assertContains( '--continue', $output );
60
	}
61
62
	public function testContinuation() {
63
		$output = $this->getOutputForArgs( [
64
			'file' => 'tests/data/simple/five-entities.json',
65
			'--continue' => '66943'
66
		] );
67
68
		$this->assertNotContains( 'Q1', $output );
69
		$this->assertNotContains( 'Q8', $output );
70
		$this->assertNotContains( 'P16', $output );
71
		$this->assertContains( 'P19', $output );
72
		$this->assertContains( 'P22', $output );
73
	}
74
75
}