Completed
Pull Request — master (#1)
by mw
01:15
created

ApprovedStatusPropertyAnnotatorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
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\ApprovedStatusPropertyAnnotator;
6
use SMW\DIProperty;
7
use SMWDIString as DIString;
8
9
/**
10
 * @covers \SMW\ApprovedRevs\PropertyAnnotators\ApprovedStatusPropertyAnnotator
11
 * @group semantic-approved-revs
12
 *
13
 * @license GNU GPL v2+
14
 * @since 1.0
15
 */
16
class ApprovedStatusPropertyAnnotatorTest extends \PHPUnit_Framework_TestCase {
17
18
	private $databaseLogReader;
19
20
	protected function setUp() {
21
		parent::setUp();
22
23
		$this->databaseLogReader = $this->getMockBuilder( '\SMW\ApprovedRevs\DatabaseLogReader' )
24
			->disableOriginalConstructor()
25
			->getMock();
26
	}
27
28
	public function testCanConstruct() {
29
30
		$this->assertInstanceOf(
31
			ApprovedStatusPropertyAnnotator::class,
32
			new ApprovedStatusPropertyAnnotator( $this->databaseLogReader )
33
		);
34
	}
35
36
	public function testAddAnnotation() {
37
38
		$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
39
			->disableOriginalConstructor()
40
			->getMock();
41
42
		$semanticData->expects( $this->once() )
43
			->method( 'addPropertyObjectValue' )
44
			->with(
45
				$this->anyThing(),
46
				$this->equalTo( new DIString( "checkme" ) ) );
47
48
		$annotator = new ApprovedStatusPropertyAnnotator(
49
			$this->databaseLogReader
50
		);
51
52
		$annotator->setApprovedStatus( "checkme" );
53
		$annotator->addAnnotation( $semanticData );
54
	}
55
56
	public function testRemoval() {
57
58
		$semanticData = $this->getMockBuilder( '\SMW\SemanticData' )
59
			->disableOriginalConstructor()
60
			->getMock();
61
62
		$semanticData->expects( $this->once() )
63
			->method( 'removeProperty' );
64
65
		$annotator = new ApprovedStatusPropertyAnnotator(
66
			$this->databaseLogReader
67
		);
68
69
		$annotator->setApprovedStatus( false );
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string.

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