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 array( |
43
|
|
|
array( new StringValue( 'ice cream' ), 'ice cream' ), |
44
|
|
|
array( new StringValue( 'cake' ), 'cake' ), |
45
|
|
|
array( new StringValue( '' ), '' ), |
46
|
|
|
array( new StringValue( ' a ' ), ' a ' ), |
47
|
|
|
array( 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 array( |
62
|
|
|
array( null ), |
63
|
|
|
array( 0 ), |
64
|
|
|
array( '' ), |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|