Completed
Pull Request — master (#297)
by
unknown
07:01
created

GraphTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 61
rs 10
c 1
b 0
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormats() 0 3 1
A getClass() 0 3 1
B testGraphNode() 0 29 1
1
<?php
2
3
namespace SRF\Tests\Unit\Formats;
4
5
use SMW\Test\QueryPrinterRegistryTestCase;
6
use SRF\Graph\GraphNode;
7
8
9
/**
10
 * Tests for the SRF\Graph class.
11
 *
12
 * @file
13
 * @since 1.8
14
 *
15
 * @ingroup SemanticResultFormats
16
 * @ingroup Test
17
 *
18
 * @group SRF
19
 * @group SMWExtension
20
 * @group ResultPrinters
21
 *
22
 * @licence GNU GPL v2+
23
 * @author Jeroen De Dauw < [email protected] >
24
 */
25
class GraphTest extends QueryPrinterRegistryTestCase {
26
27
	/**
28
	 * @see QueryPrinterRegistryTestCase::getFormats
29
	 *
30
	 * @since 1.8
31
	 *
32
	 * @return array
33
	 */
34
	public function getFormats() {
35
		return [ 'graph' ];
36
	}
37
38
	/**
39
	 * @see QueryPrinterRegistryTestCase::getClass
40
	 *
41
	 * @since 1.8
42
	 *
43
	 * @return string
44
	 */
45
	public function getClass() {
46
		return 'SRF\Graph\GraphResultPrinter';
47
	}
48
49
	/**
50
	 * Testing class GraphNode
51
	 *
52
	 * @since 3.0
53
	 *
54
	 */
55
	public function testGraphNode(){
56
57
		//can create GraphNode
58
		$this->assertInstanceOf(
59
			GraphNode::class,
60
			$node = new GraphNode( 'Team:Beta' )
61
		);
62
63
		$this->assertEquals( 'Team:Beta', $node->getID() );
64
65
		$node->addLabel( 1, "Fossil Power Generation" );
66
		$this->assertEquals( "Fossil Power Generation", $node->getLabel(1) );
67
68
		$node->addLabel( 2, "Gonzo the Great" );
69
		$this->assertEquals( "Gonzo the Great\l", $node->getLabel(2) );
70
71
		$node->addLabel( 3, "Miss Piggy" );
72
		$node->addLabel( 3, "Rowlf the Dog" );
73
		$this->assertEquals( "Miss Piggy\lRowlf the Dog\l", $node->getLabel(3) );
74
75
		$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...
76
			"predicate" => 'Part Of Team',
77
			"object"    => 'Alpha Team'
78
		];
79
80
		$node->addParentNode( 'Part Of Team', 'Alpha Team' );
81
		$this->assertEquals( $mockParentNode1, $node->getParentNode() );
82
83
	}
84
85
}
86