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); |
||
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'); |
||
0 ignored issues
–
show
|
|||
63 | $constant = $this->createConstantDescriptorMock(); |
||
64 | $constant->shouldReceive('getNamespace')->andReturn($namespaceDescriptor); |
||
0 ignored issues
–
show
The method
shouldReceive does only exist in Mockery\MockInterface , but not in phpDocumentor\Descriptor\DescriptorAbstract .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
65 | $constantConverter = $this->createFixture($constant); |
||
66 | |||
67 | // Act |
||
68 | $convertedElement = $constantConverter->convert($parent, $constant); |
||
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); |
||
0 ignored issues
–
show
The method
andReturn does only exist in Mockery\ExpectationInterface , but not in Mockery\HigherOrderMessage .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
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 method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: