Completed
Push — master ( 253fc3...1c697f )
by Frédéric G.
03:50
created

IG12913Test::testImage()   B

Complexity

Conditions 3
Paths 9

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3.0175

Importance

Changes 5
Bugs 1 Features 0
Metric Value
c 5
b 1
f 0
dl 0
loc 25
ccs 14
cts 16
cp 0.875
rs 8.8571
cc 3
eloc 17
nc 9
nop 0
crap 3.0175
1
<?php
2
3
/**
4
 * @file
5
 * Grafizzi\Graph\Tests\IG12913Test: a component of the Grafizzi library.
6
 *
7
 * (c) 2012 Frédéric G. MARAND <[email protected]>
8
 *
9
 * Grafizzi is free software: you can redistribute it and/or modify it under the
10
 * terms of the GNU Lesser General Public License as published by the Free
11
 * Software Foundation, either version 3 of the License, or (at your option) any
12
 * later version.
13
 *
14
 * Grafizzi is distributed in the hope that it will be useful, but WITHOUT ANY
15
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16
 * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
17
 * details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20
 * along with Grafizzi, in the COPYING.LESSER.txt file.  If not, see
21
 * <http://www.gnu.org/licenses/>
22
 */
23
24
namespace Grafizzi\Graph\Tests;
25
26
use Grafizzi\Graph\Attribute;
27
use Grafizzi\Graph\Cluster;
28
use Grafizzi\Graph\Filter\DotFilter;
29
use Grafizzi\Graph\Node;
30
use Pimple\Container;
31
32
require 'vendor/autoload.php';
33
34
/**
35
 * A recreation of Image_GraphViz bug_12913.phpt
36
 *
37
 * Image_GraphViz version author: Philippe Jausions <[email protected]>
38
 *
39
 * Request 12913: "PEAR_Error on failure"
40
 *
41
 * Since Grafizzi is not a PEAR component, it can throw exceptions instead of
42
 * using PEAR errors, so the test applies to exceptions.
43
 */
44
class IG12913Test extends BaseGraphTest {
45
46
  /**
47
   *
48
   * @var \Grafizzi\Graph\Graph
49
   */
50
  public $Graph2;
51
52
  /**
53
   * @var \Pimple\Container
54
   */
55
  public $dic2;
56
57 1
  public function setUp($name = 'G', $attributes = array()) {
58 1
    parent::setUp('G');
59 1
    $this->Graph2 = $this->Graph;
60 1
    $this->dic2 = $this->dic;
61 1
    $this->dic2['use_exceptions'] = false;
62 1
    unset($this->dic, $this->Graph);
63
64 1
    parent::setUp('G');
65 1
    $this->dic['use_exceptions'] = true;
66
67 1
    $this->Graph->addChild($cluster1 = new Cluster($this->dic, 1));
68 1
    $cluster1->addChild($node1 = new Node($this->dic, 'Node1', array(
69 1
      new Attribute($this->dic, 'label', 'Node1'),
70 1
    )));
71
72 1
    $this->Graph2->addChild($cluster2 = new Cluster($this->dic2, 2));
73 1
    $cluster2->addChild($node2 = new Node($this->dic2, 'Node2', array(
74 1
      new Attribute($this->dic2, 'label', 'Node2'),
75 1
    )));
76 1
  }
77
78
  /**
79
   * Tests Graph->image()
80
   */
81 1
  public function testImage() {
82 1
    $dotFilter = new DotFilter();
83 1
    $dic = new Container(array('use_exceptions' => true));
84 1
    $dotFilter->setDic($dic);
85
86 1
    $format = DotFilterTest::INVALID_FORMAT;
87
88
    try {
89 1
      $dotFilter->image($format);
90
      $this->fail('Invalid format image did not throw an exception.');
91
    }
92 1
    catch (\InvalidArgumentException $e) {
93 1
      $this->assertInstanceOf('InvalidArgumentException', $e, 'Invalid argument for invalid format.');
94
    }
95
96 1
    $dic = new Container(array('use_exceptions' => false));
97 1
    $dotFilter->setDic($dic);
98
    try {
99 1
      $result = $dotFilter->image($format);
100 1
      $this->assertFalse($result, 'Unavailable format image.');
101
    }
102 1
    catch (\InvalidArgumentException $e) {
103
      $this->fail('Invalid format image threw an exception.');
104
    }
105 1
  }
106
}
107