1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Queryr\Replicator\Integration\Importer; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Queryr\Replicator\Cli\Command\GzJsonImportCommand; |
7
|
|
|
use Queryr\Replicator\Plugin\EntityHandlerPlugin; |
8
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
9
|
|
|
use Tests\Queryr\Replicator\Integration\TestEnvironment; |
10
|
|
|
use Wikibase\DataModel\Entity\EntityDocument; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @licence GNU GPL v2+ |
14
|
|
|
* @author Jeroen De Dauw < [email protected] > |
15
|
|
|
*/ |
16
|
|
|
class LameLoggerPluginTest extends TestCase { |
17
|
|
|
|
18
|
|
|
public function setUp() { |
19
|
|
|
$this->markTestSkipped( 'Plugin system incomplete' ); // TODO |
20
|
|
|
|
21
|
|
|
global $replicatorEntityHandlers; |
22
|
|
|
|
23
|
|
|
$replicatorEntityHandlers[] = function() { |
24
|
|
|
return [ |
25
|
|
|
'input-options' => [], |
26
|
|
|
'is-enabled-function' => function() { |
27
|
|
|
return true; |
28
|
|
|
}, |
29
|
|
|
'handler-builder-function' => function() { |
30
|
|
|
return new class() implements EntityHandlerPlugin { |
31
|
|
|
private $filePath; |
32
|
|
|
|
33
|
|
|
public function __construct() { |
34
|
|
|
$this->filePath = '/tmp/LameLogging.txt'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function handleEntity( EntityDocument $entity ) { |
38
|
|
|
file_put_contents( |
39
|
|
|
$this->filePath, |
40
|
|
|
$entity->getId()->getSerialization() . "\n", |
41
|
|
|
FILE_APPEND |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getHandlingMessage( EntityDocument $entity ): string { |
46
|
|
|
return 'Doing some lame logging'; |
47
|
|
|
} |
48
|
|
|
}; |
49
|
|
|
} |
50
|
|
|
]; |
51
|
|
|
}; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testEntityIdInOutput() { |
55
|
|
|
$output = $this->getOutputForArgs( [ |
56
|
|
|
'file' => 'tests/data/simple/five-entities.json.gz' |
57
|
|
|
] ); |
58
|
|
|
|
59
|
|
|
$this->assertContains( 'Q1', $output ); |
60
|
|
|
$this->assertContains( 'Q8', $output ); |
61
|
|
|
$this->assertContains( 'P16', $output ); |
62
|
|
|
$this->assertContains( 'P19', $output ); |
63
|
|
|
$this->assertContains( 'P22', $output ); |
64
|
|
|
|
65
|
|
|
$this->assertContains( 'Doing some lame logging', $output ); |
66
|
|
|
|
67
|
|
|
$this->assertContains( 'Entity imported', $output ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
private function getOutputForArgs( array $args ) { |
71
|
|
|
$commandTester = $this->newCommandTester(); |
72
|
|
|
|
73
|
|
|
$commandTester->execute( $args ); |
74
|
|
|
|
75
|
|
|
return $commandTester->getDisplay(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
private function newCommandTester() { |
79
|
|
|
$command = new GzJsonImportCommand(); |
80
|
|
|
$command->setServiceFactory( TestEnvironment::newInstance()->getFactory() ); |
81
|
|
|
|
82
|
|
|
return new CommandTester( $command ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|