Test Failed
Pull Request — master (#91)
by Jeroen De
16:38 queued 06:39
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
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