Completed
Push — master ( 317d6d...1d0462 )
by mw
34:54 queued 09:21
created

testSetUserValueToReturnOnPreferredDisplayPrecision()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 17
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 29
rs 8.8571
1
<?php
2
3
namespace SMW\Tests\DataValues;
4
5
use SMW\DataValues\TemperatureValue;
6
use SMW\DataItemFactory;
7
use SMW\Tests\TestEnvironment;
8
9
/**
10
 * @covers \SMW\DataValues\TemperatureValue
11
 * @group semantic-mediawiki
12
 *
13
 * @license GNU GPL v2+
14
 * @since 2.4
15
 *
16
 * @author mwjames
17
 */
18
class TemperatureValueTest extends \PHPUnit_Framework_TestCase {
19
20
	private $testEnvironment;
21
	private $dataItemFactory;
22
	private $propertySpecificationLookup;
23
24
	protected function setUp() {
25
		$this->testEnvironment = new TestEnvironment();
26
		$this->dataItemFactory = new DataItemFactory();
27
28
		$this->propertySpecificationLookup = $this->getMockBuilder( '\SMW\PropertySpecificationLookup' )
29
			->disableOriginalConstructor()
30
			->getMock();
31
32
		$this->testEnvironment->registerObject( 'PropertySpecificationLookup', $this->propertySpecificationLookup );
33
	}
34
35
	protected function tearDown() {
36
		$this->testEnvironment->tearDown();
37
	}
38
39
	public function testCanConstruct() {
40
41
		$this->assertInstanceOf(
42
			'\SMW\DataValues\TemperatureValue',
43
			new TemperatureValue()
44
		);
45
	}
46
47
	public function testSetUserValueToReturnKelvinForAnyNonPreferredDisplayUnit() {
48
49
		$instance = new TemperatureValue();
50
		$instance->setUserValue( '100 °C' );
51
52
		$this->assertContains(
53
			'373.15 K',
54
			$instance->getWikiValue()
55
		);
56
57
		$instance->setUserValue( '100 Fahrenheit' );
58
59
		$this->assertContains(
60
			'310.92777777778 K',
61
			$instance->getWikiValue()
62
		);
63
64
		$this->assertContains(
65
			'100 Fahrenheit',
66
			$instance->getShortWikiText()
67
		);
68
	}
69
70
	public function testSetUserValueOnUnknownUnit() {
71
72
		$instance = new TemperatureValue();
73
		$instance->setUserValue( '100 Unknown' );
74
75
		$this->assertContains(
76
			'error',
77
			$instance->getWikiValue()
78
		);
79
	}
80
81
	public function testSetUserValueToReturnOnPreferredDisplayUnit() {
82
83
		$this->propertySpecificationLookup->expects( $this->once() )
84
			->method( 'getDisplayUnitsFor' )
85
			->will( $this->returnValue( array( 'Celsius' ) ) );
86
87
		$instance = new TemperatureValue();
88
89
		$instance->setProperty(
90
			$this->dataItemFactory->newDIProperty( 'Foo' )
0 ignored issues
show
Compatibility introduced by
$this->dataItemFactory->newDIProperty('Foo') of type object<SMW\DIProperty> is not a sub-type of object<SMWDIProperty>. It seems like you assume a child class of the class SMW\DIProperty to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
91
		);
92
93
		$instance->setUserValue( '100 °C' );
94
95
		$this->assertContains(
96
			'373.15 K',
97
			$instance->getWikiValue()
98
		);
99
100
		$this->assertContains(
101
			'100 °C',
102
			$instance->getShortWikiText()
103
		);
104
105
		$this->assertContains(
106
			'100&#160;°C (373&#160;K, 212&#160;°F, 672&#160;°R)',
107
			$instance->getLongWikiText()
108
		);
109
	}
110
111
	public function testSetUserValueToReturnOnPreferredDisplayPrecision() {
112
113
		$this->propertySpecificationLookup->expects( $this->once() )
114
			->method( 'getDisplayPrecisionFor' )
115
			->will( $this->returnValue( 0 ) );
116
117
		$instance = new TemperatureValue();
118
119
		$instance->setProperty(
120
			$this->dataItemFactory->newDIProperty( 'Foo' )
0 ignored issues
show
Compatibility introduced by
$this->dataItemFactory->newDIProperty('Foo') of type object<SMW\DIProperty> is not a sub-type of object<SMWDIProperty>. It seems like you assume a child class of the class SMW\DIProperty to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
121
		);
122
123
		$instance->setUserValue( '100 °C' );
124
125
		$this->assertContains(
126
			'373 K',
127
			$instance->getWikiValue()
128
		);
129
130
		$this->assertContains(
131
			'100 °C',
132
			$instance->getShortWikiText()
133
		);
134
135
		$this->assertContains(
136
			'373&#160;K (100&#160;°C, 212&#160;°F, 672&#160;°R)',
137
			$instance->getLongWikiText()
138
		);
139
	}
140
141
}
142