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

testGetNonExistingAttributeThrowsAttributeNotFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
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\Tests
9
 * @author    Mike van Riel <[email protected]>
10
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.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 phpDocumentor\GraphViz\AttributeNotFound;
18
use phpDocumentor\GraphViz\Node;
19
use PHPUnit\Framework\TestCase;
20
21
/**
22
 * Test for the the class representing a GraphViz node.
23
 *
24
 * @package phpDocumentor\GraphViz\Tests
25
 * @author  Mike van Riel <[email protected]>
26
 * @license http://www.opensource.org/licenses/mit-license.php MIT
27
 * @link    http://phpdoc.org
28
 */
29
class NodeTest extends TestCase
30
{
31
    /** @var Node */
32
    protected $fixture = null;
33
34
    /**
35
     * Initializes the fixture for this test.
36
     */
37
    protected function setUp()
38
    {
39
        $this->fixture = new Node('name', 'label');
40
    }
41
42
    /**
43
     * Tests the construct method
44
     *
45
     * @covers \phpDocumentor\GraphViz\Node::__construct
46
     *
47
     * @returnn void
48
     */
49
    public function testConstruct()
50
    {
51
        $fixture = new Node('MyName', 'MyLabel');
52
        $this->assertInstanceOf(
53
            Node::class,
54
            $fixture
55
        );
56
        $this->assertSame('MyName', $fixture->getName());
57
        $this->assertSame('MyLabel', $fixture->getLabel()->getValue());
0 ignored issues
show
Documentation Bug introduced by
The method getLabel does not exist on object<phpDocumentor\GraphViz\Node>? 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...
58
    }
59
60
    /**
61
     * Tests the create method
62
     *
63
     * @covers \phpDocumentor\GraphViz\Node::create
64
     *
65
     * @returnn void
66
     */
67
    public function testCreate()
68
    {
69
        $this->assertInstanceOf(
70
            Node::class,
71
            Node::create('name', 'label')
72
        );
73
    }
74
75
    /**
76
     * Tests the getting and setting of the name.
77
     *
78
     * @covers \phpDocumentor\GraphViz\Node::getName
79
     * @covers \phpDocumentor\GraphViz\Node::setName
80
     */
81
    public function testName()
82
    {
83
        $this->assertSame(
84
            $this->fixture->getName(),
85
            'name',
86
            'Expecting the name to match the initial state'
87
        );
88
        $this->assertSame(
89
            $this->fixture,
90
            $this->fixture->setName('otherName'),
91
            'Expecting a fluent interface'
92
        );
93
        $this->assertSame(
94
            $this->fixture->getName(),
95
            'otherName',
96
            'Expecting the name to contain the new value'
97
        );
98
    }
99
100
    /**
101
     * Tests the magic __call method, to work as described, return the object
102
     * instance for a setX method, return the value for an getX method, and null
103
     * for the remaining method calls
104
     *
105
     * @covers \phpDocumentor\GraphViz\Node::__call
106
     * @covers \phpDocumentor\GraphViz\Node::getAttribute
107
     * @covers \phpDocumentor\GraphViz\Node::setAttribute
108
     */
109
    public function testCall()
110
    {
111
        $fontname = 'Bitstream Vera Sans';
112
        $this->assertInstanceOf(Node::class, $this->fixture->setfontname($fontname));
0 ignored issues
show
Documentation Bug introduced by
The method setfontname does not exist on object<phpDocumentor\GraphViz\Node>? 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...
113
        $this->assertSame($fontname, $this->fixture->getfontname()->getValue());
0 ignored issues
show
Documentation Bug introduced by
The method getfontname does not exist on object<phpDocumentor\GraphViz\Node>? 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...
114
        $this->assertNull($this->fixture->someNonExistingMethod());
0 ignored issues
show
Documentation Bug introduced by
The method someNonExistingMethod does not exist on object<phpDocumentor\GraphViz\Node>? 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...
115
    }
116
117
    /**
118
     * @covers \phpDocumentor\GraphViz\Node::getAttribute
119
     */
120
    public function testGetNonExistingAttributeThrowsAttributeNotFound()
121
    {
122
        $this->expectException(AttributeNotFound::class);
123
        $this->expectExceptionMessage('Attribute with name "fontname" was not found');
124
125
        $this->fixture->getFontname();
0 ignored issues
show
Documentation Bug introduced by
The method getFontname does not exist on object<phpDocumentor\GraphViz\Node>? 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...
126
    }
127
128
    /**
129
     * Tests whether the magic __toString method returns a well formatted string
130
     * as specified in the DOT standard
131
     *
132
     * @covers \phpDocumentor\GraphViz\Node::__toString
133
     */
134
    public function testToString()
135
    {
136
        $this->fixture->setfontsize(12);
0 ignored issues
show
Documentation Bug introduced by
The method setfontsize does not exist on object<phpDocumentor\GraphViz\Node>? 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...
137
        $this->fixture->setfontname('Bitstream Vera Sans');
0 ignored issues
show
Documentation Bug introduced by
The method setfontname does not exist on object<phpDocumentor\GraphViz\Node>? 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...
138
139
        $dot = <<<DOT
140
"name" [
141
label="label"
142
fontsize="12"
143
fontname="Bitstream Vera Sans"
144
]
145
DOT;
146
147
        $this->assertSame($dot, (string) $this->fixture);
148
    }
149
150
    /**
151
     * Tests whether the magic __toString method returns a well formatted string
152
     * as specified in the DOT standard when the label contains slashes.
153
     *
154
     * @covers \phpDocumentor\GraphViz\Node::__toString
155
     */
156
    public function testToStringWithLabelContainingSlashes()
157
    {
158
        $this->fixture->setfontsize(12);
0 ignored issues
show
Documentation Bug introduced by
The method setfontsize does not exist on object<phpDocumentor\GraphViz\Node>? 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...
159
        $this->fixture->setfontname('Bitstream Vera Sans');
0 ignored issues
show
Documentation Bug introduced by
The method setfontname does not exist on object<phpDocumentor\GraphViz\Node>? 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...
160
        $this->fixture->setLabel('\phpDocumentor\Descriptor\ProjectDescriptor');
161
162
        $dot = <<<DOT
163
"name" [
164
label="\\\\phpDocumentor\\\\Descriptor\\\\ProjectDescriptor"
165
fontsize="12"
166
fontname="Bitstream Vera Sans"
167
]
168
DOT;
169
170
        $this->assertSame($dot, (string) $this->fixture);
171
    }
172
}
173