Skip to content

Commit a906a90

Browse files
committed
Merge pull request #15 from stereomon/add-strict
Allow strict graphs, add missing test for setPath, add missing doc block
2 parents 95ed74e + dddfd60 commit a906a90

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

src/phpDocumentor/GraphViz/Graph.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
2525
* @license http://www.opensource.org/licenses/mit-license.php MIT
2626
* @link http://phpdoc.org
27-
*
27+
*
2828
* @method Graph setRankSep(string $rankSep)
2929
* @method Graph setCenter(string $center)
3030
* @method Graph setRank(string $rank)
@@ -41,6 +41,9 @@ class Graph
4141
/** @var string Type of this graph; may be digraph, graph or subgraph */
4242
protected $type = 'digraph';
4343

44+
/** @var bool If the graph is strict then multiple edges are not allowed between the same pairs of nodes */
45+
protected $strict = false;
46+
4447
/** @var \phpDocumentor\GraphViz\Attribute[] A list of attributes for this Graph */
4548
protected $attributes = array();
4649

@@ -53,6 +56,7 @@ class Graph
5356
/** @var \phpDocumentor\GraphViz\Edge[] A list of edges / arrows for this Graph */
5457
protected $edges = array();
5558

59+
/** @var string The path to execute dot from */
5660
protected $path = '';
5761

5862
/**
@@ -148,6 +152,28 @@ public function getType()
148152
return $this->type;
149153
}
150154

155+
/**
156+
* Set if the Graph should be strict. If the graph is strict then
157+
* multiple edges are not allowed between the same pairs of nodes
158+
*
159+
* @param bool $isStrict
160+
*
161+
* @return \phpDocumentor\GraphViz\Graph
162+
*/
163+
public function setStrict($isStrict)
164+
{
165+
$this->strict = $isStrict;
166+
return $this;
167+
}
168+
169+
/**
170+
* @return bool
171+
*/
172+
public function isStrict()
173+
{
174+
return $this->strict;
175+
}
176+
151177
/**
152178
* Magic method to provide a getter/setter to add attributes on the Graph.
153179
*
@@ -375,8 +401,10 @@ public function __toString()
375401
}
376402
$attributes = implode(PHP_EOL, $attributes);
377403

404+
$strict = ($this->isStrict() ? 'strict ' : '');
405+
378406
return <<<DOT
379-
{$this->getType()} "{$this->getName()}" {
407+
{$strict}{$this->getType()} "{$this->getName()}" {
380408
$attributes
381409
}
382410
DOT;

tests/phpDocumentor/GraphViz/Test/GraphTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,39 @@ public function testGetType()
144144
);
145145
}
146146

147+
public function testSetStrict()
148+
{
149+
$this->assertSame(
150+
$this->fixture, $this->fixture->setStrict(true),
151+
'Expecting a fluent interface'
152+
);
153+
$this->assertSame(
154+
$this->fixture, $this->fixture->setStrict(false),
155+
'Expecting a fluent interface'
156+
);
157+
}
158+
159+
public function testIsStrict()
160+
{
161+
$this->assertSame(
162+
$this->fixture->isStrict(),
163+
false
164+
);
165+
$this->fixture->setStrict(true);
166+
$this->assertSame(
167+
$this->fixture->isStrict(),
168+
true
169+
);
170+
}
171+
172+
public function testSetPath()
173+
{
174+
$this->assertSame(
175+
$this->fixture, $this->fixture->setPath(__DIR__),
176+
'Expecting a fluent interface'
177+
);
178+
}
179+
147180
/**
148181
* @covers phpDocumentor\GraphViz\Graph::__call
149182
*/
@@ -317,6 +350,12 @@ public function test__toString()
317350
(string) $graph,
318351
('digraph "My First Graph" {' . PHP_EOL . 'label="PigeonPost"' . PHP_EOL . '}')
319352
);
353+
354+
$graph->setStrict(true);
355+
$this->assertSame(
356+
(string) $graph,
357+
('strict digraph "My First Graph" {' . PHP_EOL . 'label="PigeonPost"' . PHP_EOL . '}')
358+
);
320359
}
321360

322361
}

0 commit comments

Comments
 (0)