GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 4.2-to-master ( ed215f )
by E
06:47
created

AutocompleteElementsTest::testGetElementsClasses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ApiGen\Parser\Tests\Elements;
4
5
use ApiGen\Contracts\Parser\Elements\ElementStorageInterface;
6
use ApiGen\Contracts\Parser\Reflection\ClassReflectionInterface;
7
use ApiGen\Contracts\Parser\Reflection\ConstantReflectionInterface;
8
use ApiGen\Contracts\Parser\Reflection\FunctionReflectionInterface;
9
use ApiGen\Contracts\Parser\Reflection\MethodReflectionInterface;
10
use ApiGen\Contracts\Parser\Reflection\PropertyReflectionInterface;
11
use ApiGen\Parser\Elements\AutocompleteElements;
12
use PHPUnit\Framework\TestCase;
13
use PHPUnit_Framework_MockObject_MockObject;
14
15
final class AutocompleteElementsTest extends TestCase
16
{
17
    /**
18
     * @var AutocompleteElements
19
     */
20
    private $autocompleteElements;
21
22
    protected function setUp(): void
23
    {
24
        $elementsStorageMock = $this->createElementStorageMock();
25
        $this->autocompleteElements = new AutocompleteElements($elementsStorageMock);
0 ignored issues
show
Bug introduced by
It seems like $elementsStorageMock defined by $this->createElementStorageMock() on line 24 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, ApiGen\Parser\Elements\A...Elements::__construct() does only seem to accept object<ApiGen\Contracts\...lementStorageInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
26
    }
27
28
    public function testGetElementsClasses(): void
29
    {
30
        $elements = $this->autocompleteElements->getElements();
31
        $this->assertSame([
32
            ['c', 'ClassPrettyName'],
33
            ['p', 'ClassPrettyName::$propertyName'],
34
            ['m', 'ClassPrettyName::methodName'],
35
            ['co', 'ConstantPrettyName'],
36
            ['f', 'FunctionPrettyName'],
37
        ], $elements);
38
    }
39
40
    /**
41
     * @return PHPUnit_Framework_MockObject_MockObject|ElementStorageInterface
42
     */
43
    private function createElementStorageMock()
44
    {
45
        $classReflectionMock = $this->createMock(ClassReflectionInterface::class);
46
        $classReflectionMock->method('getPrettyName')
47
            ->willReturn('ClassPrettyName');
48
        $classReflectionMock->method('getOwnConstants')
49
            ->willReturn([]);
50
51
        $methodReflection = $this->createMock(MethodReflectionInterface::class);
52
        $methodReflection->method('getPrettyName')
53
            ->willReturn('ClassPrettyName::methodName');
54
        $classReflectionMock->method('getOwnMethods')
55
            ->willReturn([$methodReflection]);
56
57
        $propertyReflection = $this->createMock(PropertyReflectionInterface::class);
58
        $propertyReflection->method('getPrettyName')
59
            ->willReturn('ClassPrettyName::$propertyName');
60
        $classReflectionMock->method('getOwnProperties')
61
            ->willReturn([$propertyReflection]);
62
63
        $constantReflectionMock = $this->createMock(ConstantReflectionInterface::class);
64
        $constantReflectionMock->method('getPrettyName')
65
            ->willReturn('ConstantPrettyName');
66
67
        $functionReflectionMock = $this->createMock(FunctionReflectionInterface::class);
68
        $functionReflectionMock->method('getPrettyName')
69
            ->willReturn('FunctionPrettyName');
70
71
        $elementsStorageMock = $this->createMock(ElementStorageInterface::class);
72
        $elementsStorageMock->method('getElements')
73
            ->willReturn([
74
                'classes' => [$classReflectionMock],
75
                'constants' => [$constantReflectionMock],
76
                'functions' => [$functionReflectionMock]
77
            ]);
78
        return $elementsStorageMock;
79
    }
80
}
81