This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /** |
||
6 | * phpDocumentor |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | * |
||
11 | * @link http://phpdoc.org |
||
12 | */ |
||
13 | |||
14 | namespace phpDocumentor\GraphViz\Test; |
||
15 | |||
16 | use phpDocumentor\GraphViz\AttributeNotFound; |
||
17 | use phpDocumentor\GraphViz\Node; |
||
18 | use PHPUnit\Framework\TestCase; |
||
19 | |||
20 | /** |
||
21 | * Test for the the class representing a GraphViz node. |
||
22 | */ |
||
23 | class NodeTest extends TestCase |
||
24 | { |
||
25 | /** @var Node */ |
||
26 | protected $fixture = null; |
||
27 | |||
28 | /** |
||
29 | * Initializes the fixture for this test. |
||
30 | */ |
||
31 | protected function setUp() : void |
||
32 | { |
||
33 | $this->fixture = new Node('name', 'label'); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Tests the construct method |
||
38 | * |
||
39 | * @covers \phpDocumentor\GraphViz\Node::__construct |
||
40 | * @returnn void |
||
41 | */ |
||
42 | public function testConstruct() : void |
||
43 | { |
||
44 | $fixture = new Node('MyName', 'MyLabel'); |
||
45 | $this->assertInstanceOf( |
||
46 | Node::class, |
||
47 | $fixture |
||
48 | ); |
||
49 | $this->assertSame('MyName', $fixture->getName()); |
||
50 | $this->assertSame('MyLabel', $fixture->getLabel()->getValue()); |
||
0 ignored issues
–
show
|
|||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Tests the create method |
||
55 | * |
||
56 | * @covers \phpDocumentor\GraphViz\Node::create |
||
57 | * @returnn void |
||
58 | */ |
||
59 | public function testCreate() : void |
||
60 | { |
||
61 | $this->assertInstanceOf( |
||
62 | Node::class, |
||
63 | Node::create('name', 'label') |
||
64 | ); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Tests the getting and setting of the name. |
||
69 | * |
||
70 | * @covers \phpDocumentor\GraphViz\Node::getName |
||
71 | * @covers \phpDocumentor\GraphViz\Node::setName |
||
72 | */ |
||
73 | public function testName() : void |
||
74 | { |
||
75 | $this->assertSame( |
||
76 | $this->fixture->getName(), |
||
77 | 'name', |
||
78 | 'Expecting the name to match the initial state' |
||
79 | ); |
||
80 | $this->assertSame( |
||
81 | $this->fixture, |
||
82 | $this->fixture->setName('otherName'), |
||
83 | 'Expecting a fluent interface' |
||
84 | ); |
||
85 | $this->assertSame( |
||
86 | $this->fixture->getName(), |
||
87 | 'otherName', |
||
88 | 'Expecting the name to contain the new value' |
||
89 | ); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Tests the magic __call method, to work as described, return the object |
||
94 | * instance for a setX method, return the value for an getX method, and null |
||
95 | * for the remaining method calls |
||
96 | * |
||
97 | * @covers \phpDocumentor\GraphViz\Node::__call |
||
98 | * @covers \phpDocumentor\GraphViz\Node::getAttribute |
||
99 | * @covers \phpDocumentor\GraphViz\Node::setAttribute |
||
100 | */ |
||
101 | public function testCall() : void |
||
102 | { |
||
103 | $fontname = 'Bitstream Vera Sans'; |
||
104 | $this->assertInstanceOf(Node::class, $this->fixture->setfontname($fontname)); |
||
105 | $this->assertSame($fontname, $this->fixture->getfontname()->getValue()); |
||
0 ignored issues
–
show
The method
getfontname does not exist on object<phpDocumentor\GraphViz\Node> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when 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...
|
|||
106 | $this->assertNull($this->fixture->someNonExistingMethod()); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @covers \phpDocumentor\GraphViz\Node::getAttribute |
||
111 | * @covers \phpDocumentor\GraphViz\AttributeNotFound::__construct |
||
112 | */ |
||
113 | public function testGetNonExistingAttributeThrowsAttributeNotFound() : void |
||
114 | { |
||
115 | $this->expectException(AttributeNotFound::class); |
||
116 | $this->expectExceptionMessage('Attribute with name "fontname" was not found'); |
||
117 | |||
118 | $this->fixture->getFontname(); |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Tests whether the magic __toString method returns a well formatted string |
||
123 | * as specified in the DOT standard |
||
124 | * |
||
125 | * @covers \phpDocumentor\GraphViz\Node::__toString |
||
126 | */ |
||
127 | public function testToString() : void |
||
128 | { |
||
129 | $this->fixture->setfontsize(12); |
||
0 ignored issues
–
show
The method
setfontsize does not exist on object<phpDocumentor\GraphViz\Node> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when 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...
|
|||
130 | $this->fixture->setfontname('Bitstream Vera Sans'); |
||
0 ignored issues
–
show
The method
setfontname does not exist on object<phpDocumentor\GraphViz\Node> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when 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...
|
|||
131 | |||
132 | $dot = <<<DOT |
||
133 | "name" [ |
||
134 | label="label" |
||
135 | fontsize="12" |
||
136 | fontname="Bitstream Vera Sans" |
||
137 | ] |
||
138 | DOT; |
||
139 | |||
140 | $this->assertSame($dot, (string) $this->fixture); |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * Tests whether the magic __toString method returns a well formatted string |
||
145 | * as specified in the DOT standard when the label contains slashes. |
||
146 | * |
||
147 | * @covers \phpDocumentor\GraphViz\Node::__toString |
||
148 | */ |
||
149 | public function testToStringWithLabelContainingSlashes() : void |
||
150 | { |
||
151 | $this->fixture->setfontsize(12); |
||
152 | $this->fixture->setfontname('Bitstream Vera Sans'); |
||
153 | $this->fixture->setLabel('\phpDocumentor\Descriptor\ProjectDescriptor'); |
||
154 | |||
155 | $dot = <<<DOT |
||
156 | "name" [ |
||
157 | label="\\\\phpDocumentor\\\\Descriptor\\\\ProjectDescriptor" |
||
158 | fontsize="12" |
||
159 | fontname="Bitstream Vera Sans" |
||
160 | ] |
||
161 | DOT; |
||
162 | |||
163 | $this->assertSame($dot, (string) $this->fixture); |
||
164 | } |
||
165 | } |
||
166 |
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: