diff --git a/src/phpDocumentor/GraphViz/Graph.php b/src/phpDocumentor/GraphViz/Graph.php index fcca4dc..e933d74 100644 --- a/src/phpDocumentor/GraphViz/Graph.php +++ b/src/phpDocumentor/GraphViz/Graph.php @@ -24,7 +24,7 @@ * @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com) * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org - * + * * @method Graph setRankSep(string $rankSep) * @method Graph setCenter(string $center) * @method Graph setRank(string $rank) @@ -41,6 +41,9 @@ class Graph /** @var string Type of this graph; may be digraph, graph or subgraph */ protected $type = 'digraph'; + /** @var bool If the graph is strict then multiple edges are not allowed between the same pairs of nodes */ + protected $strict = false; + /** @var \phpDocumentor\GraphViz\Attribute[] A list of attributes for this Graph */ protected $attributes = array(); @@ -53,6 +56,7 @@ class Graph /** @var \phpDocumentor\GraphViz\Edge[] A list of edges / arrows for this Graph */ protected $edges = array(); + /** @var string The path to execute dot from */ protected $path = ''; /** @@ -148,6 +152,28 @@ public function getType() return $this->type; } + /** + * Set if the Graph should be strict. If the graph is strict then + * multiple edges are not allowed between the same pairs of nodes + * + * @param bool $isStrict + * + * @return \phpDocumentor\GraphViz\Graph + */ + public function setStrict($isStrict) + { + $this->strict = $isStrict; + return $this; + } + + /** + * @return bool + */ + public function isStrict() + { + return $this->strict; + } + /** * Magic method to provide a getter/setter to add attributes on the Graph. * @@ -375,8 +401,10 @@ public function __toString() } $attributes = implode(PHP_EOL, $attributes); + $strict = ($this->isStrict() ? 'strict ' : ''); + return <<getType()} "{$this->getName()}" { +{$strict}{$this->getType()} "{$this->getName()}" { $attributes } DOT; diff --git a/tests/phpDocumentor/GraphViz/Test/GraphTest.php b/tests/phpDocumentor/GraphViz/Test/GraphTest.php index 29d33c5..96d22e1 100644 --- a/tests/phpDocumentor/GraphViz/Test/GraphTest.php +++ b/tests/phpDocumentor/GraphViz/Test/GraphTest.php @@ -144,6 +144,39 @@ public function testGetType() ); } + public function testSetStrict() + { + $this->assertSame( + $this->fixture, $this->fixture->setStrict(true), + 'Expecting a fluent interface' + ); + $this->assertSame( + $this->fixture, $this->fixture->setStrict(false), + 'Expecting a fluent interface' + ); + } + + public function testIsStrict() + { + $this->assertSame( + $this->fixture->isStrict(), + false + ); + $this->fixture->setStrict(true); + $this->assertSame( + $this->fixture->isStrict(), + true + ); + } + + public function testSetPath() + { + $this->assertSame( + $this->fixture, $this->fixture->setPath(__DIR__), + 'Expecting a fluent interface' + ); + } + /** * @covers phpDocumentor\GraphViz\Graph::__call */ @@ -317,6 +350,12 @@ public function test__toString() (string) $graph, ('digraph "My First Graph" {' . PHP_EOL . 'label="PigeonPost"' . PHP_EOL . '}') ); + + $graph->setStrict(true); + $this->assertSame( + (string) $graph, + ('strict digraph "My First Graph" {' . PHP_EOL . 'label="PigeonPost"' . PHP_EOL . '}') + ); } }