Completed
Push — master ( 3d831c...fcc0b1 )
by Jeroen De
07:01 queued 02:46
created

StringFormatterTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 0
cbo 3
dl 0
loc 51
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 3 1
A validProvider() 0 9 1
A testInvalidFormat() 0 5 1
A invalidProvider() 0 7 1
A getFormatterClass() 0 3 1
1
<?php
2
3
namespace ValueFormatters\Test;
4
5
use DataValues\StringValue;
6
use ValueFormatters\FormatterOptions;
7
use ValueFormatters\StringFormatter;
8
9
/**
10
 * @covers ValueFormatters\StringFormatter
11
 *
12
 * @group ValueFormatters
13
 * @group DataValueExtensions
14
 *
15
 * @license GPL-2.0+
16
 * @author Katie Filbert < [email protected] >
17
 */
18
class StringFormatterTest extends ValueFormatterTestBase {
19
20
	/**
21
	 * @deprecated since DataValues Interfaces 0.2, just use getInstance.
22
	 */
23
	protected function getFormatterClass() {
24
		throw new \LogicException( 'Should not be called, use getInstance' );
25
	}
26
27
	/**
28
	 * @see ValueFormatterTestBase::getInstance
29
	 *
30
	 * @param FormatterOptions|null $options
31
	 *
32
	 * @return StringFormatter
33
	 */
34
	protected function getInstance( FormatterOptions $options = null ) {
35
		return new StringFormatter( $options );
0 ignored issues
show
Unused Code introduced by Thiemo Mättig
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...
36
	}
37
38
	/**
39
	 * @see ValueFormatterTestBase::validProvider
40
	 */
41
	public function validProvider() {
42
		return [
43
			[ new StringValue( 'ice cream' ), 'ice cream' ],
44
			[ new StringValue( 'cake' ), 'cake' ],
45
			[ new StringValue( '' ), '' ],
46
			[ new StringValue( ' a ' ), ' a ' ],
47
			[ new StringValue( '  ' ), '  ' ],
48
		];
49
	}
50
51
	/**
52
	 * @dataProvider invalidProvider
53
	 */
54
	public function testInvalidFormat( $value ) {
55
		$formatter = new StringFormatter();
56
		$this->setExpectedException( 'InvalidArgumentException' );
57
		$formatter->format( $value );
58
	}
59
60
	public function invalidProvider() {
61
		return [
62
			[ null ],
63
			[ 0 ],
64
			[ '' ],
65
		];
66
	}
67
68
}
69