Completed
Push — reponame-assert ( e1c5cc )
by Leszek
08:01
created

provideInvalidRepositoryNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
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