IG12913Test::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Filter\FilterInterface;
30
use Grafizzi\Graph\Node;
31
use Pimple\Container;
32
33
require 'vendor/autoload.php';
34
35
/**
36
 * A recreation of Image_GraphViz bug_12913.phpt
37
 *
38
 * Image_GraphViz version author: Philippe Jausions <[email protected]>
39
 *
40
 * Request 12913: "PEAR_Error on failure"
41
 *
42
 * Since Grafizzi is not a PEAR component, it can throw exceptions instead of
43
 * using PEAR errors, so the test applies to exceptions.
44
 */
45
class IG12913Test extends BaseGraphTest {
46
47
  /**
48
   *
49
   * @var \Grafizzi\Graph\Graph
50
   */
51
  public $Graph2;
52
53
  /**
54
   * @var \Pimple\Container
55
   */
56
  public $dic2;
57
58
  public function setUp() : void {
59
    parent::setUpExtended('G');
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setUpExtended() instead of setUp()). Are you sure this is correct? If so, you might want to change this to $this->setUpExtended().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
60
    $this->Graph2 = $this->Graph;
61
    $this->dic2 = $this->dic;
62
    $this->dic2['use_exceptions'] = false;
63
    unset($this->dic, $this->Graph);
64
65
    parent::setUpExtended('G');
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setUpExtended() instead of setUp()). Are you sure this is correct? If so, you might want to change this to $this->setUpExtended().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
66
    $this->dic['use_exceptions'] = true;
67
68
    $this->Graph->addChild($cluster1 = new Cluster($this->dic, 1));
69
    $cluster1->addChild($node1 = new Node($this->dic, 'Node1', array(
70
      new Attribute($this->dic, 'label', 'Node1'),
71
    )));
72
73
    $this->Graph2->addChild($cluster2 = new Cluster($this->dic2, 2));
74
    $cluster2->addChild($node2 = new Node($this->dic2, 'Node2', array(
75
      new Attribute($this->dic2, 'label', 'Node2'),
76
    )));
77
  }
78
79
  /**
80
   * @param DotFilter $filter
81
   * @param string $format
82
   */
83
  protected function withDicException(DotFilter $filter, $format) {
84
    try {
85
      $filter->image($format);
86
    }
87
    catch (\InvalidArgumentException $e) {
88
      $this->assertInstanceOf('InvalidArgumentException', $e, 'Invalid argument for invalid format.');
89
    }
90
  }
91
92
  /**
93
   * @param DotFilter $filter
94
   * @param string $format
95
   */
96
  protected function withDicNoException(DotFilter $filter, $format) {
97
    $result = $filter->image($format);
98
    $this->assertFalse($result, 'Unavailable format image.');
99
  }
100
101
  /**
102
   * Tests Graph->image()
103
   */
104
  public function testImage() {
105
    $dotFilter = new DotFilter();
106
    $format = DotFilterTest::INVALID_FORMAT;
107
    $this->withDicException($dotFilter->setDic(new Container(array('use_exceptions' => true))), $format);
108
    $this->withDicNoException($dotFilter->setDic(new Container(array('use_exceptions' => false))), $format);
109
  }
110
}
111