BaseGraphTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 49
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpExtended() 0 10 1
A check() 0 5 1
A tearDown() 0 4 1
1
<?php
2
3
/**
4
 * @file
5
 * Grafizzi\Graph\Tests\BaseGraphTest: 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
25
namespace Grafizzi\Graph\Tests;
26
27
require 'vendor/autoload.php';
28
29
use \Grafizzi\Graph\Graph;
30
31
use \Monolog\Logger;
32
use \Monolog\Handler\StreamHandler;
33
34
use PHPUnit\Framework\TestCase;
35
use Pimple\Container;
36
37
/**
38
 * Base test case.
39
 *
40
 * Build a graph that all other test cases will need.
41
 */
42
abstract class BaseGraphTest extends TestCase {
43
44
  /**
45
   *
46
   * @var Graph
47
   */
48
  public $Graph;
49
50
  /**
51
   * @var \Pimple\Container
52
   */
53
  public $dic;
54
55
  /**
56
   * Prepares the environment before running a test.
57
   */
58
  protected function setUpExtended($name = 'G', $attributes = array()) {
59
    parent::setUp();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setUp() instead of setUpExtended()). Are you sure this is correct? If so, you might want to change this to $this->setUp().

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
61
    $log = new Logger(basename(__FILE__, '.php'));
62
    $log->pushHandler(new StreamHandler('php://stderr', Logger::INFO));
63
    $this->dic = new Container(array(
64
      'logger' => $log,
65
    ));
66
    $this->Graph = new Graph($this->dic, $name, $attributes);
67
  }
68
69
  /**
70
   * Helper function for testBuild() method.
71
   *
72
   * @param string $expected
73
   *   A DOT source.
74
   * @param string $message
75
   *   The assertion message.
76
   */
77
  public function check($expected, $message) {
78
    $build = $this->Graph->build();
79
    $this->Graph->logger->debug("\n\n$build\n\n");
80
    $this->assertEquals($expected, $build, $message);
81
  }
82
83
  /**
84
   * Cleans up the environment after running a test.
85
   */
86
  protected function tearDown() : void {
87
    $this->Graph = null;
88
    parent::tearDown();
89
  }
90
}
91