Completed
Push — master ( f81350...043426 )
by mw
104:38 queued 69:33
created

DispatchingContentCreatorTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
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 $wikiImporter;
20
	private $messageReporter;
21
22
	protected function setUp() {
23
		parent::setUp();
24
25
		$importStreamSource = $this->getMockBuilder( '\ImportStreamSource' )
0 ignored issues
show
Unused Code introduced by
$importStreamSource is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
26
			->disableOriginalConstructor()
27
			->getMock();
28
29
		$this->wikiImporter = $this->getMockBuilder( '\WikiImporter' )
30
			->disableOriginalConstructor()
31
			->getMock();
32
33
		$this->messageReporter = $this->getMockBuilder( '\Onoi\MessageReporter\MessageReporter' )
34
			->disableOriginalConstructor()
35
			->getMock();
36
	}
37
38
	public function testCanConstruct() {
39
40
		$this->assertInstanceOf(
41
			'\SMW\Importer\ContentCreators\DispatchingContentCreator',
42
			new DispatchingContentCreator( array() )
43
		);
44
	}
45
46
	public function testCanCreateContentsFor() {
47
48
		$importContents = new ImportContents();
49
		$importContents->setContentType( 'Foo' );
50
51
		$contentCreator = $this->getMockBuilder( '\SMW\Importer\ContentCreator' )
52
			->disableOriginalConstructor()
53
			->getMock();
54
55
		$contentCreator->expects( $this->any() )
56
			->method( 'canCreateContentsFor' )
57
			->with( $this->equalTo( $importContents ) )
58
			->will( $this->returnValue( true ) );
59
60
		$instance = new DispatchingContentCreator(
61
			array(
62
				$contentCreator
63
			)
64
		);
65
66
		$this->assertTrue(
67
			$instance->canCreateContentsFor( $importContents )
68
		);
69
	}
70
71
	public function testDoCreateFrom() {
72
73
		$importContents = new ImportContents();
74
		$importContents->setContentType( 'Foo' );
75
76
		$contentCreator = $this->getMockBuilder( '\SMW\Importer\ContentCreator' )
77
			->disableOriginalConstructor()
78
			->getMock();
79
80
		$contentCreator->expects( $this->any() )
81
			->method( 'canCreateContentsFor' )
82
			->will( $this->returnValue( true ) );
83
84
		$contentCreator->expects( $this->any() )
85
			->method( 'doCreateFrom' )
86
			->with( $this->equalTo( $importContents ) )
87
			->will( $this->returnValue( true ) );
88
89
		$instance = new DispatchingContentCreator(
90
			array(
91
				$contentCreator
92
			)
93
		);
94
95
		$instance->setMessageReporter(
96
			$this->messageReporter
97
		);
98
99
		$this->assertTrue(
100
			$instance->doCreateFrom( $importContents )
101
		);
102
	}
103
104
	public function testDoCreateFromOnNonMatchableCreatorThrowsException() {
105
106
		$importContents = new ImportContents();
107
		$importContents->setContentType( 'Foo' );
108
109
		$contentCreator = $this->getMockBuilder( '\SMW\Importer\ContentCreator' )
110
			->disableOriginalConstructor()
111
			->getMock();
112
113
		$contentCreator->expects( $this->any() )
114
			->method( 'canCreateContentsFor' )
115
			->will( $this->returnValue( false ) );
116
117
		$contentCreator->expects( $this->never() )
118
			->method( 'doCreateFrom' );
119
120
		$instance = new DispatchingContentCreator(
121
			array(
122
				$contentCreator
123
			)
124
		);
125
126
		$this->setExpectedException( 'RuntimeException' );
127
		$instance->doCreateFrom( $importContents );
128
	}
129
130
}
131