These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * This file is part of 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 | * @copyright 2010-2018 Mike van Riel<[email protected]> |
||
9 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
||
10 | * @link http://phpdoc.org |
||
11 | */ |
||
12 | |||
13 | namespace phpDocumentor\Descriptor\Builder\Reflector; |
||
14 | |||
15 | use Mockery as m; |
||
16 | use phpDocumentor\Descriptor\MethodDescriptor; |
||
17 | use phpDocumentor\Descriptor\ProjectDescriptorBuilder; |
||
18 | use phpDocumentor\Reflection\Fqsen; |
||
19 | use phpDocumentor\Reflection\Php\Method; |
||
20 | use phpDocumentor\Reflection\Php\Trait_; |
||
21 | |||
22 | /** |
||
23 | * @coversDefaultClass \phpDocumentor\Descriptor\Builder\Reflector\TraitAssembler |
||
24 | * @covers ::<private> |
||
25 | */ |
||
26 | class TraitAssemblerTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
||
27 | { |
||
28 | /** |
||
29 | * @covers ::create |
||
30 | */ |
||
31 | public function testAssembleTraitWithMethod() |
||
32 | { |
||
33 | $method = new MethodDescriptor(); |
||
34 | $method->setName('method'); |
||
35 | $builder = m::mock(ProjectDescriptorBuilder::class); |
||
36 | $builder->shouldReceive('buildDescriptor')->andReturn($method); |
||
0 ignored issues
–
show
|
|||
37 | |||
38 | $traitFqsen = new Fqsen('\My\Space\MyTrait'); |
||
39 | $trait = new Trait_($traitFqsen); |
||
40 | $trait->addMethod(new Method(new Fqsen('\My\Space\MyTrait::method()'))); |
||
41 | $assembler = new TraitAssembler(); |
||
42 | $assembler->setBuilder($builder); |
||
43 | |||
44 | $result = $assembler->create($trait); |
||
45 | |||
46 | static::assertEquals('\My\Space', $result->getNamespace()); |
||
47 | static::assertSame($traitFqsen, $result->getFullyQualifiedStructuralElementName()); |
||
48 | static::assertEquals('MyTrait', $result->getName()); |
||
49 | static::assertInstanceOf(MethodDescriptor::class, $result->getMethods()->get('method', false)); |
||
50 | } |
||
51 | } |
||
52 |
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: