ExtensionSchemaUpdaterTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 91
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanConstruct() 0 11 1
A testNoExtensionUpdateForInvalidDBType() 0 29 1
A testExtensionUpdateForValidDBType() 0 32 1
A dbTypeProvider() 0 9 1
1
<?php
2
3
namespace SWL\Tests\MediaWiki\Hooks;
4
5
use SWL\MediaWiki\Hooks\ExtensionSchemaUpdater;
6
7
/**
8
 * @covers \SWL\MediaWiki\Hooks\ExtensionSchemaUpdater
9
 *
10
 * @ingroup Test
11
 *
12
 * @group SWL
13
 * @group SWLExtension
14
 *
15
 * @license GNU GPL v2+
16
 * @since 1.0
17
 *
18
 * @author mwjames
19
 */
20
class ExtensionSchemaUpdaterTest extends \PHPUnit_Framework_TestCase {
21
22
	public function testCanConstruct() {
23
24
		$databaseUpdater = $this->getMockBuilder( 'DatabaseUpdater' )
25
			->disableOriginalConstructor()
26
			->getMockForAbstractClass();
27
28
		$this->assertInstanceOf(
29
			'\SWL\MediaWiki\Hooks\ExtensionSchemaUpdater',
30
			new ExtensionSchemaUpdater( $databaseUpdater )
31
		);
32
	}
33
34
	public function testNoExtensionUpdateForInvalidDBType() {
35
36
		$dbConnection = $this->getMockBuilder( 'DatabaseBase' )
37
			->disableOriginalConstructor()
38
			->getMockForAbstractClass();
39
40
		$dbConnection->expects( $this->once() )
41
			->method( 'getType' )
42
			->will( $this->returnValue( 'foo' ) );
43
44
		$databaseUpdater = $this->getMockBuilder( 'DatabaseUpdater' )
45
			->disableOriginalConstructor()
46
			->setMethods( array(
47
				'getDB',
48
				'addExtensionUpdate' ) )
49
			->getMockForAbstractClass();
50
51
		$databaseUpdater->expects( $this->once() )
52
			->method( 'getDB' )
53
			->will( $this->returnValue( $dbConnection ) );
54
55
		$databaseUpdater->expects( $this->never() )
56
			->method( 'addExtensionUpdate' )
57
			->will( $this->returnValue( true ) );
58
59
		$instance = new ExtensionSchemaUpdater( $databaseUpdater );
60
61
		$this->assertTrue( $instance->execute() );
62
	}
63
64
	/**
65
	 * @dataProvider dbTypeProvider
66
	 */
67
	public function testExtensionUpdateForValidDBType( $dbType ) {
68
69
		$dbConnection = $this->getMockBuilder( 'DatabaseBase' )
70
			->disableOriginalConstructor()
71
			->getMockForAbstractClass();
72
73
		$dbConnection->expects( $this->once() )
74
			->method( 'getType' )
75
			->will( $this->returnValue( $dbType ) );
76
77
		$databaseUpdater = $this->getMockBuilder( 'DatabaseUpdater' )
78
			->disableOriginalConstructor()
79
			->setMethods( array(
80
				'getDB',
81
				'addExtensionUpdate' ) )
82
			->getMockForAbstractClass();
83
84
		$databaseUpdater->expects( $this->once() )
85
			->method( 'getDB' )
86
			->will( $this->returnValue( $dbConnection ) );
87
88
		$databaseUpdater->expects( $this->at( 6 ) )
89
			->method( 'addExtensionUpdate' )
90
			->will( $this->returnValue( true ) );
91
92
		$configuration = array( 'egSwlSqlDatabaseSchemaPath' => 'foo' );
93
94
		$instance = new ExtensionSchemaUpdater( $databaseUpdater );
95
		$instance->setConfiguration( $configuration );
96
97
		$this->assertTrue( $instance->execute() );
98
	}
99
100
	public function dbTypeProvider() {
101
102
		$provider = array(
103
			array( 'sqlite' ),
104
			array( 'mysql' )
105
		);
106
107
		return $provider;
108
	}
109
110
}
111