Passed
Push — nullBounds ( b3e7e4...f3529c )
by no
03:35
created

DecimalFormatterTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 5
c 6
b 0
f 0
lcom 0
cbo 4
dl 0
loc 63
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormatterClass() 0 3 1
A getInstance() 0 3 1
A validProvider() 0 23 2
A testLocalization() 0 14 1
1
<?php
2
3
namespace ValueFormatters\Test;
4
5
use DataValues\DecimalValue;
6
use ValueFormatters\DecimalFormatter;
7
use ValueFormatters\FormatterOptions;
8
9
/**
10
 * @covers ValueFormatters\DecimalFormatter
11
 *
12
 * @group ValueFormatters
13
 * @group DataValueExtensions
14
 *
15
 * @license GPL-2.0+
16
 * @author Daniel Kinzler
17
 */
18
class DecimalFormatterTest 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 DecimalFormatter
33
	 */
34
	protected function getInstance( FormatterOptions $options = null ) {
35
		return new DecimalFormatter( $options );
36
	}
37
38
	/**
39
	 * @see ValueFormatterTestBase::validProvider
40
	 */
41
	public function validProvider() {
42
		$optionsForceSign = new FormatterOptions( array(
43
			DecimalFormatter::OPT_FORCE_SIGN => true
44
		) );
45
46
		$decimals = array(
47
			'+0' => array( '0', null ),
48
			'+0.0' => array( '0.0', null ),
49
			'-0.0130' => array( '-0.0130', null ),
50
			'+10000.013' => array( '10000.013', null ),
51
			'+20000.4' => array( '+20000.4', $optionsForceSign ),
52
			'-12' => array( '-12', null )
53
		);
54
55
		$argLists = array();
56
		foreach ( $decimals as $input => $args ) {
57
			$inputValue = new DecimalValue( $input );
58
59
			$argLists[$input] = array_merge( array( $inputValue ), $args );
60
		}
61
62
		return $argLists;
63
	}
64
65
	public function testLocalization() {
66
		$localizer = $this->getMock( 'ValueFormatters\NumberLocalizer' );
67
68
		$localizer->expects( $this->once() )
69
			->method( 'localizeNumber' )
70
			->will( $this->returnCallback( function ( $number ) {
71
				return "n:$number";
72
			} ) );
73
74
		$value = new DecimalValue( '+12345' );
75
		$formatter = new DecimalFormatter( null, $localizer );
76
77
		$this->assertEquals( 'n:12345', $formatter->format( $value ) );
78
	}
79
80
}
81