Passed
Push — master ( 5e2fb7...f2aa59 )
by Marius
01:47
created

TitleValidatorTest::titleProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 18
nc 1
nop 0
1
<?php
2
3
namespace ValueValidators\Tests;
4
5
use PHPUnit_Framework_TestCase;
6
use ValueValidators\Error;
7
use ValueValidators\TitleValidator;
8
9
/**
10
 * @covers ValueValidators\TitleValidator
11
 *
12
 * @group ValueValidators
13
 * @group DataValueExtensions
14
 *
15
 * @licence GNU GPL v2+
16
 * @author Thiemo Mättig
17
 */
18
class TitleValidatorTest extends PHPUnit_Framework_TestCase {
19
20
	/**
21
	 * @dataProvider titleProvider
22
	 */
23
	public function testValidate( $value, $hasToExist, $expectedError ) {
24
		$validator = new TitleValidator();
25
		$validator->setOptions( [ 'hastoexist' => $hasToExist ] );
26
		$result = $validator->validate( $value );
27
28
		$this->assertEquals(
29
			$expectedError === null ? [] : [ $expectedError ],
30
			$result->getErrors()
31
		);
32
	}
33
34
	public function titleProvider() {
35
		$title = $this->getMockBuilder( 'Title' )
36
			->disableOriginalConstructor()
37
			->setMethods( [ 'exists' ] )
38
			->getMock();
39
		$title->expects( $this->any() )
40
			->method( 'exists' )
41
			->will( $this->returnValue( false ) );
42
43
		return [
44
			[
45
				'value' => null,
46
				'hasToExist' => false,
47
				'expectedErrors' => Error::newError( 'Not a title' )
48
			],
49
			[
50
				'value' => $title,
51
				'hasToExist' => false,
52
				'expectedErrors' => null
53
			],
54
			[
55
				'value' => $title,
56
				'hasToExist' => true,
57
				'expectedErrors' => Error::newError( 'Title does not exist' )
58
			],
59
		];
60
	}
61
62
}
63