Completed
Pull Request — master (#538)
by
unknown
13:29
created

GraphFormatterTest::testGetGraphLegend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
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\GraphFormatter;
6
use SRF\Graph\GraphNode;
7
8
9
/**
10
 * @covers \SRF\Graph\GraphFormatter
11
 * @group semantic-result-formats
12
 *
13
 * @license GNU GPL v2+
14
 *
15
 * @author Sebastian Schmid (gesinn.it)
16
 */
17
class GraphFormatterTest extends \PHPUnit_Framework_TestCase {
18
19
	/*
20
	* @see https://www.semantic-mediawiki.org/wiki/Help:Graph_format
21
	*/
22
	private $options = [
23
		'graphName' => "Unit Test",
24
		'graphSize' => "100",
25
		'nodeShape' => "rect",
26
		'nodeLabel' => "displaytitle",
27
		'rankDir' => "TB",
28
		'wordWrapLimit' => "20",
29
		'parentRelation' => "parent",
30
		'enableGraphLink' => "yes",
31
		'showGraphLabel' => "yes",
32
		'showGraphColor' => "yes",
33
		'showGraphLegend' => "yes",
34
	];
35
36
	private $graphFormatter;
37
38
	private $nodes = [];
39
40
	protected function setUp() {
41
		parent::setUp();
42
43
		$this->graphFormatter = new GraphFormatter( $this->options );
44
45
		$this->nodes = [];
46
47
		$node1 = new GraphNode( 'Team:Alpha' );
48
		$node1->setLabel( "Alpha" );
49
		$node1->addParentNode( "Casted", "Person:Alexander Gesinn" );
50
		$this->nodes[] = $node1;
51
52
		$node2 = new GraphNode( 'Team:Beta' );
53
		$node2->setLabel( "Beta" );
54
		$node2->addParentNode( "Casted", "Person:Sebastian Schmid" );
55
		$node2->addParentNode( "Casted", "Person:Alexander Gesinn" );
56
		$node2->addParentNode( "Part of Team ", "Team:Alpha" );
57
		$this->nodes[] = $node2;
58
59
		$this->graphFormatter->buildGraph( $this->nodes );
0 ignored issues
show
Documentation introduced by
$this->nodes is of type array<integer,object<SRF\Graph\GraphNode>>, but the function expects a array<integer,object<SRF...\SRF\Graph\GraphNodes>>.

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...
60
	}
61
62
	public function testCanConstruct() {
63
		$this->assertInstanceOf( GraphFormatter::class, new GraphFormatter( $this->options ) );
64
	}
65
66
	public function testGetWordWrappedText() {
67
		$text = 'Lorem ipsum dolor sit amet';
68
		$expected = 'Lorem \nipsum \ndolor sit \namet';
69
70
		$this->assertEquals( GraphFormatter::getWordWrappedText( $text, 10 ), $expected );
71
	}
72
73
	public function testGetGraphLegend() {
74
		$expected =
75
			'<div class="graphlegend"><div class="graphlegenditem" style="color: black">black: Casted</div><div class="graphlegenditem" style="color: red">red: Part of Team </div></div>';
76
77
		$this->assertEquals( $this->graphFormatter->getGraphLegend(), $expected );
78
	}
79
}