These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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
|
|||
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 |
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.