Completed
Pull Request — master (#507)
by
unknown
14:08
created

GraphNodeTest::testGraphNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SRF\Tests\Unit\Formats;
4
5
use SRF\Graph\GraphNode;
6
7
8
/**
9
 * @covers \SRF\Graph\GraphNode
10
 * @group semantic-result-formats
11
 *
12
 * @licence GNU GPL v2+
13
 * @since 3.1
14
 *
15
 * @author Sebastian Schmid < [email protected] >
16
 */
17
18
class GraphNodeTest extends \PHPUnit_Framework_TestCase {
19
20
	public function testCanConstruct() {
21
22
		$this->assertInstanceOf(
23
			GraphNode::class,
24
			new GraphNode( "graphnode:id" )
25
		);
26
	}
27
28
	public function testGraphNode(){
29
30
		$node = new GraphNode( 'Team:Beta' );
31
		$this->assertEquals( 'Team:Beta', $node->getID() );
32
33
		$node->setLabel( "Fossil Power Generation" );
34
		$this->assertEquals( "Fossil Power Generation", $node->getLabel() );
35
	}
36
37
	public function testAddParentNode(){
38
39
		$mockParentNode1[] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$mockParentNode1 was never initialized. Although not strictly required by PHP, it is generally a good practice to add $mockParentNode1 = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
40
			"predicate" => 'Part Of Team',
41
			"object"    => 'Alpha Team'
42
		];
43
44
		$node = new GraphNode( 'Team:Beta' );
45
46
		$node->addParentNode( 'Part Of Team', 'Alpha Team' );
47
		$this->assertEquals( $mockParentNode1, $node->getParentNode() );
48
	}
49
50
}
51