Completed
Push — master ( 69614a...9cb597 )
by mw
14s
created

tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace SMW\Tests\Exporter\ResourceBuilders;
4
5
use SMW\Exporter\ResourceBuilders\PropertyDescriptionValueResourceBuilder;
6
use SMW\DataItemFactory;
7
use SMW\DataValueFactory;
8
use SMW\Tests\TestEnvironment;
9
use SMWExpData as ExpData;
10
use SMW\Exporter\Element\ExpNsResource;
11
12
/**
13
 * @covers \SMW\Exporter\ResourceBuilders\PropertyDescriptionValueResourceBuilder
14
 * @group semantic-mediawiki
15
 *
16
 * @license GNU GPL v2+
17
 * @since 2.5
18
 *
19
 * @author mwjames
20
 */
21
class PropertyDescriptionValueResourceBuilderTest extends \PHPUnit_Framework_TestCase {
22
23
	private $dataItemFactory;
24
	private $dataValueFactory;
25
	private $testEnvironment;
26
27
	protected function setUp() {
28
		parent::setUp();
29
		$this->dataItemFactory = new DataItemFactory();
30
		$this->dataValueFactory = DataValueFactory::getInstance();
31
32
		$this->testEnvironment = new TestEnvironment();
33
		$this->testEnvironment->resetPoolCacheFor( \SMWExporter::POOLCACHE_ID );
34
	}
35
36
	protected function tearDown() {
37
		$this->testEnvironment->tearDown();
38
		parent::tearDown();
39
	}
40
41
	public function testCanConstruct() {
42
43
		$this->assertInstanceof(
44
			PropertyDescriptionValueResourceBuilder::class,
45
			new PropertyDescriptionValueResourceBuilder()
46
		);
47
	}
48
49
	public function testIsNotResourceBuilderForPropertyDescription() {
50
51
		$property = $this->dataItemFactory->newDIProperty( 'Foo' );
52
53
		$instance = new PropertyDescriptionValueResourceBuilder();
54
55
		$this->assertFalse(
56
			$instance->isResourceBuilderFor( $property )
57
		);
58
	}
59
60
	public function testAddResourceValueForPropertyDescription() {
61
62
		$property = $this->dataItemFactory->newDIProperty( '_PDESC' );
63
64
		$monolingualTextValue = $this->dataValueFactory->newDataValueByProperty(
65
			$property,
66
			'Some description@en'
0 ignored issues
show
Documentation introduced by
'Some description@en' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
67
		);
68
69
		$expData = new ExpData(
70
			new ExpNsResource( 'Foobar', 'Bar', 'Mo', null )
0 ignored issues
show
Documentation introduced by
new \SMW\Exporter\Elemen...ar', 'Bar', 'Mo', null) is of type object<SMW\Exporter\Element\ExpNsResource>, but the function expects a object<SMWExpResource>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
71
		);
72
73
		$instance = new PropertyDescriptionValueResourceBuilder();
74
75
		$instance->addResourceValue(
76
			$expData,
77
			$property,
78
			$monolingualTextValue->getDataItem()
79
		);
80
81
		$this->assertTrue(
82
			$instance->isResourceBuilderFor( $property )
83
		);
84
	}
85
86
}
87