Failed Conditions
Pull Request — master (#3)
by Jonathan
01:51
created

FindClassMethodUsagesTest::testInvoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 0
dl 0
loc 27
rs 9.7333
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A FindClassMethodUsagesTest::testInvokeUsagesFoundConcreteClass() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace UsageFinder\Tests;
6
7
use PHPUnit\Framework\TestCase;
8
use Symfony\Component\Process\Process;
9
use UsageFinder\ClassMethodReference;
10
use UsageFinder\ClassMethodUsage;
11
use UsageFinder\FindClassMethodUsages;
12
use function file_exists;
13
14
final class FindClassMethodUsagesTest extends TestCase
15
{
16
    /** @var string */
17
    private $rootDir;
18
19
    public function testInvokeUsagesFoundConcreteClass() : void
20
    {
21
        $classMethodReference = new ClassMethodReference('Doctrine\Common\Collections\ArrayCollection::slice');
22
23
        $expectedUsages = [
24
            new ClassMethodUsage('src/AppCode.php', 14, '            ->slice(0, 1);', 'slice'),
25
            new ClassMethodUsage('src/AppCode.php', 20, '            ->slice(0, 3);', 'slice'),
26
        ];
27
28
        $examplePath = __DIR__ . '/example';
29
30
        $usages = (new FindClassMethodUsages())->
31
            __invoke($examplePath, $classMethodReference, 2);
32
33
        self::assertCount(2, $usages);
0 ignored issues
show
Bug introduced by
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

33
        self::/** @scrutinizer ignore-call */ 
34
              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...
34
        self::assertEquals($expectedUsages, $usages);
0 ignored issues
show
Bug introduced by
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

34
        self::/** @scrutinizer ignore-call */ 
35
              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...
35
    }
36
37
    public function testInvokeUsagesFoundInterface() : void
38
    {
39
        $classMethodReference = new ClassMethodReference('Doctrine\Common\Collections\Collection::slice');
40
41
        $expectedUsages = [
42
            new ClassMethodUsage('src/AppCode.php', 14, '            ->slice(0, 1);', 'slice'),
43
            new ClassMethodUsage('src/AppCode.php', 17, '            ->slice(0, 2);', 'slice'),
44
            new ClassMethodUsage('src/AppCode.php', 20, '            ->slice(0, 3);', 'slice'),
45
        ];
46
47
        $examplePath = __DIR__ . '/example';
48
49
        $usages = (new FindClassMethodUsages())->
50
            __invoke($examplePath, $classMethodReference, 2);
51
52
        self::assertCount(3, $usages);
53
        self::assertEquals($expectedUsages, $usages);
54
    }
55
56
    public function testInvokeNoUsagesFound() : void
57
    {
58
        $classMethodReference = new ClassMethodReference('Class::doesNotExist');
59
60
        $examplePath = __DIR__ . '/example';
61
62
        $usages = (new FindClassMethodUsages())->
63
            __invoke($examplePath, $classMethodReference, 2);
64
65
        self::assertCount(0, $usages);
66
    }
67
68
    public function testInvokeOnInvalidCode() : void
69
    {
70
        $classMethodReference = new ClassMethodReference('Class::doesNotExist');
71
72
        $examplePath = __DIR__ . '/invalid-code-example';
73
74
        $usages = (new FindClassMethodUsages())->
75
            __invoke($examplePath, $classMethodReference, 2);
76
77
        self::assertCount(0, $usages);
78
    }
79
80
    public function testInvokeNoProblems() : void
81
    {
82
        $classMethodReference = new ClassMethodReference('Class::doesNotExist');
83
84
        $examplePath = __DIR__ . '/no-problems-example';
85
86
        $usages = (new FindClassMethodUsages())->
87
            __invoke($examplePath, $classMethodReference, 2);
88
89
        self::assertCount(0, $usages);
90
    }
91
92
    protected function setUp() : void
93
    {
94
        $this->rootDir = __DIR__ . '/..';
95
        $composerPath  = $this->rootDir . '/composer.phar';
96
97
        if (! file_exists($composerPath)) {
98
            self::markTestSkipped('Download composer with the ./download-composer.sh shell script.');
0 ignored issues
show
Bug introduced by
The method markTestSkipped() 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

98
            self::/** @scrutinizer ignore-call */ 
99
                  markTestSkipped('Download composer with the ./download-composer.sh shell script.');

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...
99
        }
100
101
        $process = new Process(['php', $composerPath, 'install'], __DIR__ . '/example');
102
        $process->run();
103
    }
104
}
105