Completed
Push — master ( ee97e0...8d3377 )
by mw
199:01 queued 164:02
created

setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 9.4285
1
<?php
2
3
namespace SMW\Tests\Exporter\ResourceBuilders;
4
5
use SMW\Exporter\ResourceBuilders\UniquenessConstraintPropertyValueResourceBuilder;
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\UniquenessConstraintPropertyValueResourceBuilder
14
 * @group semantic-mediawiki
15
 *
16
 * @license GNU GPL v2+
17
 * @since 2.5
18
 *
19
 * @author mwjames
20
 */
21
class UniquenessConstraintPropertyValueResourceBuilderTest 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
			UniquenessConstraintPropertyValueResourceBuilder::class,
45
			new UniquenessConstraintPropertyValueResourceBuilder()
46
		);
47
	}
48
49
	public function testIsNotResourceBuilderForNonUniquenessConstraintProperty() {
50
51
		$property = $this->dataItemFactory->newDIProperty( 'Foo' );
52
53
		$instance = new UniquenessConstraintPropertyValueResourceBuilder();
54
55
		$this->assertFalse(
56
			$instance->isResourceBuilderFor( $property )
57
		);
58
	}
59
60
	public function testAddResourceValueForValidProperty() {
61
62
		$property = $this->dataItemFactory->newDIProperty( '_PVUC' );
63
64
		$expData = new ExpData(
65
			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...
66
		);
67
68
		$instance = new UniquenessConstraintPropertyValueResourceBuilder();
69
70
		$instance->addResourceValue(
71
			$expData,
72
			$property,
73
			$this->dataItemFactory->newDIBoolean( true )
74
		);
75
76
		$this->assertTrue(
77
			$instance->isResourceBuilderFor( $property )
78
		);
79
	}
80
81
}
82