Passed
Push — master ( 8ff373...315bd9 )
by adam
01:44
created

StringFormatterTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 36
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testValidFormat() 0 4 1
A validProvider() 0 9 1
A testInvalidFormat() 0 5 1
A invalidProvider() 0 7 1
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