Skip to content

Commit

Permalink
Merge pull request #15 from stereomon/add-strict
Browse files Browse the repository at this point in the history
Allow strict graphs, add missing test for setPath, add missing doc block
  • Loading branch information
mvriel committed Feb 2, 2016
2 parents 95ed74e + dddfd60 commit a906a90
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/phpDocumentor/GraphViz/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();

Expand All @@ -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 = '';

/**
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -375,8 +401,10 @@ public function __toString()
}
$attributes = implode(PHP_EOL, $attributes);

$strict = ($this->isStrict() ? 'strict ' : '');

return <<<DOT
{$this->getType()} "{$this->getName()}" {
{$strict}{$this->getType()} "{$this->getName()}" {
$attributes
}
DOT;
Expand Down
39 changes: 39 additions & 0 deletions tests/phpDocumentor/GraphViz/Test/GraphTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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 . '}')
);
}

}

0 comments on commit a906a90

Please sign in to comment.