Completed
Pull Request — master (#687)
by Leszek
05:29
created

RepositoryNameAssertTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A provideInvalidRepositoryNames() 0 12 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
			[ 123 ],
22
			[ null ],
23
			[ false ],
24
			[ [ 'foo' ] ],
25
		];
26
	}
27
28
	/**
29
	 * @dataProvider provideInvalidRepositoryNames
30
	 */
31
	public function testGivenInvalidValue_assertParameterIsValidRepositoryNameFails( $value ) {
32
		$this->setExpectedException( ParameterAssertionException::class );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
33
		RepositoryNameAssert::assertParameterIsValidRepositoryName( $value, 'test' );
34
	}
35
36
	public function provideValidRepositoryNames() {
37
		return [
38
			[ '' ],
39
			[ 'foo' ],
40
			[ '123' ],
41
		];
42
	}
43
44
	/**
45
	 * @dataProvider provideValidRepositoryNames
46
	 */
47
	public function testGivenValidValue_assertParameterIsValidRepositoryNamePasses( $value ) {
48
		RepositoryNameAssert::assertParameterIsValidRepositoryName( $value, 'test' );
49
	}
50
51
	public function provideInvalidRepositoryNameIndexedArrays() {
52
		return [
53
			[ 'foo' ],
54
			[ [ 0 => 'foo' ] ],
55
			[ [ 'fo:0' => 'bar' ] ],
56
			[ [ 'foo:' => 'bar' ] ],
57
			[ [ ':foo' => 'bar' ] ],
58
		];
59
	}
60
61
	/**
62
	 * @dataProvider provideInvalidRepositoryNameIndexedArrays
63
	 */
64
	public function testGivenInvalidValue_assertParameterKeysAreValidRepositoryNamesFails( $values ) {
65
		$this->setExpectedException( ParameterAssertionException::class );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
66
		RepositoryNameAssert::assertParameterKeysAreValidRepositoryNames( $values, 'test' );
67
	}
68
69
	public function provideValidRepositoryNameIndexedArrays() {
70
		return [
71
			[ [ 'foo' => 'bar' ] ],
72
			[ [ '' => 'bar' ] ],
73
			[ [ '' => 'bar', 'foo' => 'baz' ] ],
74
			[ [] ],
75
		];
76
	}
77
78
	/**
79
	 * @dataProvider provideValidRepositoryNameIndexedArrays
80
	 */
81
	public function testGivenValidValue_assertParameterKeysAreValidRepositoryNamesPasses( array $values ) {
82
		RepositoryNameAssert::assertParameterKeysAreValidRepositoryNames( $values, 'test' );
83
	}
84
85
}
86