Issues (35)

tests/FindClassMethodUsagesTest.php (2 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace UsageFinder\Tests;
6
7
use UsageFinder\ClassMethodReference;
8
use UsageFinder\ClassMethodUsage;
9
use UsageFinder\FindClassMethodUsages;
10
11
final class FindClassMethodUsagesTest extends TestCase
12
{
13
    public function testInvokeUsagesFoundConcreteClass() : void
14
    {
15
        $classMethodReference = new ClassMethodReference('Doctrine\Common\Collections\ArrayCollection::slice');
16
17
        $expectedUsages = [
18
            new ClassMethodUsage('src/AppCode.php', 14, '            ->slice(0, 1);', 'slice'),
19
            new ClassMethodUsage('src/AppCode.php', 20, '            ->slice(0, 3);', 'slice'),
20
        ];
21
22
        $examplePath = __DIR__ . '/example';
23
24
        $usages = (new FindClassMethodUsages())->
25
            __invoke($examplePath, $classMethodReference, 2);
26
27
        self::assertCount(2, $usages);
0 ignored issues
show
The method assertCount() does not exist on UsageFinder\Tests\FindClassMethodUsagesTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        self::/** @scrutinizer ignore-call */ 
28
              assertCount(2, $usages);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
        self::assertEquals($expectedUsages, $usages);
0 ignored issues
show
The method assertEquals() does not exist on UsageFinder\Tests\FindClassMethodUsagesTest. Did you maybe mean assertFalse()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        self::/** @scrutinizer ignore-call */ 
29
              assertEquals($expectedUsages, $usages);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
    }
30
31
    public function testInvokeUsagesFoundInterface() : void
32
    {
33
        $classMethodReference = new ClassMethodReference('Doctrine\Common\Collections\Collection::slice');
34
35
        $expectedUsages = [
36
            new ClassMethodUsage('src/AppCode.php', 14, '            ->slice(0, 1);', 'slice'),
37
            new ClassMethodUsage('src/AppCode.php', 17, '            ->slice(0, 2);', 'slice'),
38
            new ClassMethodUsage('src/AppCode.php', 20, '            ->slice(0, 3);', 'slice'),
39
        ];
40
41
        $examplePath = __DIR__ . '/example';
42
43
        $usages = (new FindClassMethodUsages())->
44
            __invoke($examplePath, $classMethodReference, 2);
45
46
        self::assertCount(3, $usages);
47
        self::assertEquals($expectedUsages, $usages);
48
    }
49
50
    public function testInvokeNoUsagesFound() : void
51
    {
52
        $classMethodReference = new ClassMethodReference('Class::doesNotExist');
53
54
        $examplePath = __DIR__ . '/example';
55
56
        $usages = (new FindClassMethodUsages())->
57
            __invoke($examplePath, $classMethodReference, 2);
58
59
        self::assertCount(0, $usages);
60
    }
61
62
    public function testInvokeOnInvalidCode() : void
63
    {
64
        $classMethodReference = new ClassMethodReference('Class::doesNotExist');
65
66
        $examplePath = __DIR__ . '/invalid-code-example';
67
68
        $usages = (new FindClassMethodUsages())->
69
            __invoke($examplePath, $classMethodReference, 2);
70
71
        self::assertCount(0, $usages);
72
    }
73
74
    public function testInvokeNoProblems() : void
75
    {
76
        $classMethodReference = new ClassMethodReference('Class::doesNotExist');
77
78
        $examplePath = __DIR__ . '/no-problems-example';
79
80
        $usages = (new FindClassMethodUsages())->
81
            __invoke($examplePath, $classMethodReference, 2);
82
83
        self::assertCount(0, $usages);
84
    }
85
}
86