Completed
Push — master ( cd2f8d...f0067b )
by mw
37:19 queued 02:22
created

TemperatureValueTest::testCanConstruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace SMW\Tests\DataValues;
4
5
use SMW\DataValues\TemperatureValue;
6
use SMW\ApplicationFactory;
7
use SMW\DIProperty;
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
	public function testCanConstruct() {
21
22
		$this->assertInstanceOf(
23
			'\SMW\DataValues\TemperatureValue',
24
			new TemperatureValue()
25
		);
26
	}
27
28
	public function testSetUserValueToReturnKelvinForAnyNonPreferredDisplayUnit() {
29
30
		$instance = new TemperatureValue();
31
		$instance->setUserValue( '100 °C' );
32
33
		$this->assertContains(
34
			'373.15 K',
35
			$instance->getWikiValue()
36
		);
37
38
		$instance->setUserValue( '100 Fahrenheit' );
39
40
		$this->assertContains(
41
			'310.928 K',
42
			$instance->getWikiValue()
43
		);
44
45
		$this->assertContains(
46
			'100 Fahrenheit',
47
			$instance->getShortWikiText()
48
		);
49
	}
50
51
	public function testSetUserValueOnUnknownUnit() {
52
53
		$instance = new TemperatureValue();
54
		$instance->setUserValue( '100 Unknown' );
55
56
		$this->assertContains(
57
			'error',
58
			$instance->getWikiValue()
59
		);
60
	}
61
62
	public function testSetUserValueToReturnOnPreferredDisplayUnit() {
63
64
		$propertySpecificationLookup = $this->getMockBuilder( '\SMW\PropertySpecificationLookup' )
65
			->disableOriginalConstructor()
66
			->getMock();
67
68
		$propertySpecificationLookup->expects( $this->once() )
69
			->method( 'getDisplayUnitsFor' )
70
			->will( $this->returnValue( array( 'Celsius' ) ) );
71
72
		ApplicationFactory::getInstance()->registerObject( 'PropertySpecificationLookup', $propertySpecificationLookup );
73
74
		$instance = new TemperatureValue();
75
		$instance->setProperty( new DIProperty( 'Foo' ) );
0 ignored issues
show
Compatibility introduced by
new \SMW\DIProperty('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...
76
		$instance->setUserValue( '100 °C' );
77
78
		$this->assertContains(
79
			'373 K',
80
			$instance->getWikiValue()
81
		);
82
83
		$this->assertContains(
84
			'100 °C',
85
			$instance->getShortWikiText()
86
		);
87
88
		$this->assertContains(
89
			'100&#160;°C (373&#160;K, 212&#160;°F, 672&#160;°R)',
90
			$instance->getLongWikiText()
91
		);
92
93
		ApplicationFactory::getInstance()->clear();
94
	}
95
96
}
97