Completed
Push — master ( 946aec...bc2207 )
by mw
03:21
created

ApprovedRevPropertyAnnotatorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 58
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testCanConstruct() 0 7 1
A testAddAnnotation() 0 19 1
A testRemoval() 0 16 1
1
<?php
2
3
namespace SMW\ApprovedRevs\Tests\PropertyAnnotators;
4
5
use SMW\ApprovedRevs\PropertyAnnotators\ApprovedRevPropertyAnnotator;
6
use SMW\DIProperty;
7
use SMW\DIWikiPage;
8
use SMWDINumber as DINumber;
9
10
/**
11
 * @covers \SMW\ApprovedRevs\PropertyAnnotators\ApprovedRevPropertyAnnotator
12
 * @group semantic-approved-revs
13
 *
14
 * @license GNU GPL v2+
15
 * @since 1.0
16
 */
17
class ApprovedRevPropertyAnnotatorTest extends \PHPUnit_Framework_TestCase {
18
19
	private $approvedRevsFacade;
20
21
	protected function setUp() {
22
		parent::setUp();
23
24
		$this->approvedRevsFacade = $this->getMockBuilder( '\SMW\ApprovedRevs\ApprovedRevsFacade' )
25
			->disableOriginalConstructor()
26
			->getMock();
27
	}
28
29
	public function testCanConstruct() {
30
31
		$this->assertInstanceOf(
32
			ApprovedRevPropertyAnnotator::class,
33
			new ApprovedRevPropertyAnnotator( $this->approvedRevsFacade )
34
		);
35
	}
36
37
	public function testAddAnnotation() {
38
39
		$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
40
			->disableOriginalConstructor()
41
			->getMock();
42
43
		$semanticData->expects( $this->once() )
44
			->method( 'addPropertyObjectValue' )
45
			->with(
46
				$this->anyThing(),
47
				$this->equalTo( new DINumber( 42 ) ) );
48
49
		$annotator = new ApprovedRevPropertyAnnotator(
50
			$this->approvedRevsFacade
51
		);
52
53
		$annotator->setApprovedRev( 42 );
54
		$annotator->addAnnotation( $semanticData );
55
	}
56
57
	public function testRemoval() {
58
59
		$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
60
			->disableOriginalConstructor()
61
			->getMock();
62
63
		$semanticData->expects( $this->once() )
64
			->method( 'removeProperty' );
65
66
		$annotator = new ApprovedRevPropertyAnnotator(
67
			$this->approvedRevsFacade
68
		);
69
70
		$annotator->setApprovedRev( false );
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

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
		$annotator->addAnnotation( $semanticData );
72
	}
73
74
}
75