Passed
Push — rankClass ( 1b9cf4...7f76c7 )
by no
04:15 queued 16s
created

RepositoryNameAssertTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 2
dl 0
loc 77
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A provideInvalidRepositoryNames() 0 16 1
A testGivenInvalidValue_assertParameterIsValidRepositoryNameFails() 0 4 1
A provideValidRepositoryNames() 0 7 1
A testGivenValidValue_assertParameterIsValidRepositoryNamePasses() 0 3 1
A provideInvalidRepositoryNameIndexedArrays() 0 9 1
A testGivenInvalidValue_assertParameterKeysAreValidRepositoryNamesFails() 0 4 1
A provideValidRepositoryNameIndexedArrays() 0 8 1
A testGivenValidValue_assertParameterKeysAreValidRepositoryNamesPasses() 0 3 1
1
<?php
2
3
namespace Wikibase\DataModel\Tests\Assert;
4
5
use Wikibase\DataModel\Assert\RepositoryNameAssert;
6
use Wikimedia\Assert\ParameterAssertionException;
7
8
/**
9
 * @covers \Wikibase\DataModel\Assert\RepositoryNameAssert
10
 *
11
 * @license GPL-2.0+
12
 */
13
class RepositoryNameAssertTest extends \PHPUnit_Framework_TestCase {
14
15
	public function provideInvalidRepositoryNames() {
16
		return [
17
			[ 'fo:o' ],
18
			[ 'foo:' ],
19
			[ ':foo' ],
20
			[ ':' ],
21
			[ 'fo.o' ],
22
			[ 'foo.' ],
23
			[ '.foo' ],
24
			[ '.' ],
25
			[ 123 ],
26
			[ null ],
27
			[ false ],
28
			[ [ 'foo' ] ],
29
		];
30
	}
31
32
	/**
33
	 * @dataProvider provideInvalidRepositoryNames
34
	 */
35
	public function testGivenInvalidValue_assertParameterIsValidRepositoryNameFails( $value ) {
36
		$this->expectException( ParameterAssertionException::class );
37
		RepositoryNameAssert::assertParameterIsValidRepositoryName( $value, 'test' );
38
	}
39
40
	public function provideValidRepositoryNames() {
41
		return [
42
			[ '' ],
43
			[ 'foo' ],
44
			[ '123' ],
45
		];
46
	}
47
48
	/**
49
	 * @dataProvider provideValidRepositoryNames
50
	 */
51
	public function testGivenValidValue_assertParameterIsValidRepositoryNamePasses( $value ) {
52
		RepositoryNameAssert::assertParameterIsValidRepositoryName( $value, 'test' );
53
	}
54
55
	public function provideInvalidRepositoryNameIndexedArrays() {
56
		return [
57
			[ 'foo' ],
58
			[ [ 0 => 'foo' ] ],
59
			[ [ 'fo:0' => 'bar' ] ],
60
			[ [ 'foo:' => 'bar' ] ],
61
			[ [ ':foo' => 'bar' ] ],
62
		];
63
	}
64
65
	/**
66
	 * @dataProvider provideInvalidRepositoryNameIndexedArrays
67
	 */
68
	public function testGivenInvalidValue_assertParameterKeysAreValidRepositoryNamesFails( $values ) {
69
		$this->expectException( ParameterAssertionException::class );
70
		RepositoryNameAssert::assertParameterKeysAreValidRepositoryNames( $values, 'test' );
71
	}
72
73
	public function provideValidRepositoryNameIndexedArrays() {
74
		return [
75
			[ [ 'foo' => 'bar' ] ],
76
			[ [ '' => 'bar' ] ],
77
			[ [ '' => 'bar', 'foo' => 'baz' ] ],
78
			[ [] ],
79
		];
80
	}
81
82
	/**
83
	 * @dataProvider provideValidRepositoryNameIndexedArrays
84
	 */
85
	public function testGivenValidValue_assertParameterKeysAreValidRepositoryNamesPasses( array $values ) {
86
		RepositoryNameAssert::assertParameterKeysAreValidRepositoryNames( $values, 'test' );
87
	}
88
89
}
90