1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ValueFormatters\Test; |
4
|
|
|
|
5
|
|
|
use DataValues\StringValue; |
6
|
|
|
use ValueFormatters\FormatterOptions; |
7
|
|
|
use ValueFormatters\StringFormatter; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers ValueFormatters\StringFormatter |
11
|
|
|
* |
12
|
|
|
* @group ValueFormatters |
13
|
|
|
* @group DataValueExtensions |
14
|
|
|
* |
15
|
|
|
* @license GPL-2.0+ |
16
|
|
|
* @author Katie Filbert < [email protected] > |
17
|
|
|
*/ |
18
|
|
|
class StringFormatterTest extends ValueFormatterTestBase { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @deprecated since DataValues Interfaces 0.2, just use getInstance. |
22
|
|
|
*/ |
23
|
|
|
protected function getFormatterClass() { |
24
|
|
|
throw new \LogicException( 'Should not be called, use getInstance' ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @see ValueFormatterTestBase::getInstance |
29
|
|
|
* |
30
|
|
|
* @param FormatterOptions|null $options |
31
|
|
|
* |
32
|
|
|
* @return StringFormatter |
33
|
|
|
*/ |
34
|
|
|
protected function getInstance( FormatterOptions $options = null ) { |
35
|
|
|
return new StringFormatter( $options ); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @see ValueFormatterTestBase::validProvider |
40
|
|
|
*/ |
41
|
|
|
public function validProvider() { |
42
|
|
|
return [ |
43
|
|
|
[ new StringValue( 'ice cream' ), 'ice cream' ], |
44
|
|
|
[ new StringValue( 'cake' ), 'cake' ], |
45
|
|
|
[ new StringValue( '' ), '' ], |
46
|
|
|
[ new StringValue( ' a ' ), ' a ' ], |
47
|
|
|
[ new StringValue( ' ' ), ' ' ], |
48
|
|
|
]; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @dataProvider invalidProvider |
53
|
|
|
*/ |
54
|
|
|
public function testInvalidFormat( $value ) { |
55
|
|
|
$formatter = new StringFormatter(); |
56
|
|
|
$this->setExpectedException( 'InvalidArgumentException' ); |
57
|
|
|
$formatter->format( $value ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function invalidProvider() { |
61
|
|
|
return [ |
62
|
|
|
[ null ], |
63
|
|
|
[ 0 ], |
64
|
|
|
[ '' ], |
65
|
|
|
]; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.