These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * phpDocumentor |
||
4 | * |
||
5 | * PHP Version 5.3 |
||
6 | * |
||
7 | * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
||
8 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
||
9 | * @link http://phpdoc.org |
||
10 | */ |
||
11 | |||
12 | namespace phpDocumentor\Transformer\Writer\Xml; |
||
13 | |||
14 | use Mockery as m; |
||
15 | use phpDocumentor\Descriptor\ConstantDescriptor; |
||
16 | use phpDocumentor\Descriptor\DescriptorAbstract; |
||
17 | |||
18 | /** |
||
19 | * Test class for \phpDocumentor\Transformer\Writer\Xml\ConstantConverter. |
||
20 | * |
||
21 | * @covers phpDocumentor\Transformer\Writer\Xml\ConstantConverter |
||
22 | */ |
||
23 | class ConstantConverterTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
||
24 | { |
||
25 | /** |
||
26 | * Tests whether the XML Element representing a constant is properly created. |
||
27 | * |
||
28 | * @covers phpDocumentor\Transformer\Writer\Xml\ConstantConverter::convert |
||
29 | */ |
||
30 | public function testConstantXmlElementIsCreated() |
||
31 | { |
||
32 | // Arrange |
||
33 | $constant = $this->createConstantDescriptorMock(); |
||
34 | $constantConverter = $this->createFixture($constant); |
||
35 | $parent = $this->prepareParentXMLElement(); |
||
36 | $parent->setAttribute('namespace', 'phpDocumentor'); |
||
37 | |||
38 | // Act |
||
39 | $convertedElement = $constantConverter->convert($parent, $constant); |
||
0 ignored issues
–
show
|
|||
40 | |||
41 | // Assert |
||
42 | $this->assertSame('100', $convertedElement->getAttribute('line')); |
||
43 | $this->assertSame('phpDocumentor', $convertedElement->getAttribute('namespace')); |
||
44 | $this->assertSame('Constant', $convertedElement->getElementsByTagName('name')->item(0)->nodeValue); |
||
45 | $this->assertSame( |
||
46 | 'phpDocumentor\Class::Constant', |
||
47 | $convertedElement->getElementsByTagName('full_name')->item(0)->nodeValue |
||
48 | ); |
||
49 | $this->assertSame('defaultString', $convertedElement->getElementsByTagName('value')->item(0)->nodeValue); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Tests whether the XML Element representing a constant is properly created. |
||
54 | * |
||
55 | * @covers phpDocumentor\Transformer\Writer\Xml\ConstantConverter::convert |
||
56 | */ |
||
57 | public function testNamespaceNameIsTakenFromNamespaceDescriptorIfPresent() |
||
58 | { |
||
59 | // Arrange |
||
60 | $parent = $this->prepareParentXMLElement(); |
||
61 | $namespaceDescriptor = m::mock('phpDocumentor\Descriptor\NamespaceDescriptor'); |
||
62 | $namespaceDescriptor->shouldReceive('getFullyQualifiedStructuralElementName')->andReturn('MySpace'); |
||
63 | $constant = $this->createConstantDescriptorMock(); |
||
64 | $constant->shouldReceive('getNamespace')->andReturn($namespaceDescriptor); |
||
65 | $constantConverter = $this->createFixture($constant); |
||
66 | |||
67 | // Act |
||
68 | $convertedElement = $constantConverter->convert($parent, $constant); |
||
0 ignored issues
–
show
$constant is of type object<Mockery\MockInter...tor\DescriptorAbstract> , but the function expects a object<phpDocumentor\Des...tor\ConstantDescriptor> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
69 | |||
70 | // Assert |
||
71 | $this->assertSame('MySpace', $convertedElement->getAttribute('namespace')); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Creates an XML Element that can serve as parent. |
||
76 | * |
||
77 | * @return \DOMElement |
||
78 | */ |
||
79 | protected function prepareParentXMLElement() |
||
80 | { |
||
81 | $document = new \DOMDocument(); |
||
82 | $parent = new \DOMElement('class'); |
||
83 | $document->appendChild($parent); |
||
84 | |||
85 | return $parent; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Creates a mock for the ConstantDescriptor class. |
||
90 | * |
||
91 | * @return m\MockInterface|DescriptorAbstract |
||
92 | */ |
||
93 | protected function createConstantDescriptorMock() |
||
94 | { |
||
95 | $constant = m::mock('phpDocumentor\\Descriptor\\ConstantDescriptor'); |
||
96 | $constant->shouldReceive('getLine')->andReturn(100); |
||
97 | $constant->shouldReceive('getName')->andReturn('Constant'); |
||
98 | $constant->shouldReceive('getFullyQualifiedStructuralElementName')->andReturn('phpDocumentor\Class::Constant'); |
||
99 | $constant->shouldReceive('getValue')->andReturn('defaultString'); |
||
100 | $constant->shouldIgnoreMissing(); |
||
101 | |||
102 | return $constant; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Creates the ConstantConverter fixture with a DocBlock mock. |
||
107 | * |
||
108 | * @return ConstantConverter |
||
109 | */ |
||
110 | protected function createFixture(ConstantDescriptor $constant) |
||
111 | { |
||
112 | $docBlockConverter = m::mock('phpDocumentor\Transformer\Writer\Xml\DocBlockConverter'); |
||
113 | $docBlockConverter->shouldReceive('convert')->with(m::type('DOMElement'), $constant); |
||
114 | |||
115 | return new ConstantConverter($docBlockConverter); |
||
116 | } |
||
117 | } |
||
118 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: