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\Router\UrlGenerator\Standard; |
||
13 | |||
14 | use Mockery as m; |
||
15 | |||
16 | /** |
||
17 | * Test for the ConstantDescriptor URL Generator with the Standard Router |
||
18 | */ |
||
19 | class ConstantDescriptorTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
||
20 | { |
||
21 | /** |
||
22 | * @codingStandardsIgnoreStart |
||
23 | * @covers phpDocumentor\Transformer\Router\UrlGenerator\Standard\ConstantDescriptor::__construct |
||
24 | * @covers phpDocumentor\Transformer\Router\UrlGenerator\Standard\ConstantDescriptor::__invoke |
||
25 | * @covers phpDocumentor\Transformer\Router\UrlGenerator\Standard\ConstantDescriptor::getUrlPathPrefixForGlobalConstants |
||
26 | * @covers phpDocumentor\Transformer\Router\UrlGenerator\Standard\QualifiedNameToUrlConverter::fromNamespace |
||
27 | * @codingStandardsIgnoreEnd |
||
28 | */ |
||
29 | public function testGenerateUrlForGlobalConstants() |
||
30 | { |
||
31 | // Arrange |
||
32 | $fixture = new ConstantDescriptor(); |
||
33 | $constantDescriptorMock = m::mock('phpDocumentor\Descriptor\ConstantDescriptor'); |
||
34 | $constantDescriptorMock |
||
0 ignored issues
–
show
|
|||
35 | ->shouldReceive('getParent')->andReturn(m::mock('phpDocumentor\Descriptor\FileDescriptor')); |
||
36 | $constantDescriptorMock->shouldReceive('getNamespace')->andReturn('My\\Space'); |
||
37 | $constantDescriptorMock->shouldReceive('getName')->andReturn('myConstant'); |
||
38 | |||
39 | // Act |
||
40 | $result = $fixture($constantDescriptorMock); |
||
41 | |||
42 | // Assert |
||
43 | $this->assertSame('/namespaces/My.Space.html#constant_myConstant', $result); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @codingStandardsIgnoreStart |
||
48 | * @covers phpDocumentor\Transformer\Router\UrlGenerator\Standard\ConstantDescriptor::__construct |
||
49 | * @covers phpDocumentor\Transformer\Router\UrlGenerator\Standard\ConstantDescriptor::__invoke |
||
50 | * @covers phpDocumentor\Transformer\Router\UrlGenerator\Standard\ConstantDescriptor::getUrlPathPrefixForGlobalConstants |
||
51 | * @covers phpDocumentor\Transformer\Router\UrlGenerator\Standard\QualifiedNameToUrlConverter::fromNamespace |
||
52 | * @codingStandardsIgnoreEnd |
||
53 | */ |
||
54 | public function testGenerateUrlForGlobalConstantsAtRootNamespace() |
||
55 | { |
||
56 | // Arrange |
||
57 | $fixture = new ConstantDescriptor(); |
||
58 | $constantDescriptorMock = m::mock('phpDocumentor\Descriptor\ConstantDescriptor'); |
||
59 | $constantDescriptorMock->shouldReceive('getParent')->andReturnNull(); |
||
60 | $constantDescriptorMock->shouldReceive('getNamespace')->andReturn('\\'); |
||
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...
|
|||
61 | $constantDescriptorMock->shouldReceive('getName')->andReturn('myConstant'); |
||
62 | |||
63 | // Act |
||
64 | $result = $fixture($constantDescriptorMock); |
||
65 | |||
66 | // Assert |
||
67 | $this->assertSame('/namespaces/default.html#constant_myConstant', $result); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @codingStandardsIgnoreStart |
||
72 | * @covers phpDocumentor\Transformer\Router\UrlGenerator\Standard\ConstantDescriptor::__invoke |
||
73 | * @covers phpDocumentor\Transformer\Router\UrlGenerator\Standard\ConstantDescriptor::getUrlPathPrefixForClassConstants |
||
74 | * @covers phpDocumentor\Transformer\Router\UrlGenerator\Standard\QualifiedNameToUrlConverter::fromClass |
||
75 | * @codingStandardsIgnoreEnd |
||
76 | */ |
||
77 | public function testGenerateUrlForClassConstants() |
||
78 | { |
||
79 | // Arrange |
||
80 | $fixture = new ConstantDescriptor(); |
||
81 | |||
82 | $classDescriptorMock = m::mock('phpDocumentor\Descriptor\ClassDescriptor'); |
||
83 | $classDescriptorMock->shouldReceive('getFullyQualifiedStructuralElementName')->andReturn('My\\Space\\Class'); |
||
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...
|
|||
84 | |||
85 | $constantDescriptorMock = m::mock('phpDocumentor\Descriptor\ConstantDescriptor'); |
||
86 | $constantDescriptorMock->shouldReceive('getParent')->andReturn($classDescriptorMock); |
||
87 | $constantDescriptorMock->shouldReceive('getName')->andReturn('myConstant'); |
||
88 | |||
89 | // Act |
||
90 | $result = $fixture($constantDescriptorMock); |
||
91 | |||
92 | // Assert |
||
93 | $this->assertSame('/classes/My.Space.Class.html#constant_myConstant', $result); |
||
94 | } |
||
95 | } |
||
96 |
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: