Passed
Push — master ( c10187...e70c3d )
by Jeroen De
01:08 queued 14s
created

TitleValidatorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testValidate() 0 10 2
A titleProvider() 0 27 1
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
 * @license GPL-2.0-or-later
16
 * @author Thiemo Kreuz
17
 */
18
class TitleValidatorTest extends 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' )
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/pull/3687

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...
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