ScribuntoLuaLibrarySetTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 76
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTestModules() 0 5 1
A testSet() 0 6 1
A dataProviderSetTest() 0 36 1
1
<?php
2
3
namespace SMW\Scribunto\Tests;
4
5
/**
6
 * @covers \SMW\Scribunto\ScribuntoLuaLibrary
7
 * @group semantic-scribunto
8
 *
9
 * @license GNU GPL v2+
10
 * @since 1.0
11
 *
12
 * @author Tobias Oetterer
13
 */
14
class ScribuntoLuaLibrarySetTest extends ScribuntoLuaEngineTestBase {
15
16
	/**
17
	 * Lua test module
18
	 * @var string
19
	 */
20
	protected static $moduleName = self::class;
21
22
	/**
23
	 * ScribuntoLuaEngineTestBase::getTestModules
24
	 */
25
	public function getTestModules() {
26
		return parent::getTestModules() + [
27
			self::$moduleName => __DIR__ . '/' . 'mw.smw.set.tests.lua',
28
		];
29
	}
30
31
	/**
32
	 * Tests method set through assertions based upon
33
	 * dataProvider {@see \SMW\Scribunto\Tests\ScribuntoLuaLibraryTest::dataProviderSetTest}
34
	 *
35
	 * @dataProvider dataProviderSetTest
36
	 * @param array $arguments arguments passed to function
37
	 * @param mixed $expected expected return value
38
	 */
39
	public function testSet( $arguments, $expected) {
40
		$this->assertEquals(
41
			$expected,
42
			$this->getScribuntoLuaLibrary()->set($arguments)
43
		);
44
	}
45
46
	/**
47
	 * Data provider for {@see testSet}
48
	 *
49
	 * @see testSet
50
	 *
51
	 * @return array
52
	 */
53
	public function dataProviderSetTest() {
54
		return [
55
			[
56
				null,
57
				[ 1 => true ]
58
			],
59
			[
60
				'',
61
				[ 1 => true ]
62
			],
63
			[
64
				[ ],
65
				[ 1 => true ]
66
			],
67
			[
68
				[ '' ],
69
				[ 1 => true ]
70
			],
71
			[
72
				[ 'has text=test' ],
73
				[ 1 => true ]
74
			],
75
			[
76
				[ 'has type=test' ],
77
				[ [ 1 => false, 'error' => wfMessage('smw-datavalue-property-restricted-declarative-use', 'Has type')->inLanguage('en')->plain() ] ]
78
			],
79
			[
80
				[ '1215623e790d918773db943232068a93b21c9f1419cb85666c6558e87f5b7d47=test' ],
81
				[ 1 => true ]
82
			],
83
			[
84
				[ '1215623e790d918773db943232068a93b21c9f1419cb85666c6558e87f5b7d47=test', 'foo' => 'bar' ],
85
				[ 1 => true ]
86
			]
87
		];
88
	}
89
}