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