Completed
Pull Request — master (#26)
by Simon
02:52
created

testGetNonExistingAttributeThrowsAttributeNotFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * phpDocumentor
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @package   phpDocumentor\GraphViz\Test
9
 * @author    Danny van der Sluijs <[email protected]>
10
 * @copyright 2012-2018 Danny van der Sluijs (http://www.dannyvandersluijs.com)
11
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
12
 * @link      http://phpdoc.org
13
 */
14
15
namespace phpDocumentor\GraphViz\Test;
16
17
use Mockery as m;
18
use phpDocumentor\GraphViz\AttributeNotFound;
19
use phpDocumentor\GraphViz\Edge;
20
use phpDocumentor\GraphViz\Node;
21
use PHPUnit\Framework\TestCase;
22
23
/**
24
 * Test for the the class representing a GraphViz edge (vertex).
25
 *
26
 * @package phpDocumentor\GraphViz\Test
27
 * @author  Danny van der Sluijs <[email protected]>
28
 * @license http://www.opensource.org/licenses/mit-license.php MIT
29
 * @link    http://phpdoc.org
30
 */
31
class EdgeTest extends TestCase
32
{
33
    /**
34
     * Tears down the fixture, for example, closes a network connection.
35
     * This method is called after a test is executed.
36
     */
37
    protected function tearDown()
38
    {
39
        m::close();
40
    }
41
42
    /**
43
     * Tests the construct method
44
     *
45
     * @covers \phpDocumentor\GraphViz\Edge::__construct
46
     */
47
    public function testConstruct()
48
    {
49
        $fromNode = m::mock(Node::class);
50
        $toNode = m::mock(Node::class);
51
        $fixture = new Edge($fromNode, $toNode);
52
53
        $this->assertInstanceOf(
54
            Edge::class,
55
            $fixture
56
        );
57
        $this->assertSame(
58
            $fromNode,
59
            $fixture->getFrom()
60
        );
61
        $this->assertSame(
62
            $toNode,
63
            $fixture->getTo()
64
        );
65
    }
66
67
    /**
68
     * Tests the create method
69
     *
70
     * @covers \phpDocumentor\GraphViz\Edge::create
71
     */
72
    public function testCreate()
73
    {
74
        $this->assertInstanceOf(
75
            Edge::class,
76
            Edge::create(new Node('from'), new Node('to'))
77
        );
78
    }
79
80
    /**
81
     * Tests whether the getFrom method returns the same node as passed
82
     * in the create method
83
     *
84
     * @covers \phpDocumentor\GraphViz\Edge::getFrom
85
     */
86
    public function testGetFrom()
87
    {
88
        $from = new Node('from');
89
        $edge = Edge::create($from, new Node('to'));
90
        $this->assertSame($from, $edge->getFrom());
91
    }
92
93
    /**
94
     * Tests the getTo method returns the same node as passed
95
     * in the create method
96
     *
97
     * @covers \phpDocumentor\GraphViz\Edge::getTo
98
     */
99
    public function testGetTo()
100
    {
101
        $to = new Node('to');
102
        $edge = Edge::create(new Node('from'), $to);
103
        $this->assertSame($to, $edge->getTo());
104
    }
105
106
    /**
107
     * Tests the magic __call method, to work as described, return the object
108
     * instance for a setX method, return the value for an getX method, and null
109
     * for the remaining method calls
110
     *
111
     * @covers \phpDocumentor\GraphViz\Edge::__call
112
     * @covers \phpDocumentor\GraphViz\Edge::setAttribute
113
     * @covers \phpDocumentor\GraphViz\Edge::getAttribute
114
     */
115
    public function testCall()
116
    {
117
        $label = 'my label';
118
        $fixture = new Edge(new Node('from'), new Node('to'));
119
        $this->assertInstanceOf(Edge::class, $fixture->setLabel($label));
0 ignored issues
show
Documentation Bug introduced by
The method setLabel does not exist on object<phpDocumentor\GraphViz\Edge>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
120
        $this->assertSame($label, $fixture->getLabel()->getValue());
0 ignored issues
show
Documentation Bug introduced by
The method getLabel does not exist on object<phpDocumentor\GraphViz\Edge>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
121
        $this->assertNull($fixture->someNonExcistingMethod());
0 ignored issues
show
Documentation Bug introduced by
The method someNonExcistingMethod does not exist on object<phpDocumentor\GraphViz\Edge>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
122
    }
123
124
    /**
125
     * @covers \phpDocumentor\GraphViz\Edge::getAttribute
126
     */
127
    public function testGetNonExistingAttributeThrowsAttributeNotFound()
128
    {
129
        $fixture = new Edge(new Node('from'), new Node('to'));
130
131
        $this->expectException(AttributeNotFound::class);
132
        $this->expectExceptionMessage('Attribute with name "label" was not found');
133
134
        $fixture->getLabel();
0 ignored issues
show
Documentation Bug introduced by
The method getLabel does not exist on object<phpDocumentor\GraphViz\Edge>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
135
    }
136
137
    /**
138
     * Tests whether the magic __toString method returns a well formatted string
139
     * as specified in the DOT standard
140
     *
141
     * @covers \phpDocumentor\GraphViz\Edge::__toString
142
     */
143
    public function testToString()
144
    {
145
        $fixture = new Edge(new Node('from'), new Node('to'));
146
        $fixture->setLabel('MyLabel');
0 ignored issues
show
Documentation Bug introduced by
The method setLabel does not exist on object<phpDocumentor\GraphViz\Edge>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
147
        $fixture->setWeight(45);
0 ignored issues
show
Documentation Bug introduced by
The method setWeight does not exist on object<phpDocumentor\GraphViz\Edge>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
148
149
        $dot = <<<DOT
150
"from" -> "to" [
151
label="MyLabel"
152
weight="45"
153
]
154
DOT;
155
156
        $this->assertSame($dot, (string) $fixture);
157
    }
158
}
159