Completed
Push — master ( 7830fd...6b6dd7 )
by Jeroen De
07:58 queued 23s
created

LameLoggerPluginTest.php$0 ➔ getHandlingMessage()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
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
		$this->markTestSkipped( 'Plugin system incomplete' ); // TODO
19
20
		global $replicatorEntityHandlers;
21
22
		$replicatorEntityHandlers[] = function() {
23
			return [
24
				'input-options' => [],
25
				'is-enabled-function' => function() {
26
					return true;
27
				},
28
				'handler-builder-function' => function() {
29
					return new class() implements EntityHandlerPlugin {
30
						private $filePath;
31
32
						public function __construct() {
33
							$this->filePath = '/tmp/LameLogging.txt';
34
						}
35
36
						public function handleEntity( EntityDocument $entity ) {
37
							file_put_contents(
38
								$this->filePath,
39
								$entity->getId()->getSerialization() . "\n",
40
								FILE_APPEND
41
							);
42
						}
43
44
						public function getHandlingMessage( EntityDocument $entity ): string {
45
							return 'Doing some lame logging';
46
						}
47
					};
48
				}
49
			];
50
		};
51
	}
52
53
	public function testEntityIdInOutput() {
54
		$output = $this->getOutputForArgs( [
55
			'file' => 'tests/data/simple/five-entities.json.gz'
56
		] );
57
58
		$this->assertContains( 'Q1', $output );
59
		$this->assertContains( 'Q8', $output );
60
		$this->assertContains( 'P16', $output );
61
		$this->assertContains( 'P19', $output );
62
		$this->assertContains( 'P22', $output );
63
64
		$this->assertContains( 'Doing some lame logging', $output );
65
66
		$this->assertContains( 'Entity imported', $output );
67
	}
68
69
	private function getOutputForArgs( array $args ) {
70
		$commandTester = $this->newCommandTester();
71
72
		$commandTester->execute( $args );
73
74
		return $commandTester->getDisplay();
75
	}
76
77
	private function newCommandTester() {
78
		$command = new GzJsonImportCommand();
79
		$command->setServiceFactory( TestEnvironment::newInstance()->getFactory() );
80
81
		return new CommandTester( $command );
82
	}
83
84
}
85