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