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