Completed
Push — master ( 813ff2...07dd29 )
by mw
377:22 queued 342:34
created

DispatchingContentCreatorTest::testDoCreateFrom()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
c 0
b 0
f 0
cc 1
eloc 20
nc 1
nop 0
rs 8.8571
1
<?php
2
3
namespace SMW\TestsImporter\ContentCreators;
4
5
use SMW\Importer\ContentCreators\DispatchingContentCreator;
6
use SMW\Importer\ImportContents;
7
8
/**
9
 * @covers \SMW\Importer\ContentCreators\DispatchingContentCreator
10
 * @group semantic-mediawiki
11
 *
12
 * @license GNU GPL v2+
13
 * @since 2.5
14
 *
15
 * @author mwjames
16
 */
17
class DispatchingContentCreatorTest extends \PHPUnit_Framework_TestCase {
18
19
	private $importServicesFactory;
20
	private $wikiImporter;
21
	private $messageReporter;
22
23
	protected function setUp() {
24
		parent::setUp();
25
26
		$importStreamSource = $this->getMockBuilder( '\ImportStreamSource' )
27
			->disableOriginalConstructor()
28
			->getMock();
29
30
		$this->wikiImporter = $this->getMockBuilder( '\WikiImporter' )
31
			->disableOriginalConstructor()
32
			->getMock();
33
34
		$this->importServicesFactory = $this->getMockBuilder( '\SMW\Services\ImportServicesFactory' )
35
			->disableOriginalConstructor()
36
			->getMock();
37
38
		$this->importServicesFactory->expects( $this->any() )
39
			->method( 'newImportStreamSource' )
40
			->will( $this->returnValue( $importStreamSource ) );
41
42
		$this->importServicesFactory->expects( $this->any() )
43
			->method( 'newWikiImporter' )
44
			->will( $this->returnValue( $this->wikiImporter ) );
45
46
		$this->messageReporter = $this->getMockBuilder( '\Onoi\MessageReporter\MessageReporter' )
47
			->disableOriginalConstructor()
48
			->getMock();
49
	}
50
51
	public function testCanConstruct() {
52
53
		$this->assertInstanceOf(
54
			'\SMW\Importer\ContentCreators\DispatchingContentCreator',
55
			new DispatchingContentCreator( array() )
56
		);
57
	}
58
59
	public function testCanCreateContentsFor() {
60
61
		$importContents = new ImportContents();
62
		$importContents->setContentType( 'Foo' );
63
64
		$contentCreator = $this->getMockBuilder( '\SMW\Importer\ContentCreator' )
65
			->disableOriginalConstructor()
66
			->getMock();
67
68
		$contentCreator->expects( $this->any() )
69
			->method( 'canCreateContentsFor' )
70
			->with( $this->equalTo( $importContents ) )
71
			->will( $this->returnValue( true ) );
72
73
		$instance = new DispatchingContentCreator(
74
			array(
75
				$contentCreator
76
			)
77
		);
78
79
		$this->assertTrue(
80
			$instance->canCreateContentsFor( $importContents )
81
		);
82
	}
83
84
	public function testDoCreateFrom() {
85
86
		$importContents = new ImportContents();
87
		$importContents->setContentType( 'Foo' );
88
89
		$contentCreator = $this->getMockBuilder( '\SMW\Importer\ContentCreator' )
90
			->disableOriginalConstructor()
91
			->getMock();
92
93
		$contentCreator->expects( $this->any() )
94
			->method( 'canCreateContentsFor' )
95
			->will( $this->returnValue( true ) );
96
97
		$contentCreator->expects( $this->any() )
98
			->method( 'doCreateFrom' )
99
			->with( $this->equalTo( $importContents ) )
100
			->will( $this->returnValue( true ) );
101
102
		$instance = new DispatchingContentCreator(
103
			array(
104
				$contentCreator
105
			)
106
		);
107
108
		$instance->setMessageReporter(
109
			$this->messageReporter
110
		);
111
112
		$this->assertTrue(
113
			$instance->doCreateFrom( $importContents )
114
		);
115
	}
116
117
	public function testDoCreateFromOnNonMatchableCreatorThrowsException() {
118
119
		$importContents = new ImportContents();
120
		$importContents->setContentType( 'Foo' );
121
122
		$contentCreator = $this->getMockBuilder( '\SMW\Importer\ContentCreator' )
123
			->disableOriginalConstructor()
124
			->getMock();
125
126
		$contentCreator->expects( $this->any() )
127
			->method( 'canCreateContentsFor' )
128
			->will( $this->returnValue( false ) );
129
130
		$contentCreator->expects( $this->never() )
131
			->method( 'doCreateFrom' );
132
133
		$instance = new DispatchingContentCreator(
134
			array(
135
				$contentCreator
136
			)
137
		);
138
139
		$this->setExpectedException( 'RuntimeException' );
140
		$instance->doCreateFrom( $importContents );
141
	}
142
143
}
144