Passed
Push — trimNormalizer ( b2284d...0e0038 )
by no
05:06
created

StringFormatterTest::validProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace ValueFormatters\Test;
4
5
use DataValues\StringValue;
6
use InvalidArgumentException;
7
use ValueFormatters\FormatterOptions;
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 ValueFormatterTestBase {
20
21
	/**
22
	 * @see ValueFormatterTestBase::getInstance
23
	 *
24
	 * @param FormatterOptions|null $options
25
	 *
26
	 * @return StringFormatter
27
	 */
28
	protected function getInstance( FormatterOptions $options = null ) {
29
		return new StringFormatter( $options );
0 ignored issues
show
Unused Code introduced by
The call to StringFormatter::__construct() has too many arguments starting with $options.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
30
	}
31
32
	/**
33
	 * @see ValueFormatterTestBase::validProvider
34
	 */
35
	public function validProvider() {
36
		return [
37
			[ new StringValue( 'ice cream' ), 'ice cream' ],
38
			[ new StringValue( 'cake' ), 'cake' ],
39
			[ new StringValue( '' ), '' ],
40
			[ new StringValue( ' a ' ), ' a ' ],
41
			[ new StringValue( '  ' ), '  ' ],
42
		];
43
	}
44
45
	/**
46
	 * @dataProvider invalidProvider
47
	 */
48
	public function testInvalidFormat( $value ) {
49
		$formatter = new StringFormatter();
50
		$this->setExpectedException( InvalidArgumentException::class );
51
		$formatter->format( $value );
52
	}
53
54
	public function invalidProvider() {
55
		return [
56
			[ null ],
57
			[ 0 ],
58
			[ '' ],
59
		];
60
	}
61
62
}
63