1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ValueFormatters\Test; |
4
|
|
|
|
5
|
|
|
use DataValues\StringValue; |
6
|
|
|
use InvalidArgumentException; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use ValueFormatters\StringFormatter; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers \ValueFormatters\StringFormatter |
12
|
|
|
* |
13
|
|
|
* @group ValueFormatters |
14
|
|
|
* @group DataValueExtensions |
15
|
|
|
* |
16
|
|
|
* @license GPL-2.0+ |
17
|
|
|
* @author Katie Filbert < [email protected] > |
18
|
|
|
*/ |
19
|
|
|
class StringFormatterTest extends TestCase { |
20
|
|
|
|
21
|
|
|
/** @dataProvider validProvider */ |
22
|
|
|
public function testValidFormat( StringValue $value, string $expected ) { |
23
|
|
|
$formatter = new StringFormatter(); |
24
|
|
|
$this->assertSame( $expected, $formatter->format( $value ) ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function validProvider() { |
28
|
|
|
return [ |
29
|
|
|
[ new StringValue( 'ice cream' ), 'ice cream' ], |
30
|
|
|
[ new StringValue( 'cake' ), 'cake' ], |
31
|
|
|
[ new StringValue( '' ), '' ], |
32
|
|
|
[ new StringValue( ' a ' ), ' a ' ], |
33
|
|
|
[ new StringValue( ' ' ), ' ' ], |
34
|
|
|
]; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @dataProvider invalidProvider |
39
|
|
|
*/ |
40
|
|
|
public function testInvalidFormat( $value ) { |
41
|
|
|
$formatter = new StringFormatter(); |
42
|
|
|
$this->expectException( InvalidArgumentException::class ); |
43
|
|
|
$formatter->format( $value ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function invalidProvider() { |
47
|
|
|
return [ |
48
|
|
|
[ null ], |
49
|
|
|
[ 0 ], |
50
|
|
|
[ '' ], |
51
|
|
|
]; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
} |
55
|
|
|
|