Failed Conditions
Push — master ( 528b1f...8f64a3 )
by Jonathan
09:23 queued 02:28
created

ClassMethodReferenceTest::testGetName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace UsageFinder\Tests;
6
7
use InvalidArgumentException;
8
use PHPUnit\Framework\TestCase;
9
use UsageFinder\ClassMethodReference;
10
11
final class ClassMethodReferenceTest extends TestCase
12
{
13
    public function testGetName() : void
14
    {
15
        self::assertSame(
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\Assert::assertSame() is not static, but was called statically. ( Ignorable by Annotation )

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

15
        self::/** @scrutinizer ignore-call */ 
16
              assertSame(
Loading history...
16
            'Doctrine\Common\Collections\Collection::slice',
0 ignored issues
show
Bug introduced by
'Doctrine\Common\Collections\Collection::slice' of type string is incompatible with the type PHPUnit\Framework\T expected by parameter $expected of PHPUnit\Framework\Assert::assertSame(). ( Ignorable by Annotation )

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

16
            /** @scrutinizer ignore-type */ 'Doctrine\Common\Collections\Collection::slice',
Loading history...
17
            (new ClassMethodReference('Doctrine\Common\Collections\Collection::slice'))->getName()
18
        );
19
    }
20
21
    public function testGetClassName() : void
22
    {
23
        self::assertSame(
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\Assert::assertSame() is not static, but was called statically. ( Ignorable by Annotation )

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

23
        self::/** @scrutinizer ignore-call */ 
24
              assertSame(
Loading history...
24
            'Doctrine\Common\Collections\Collection',
0 ignored issues
show
Bug introduced by
'Doctrine\Common\Collections\Collection' of type string is incompatible with the type PHPUnit\Framework\T expected by parameter $expected of PHPUnit\Framework\Assert::assertSame(). ( Ignorable by Annotation )

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

24
            /** @scrutinizer ignore-type */ 'Doctrine\Common\Collections\Collection',
Loading history...
25
            (new ClassMethodReference('Doctrine\Common\Collections\Collection::slice'))->getClassName()
26
        );
27
    }
28
29
    public function testGetMethodName() : void
30
    {
31
        self::assertSame(
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\Assert::assertSame() is not static, but was called statically. ( Ignorable by Annotation )

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

31
        self::/** @scrutinizer ignore-call */ 
32
              assertSame(
Loading history...
32
            'slice',
0 ignored issues
show
Bug introduced by
'slice' of type string is incompatible with the type PHPUnit\Framework\T expected by parameter $expected of PHPUnit\Framework\Assert::assertSame(). ( Ignorable by Annotation )

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

32
            /** @scrutinizer ignore-type */ 'slice',
Loading history...
33
            (new ClassMethodReference('Doctrine\Common\Collections\Collection::slice'))->getMethodName()
34
        );
35
    }
36
37
    /**
38
     * @dataProvider provideForTestInvalidClassMethodReference
39
     */
40
    public function testInvalidClassMethodReference(string $input, string $message) : void
41
    {
42
        self::expectException(InvalidArgumentException::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

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

42
        self::/** @scrutinizer ignore-call */ 
43
              expectException(InvalidArgumentException::class);
Loading history...
43
        self::expectExceptionMessage($message);
0 ignored issues
show
Bug introduced by
The method expectExceptionMessage() does not exist on UsageFinder\Tests\ClassMethodReferenceTest. Did you maybe mean expectException()? ( Ignorable by Annotation )

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

43
        self::/** @scrutinizer ignore-call */ 
44
              expectExceptionMessage($message);

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...
44
45
        new ClassMethodReference($input);
46
    }
47
48
    /**
49
     * @return array<int, array<int, string>>
50
     */
51
    public function provideForTestInvalidClassMethodReference() : array
52
    {
53
        return [
54
            [
55
                '',
56
                'Invalid ClassMethodReference, empty string given. Format must be ClassName::methodName.',
57
            ],
58
            [
59
                'Doctrine\Common\Collections\Collection::',
60
                'You must specify a method name to find. "Doctrine\Common\Collections\Collection::" given.',
61
            ],
62
            [
63
                'Doctrine\Common\Collections\Collection:: ',
64
                'You must specify a method name to find. "Doctrine\Common\Collections\Collection:: " given.',
65
            ],
66
            [
67
                'Doctrine\Common\Collections\Collection',
68
                'Invalid ClassMethodReference, "Doctrine\Common\Collections\Collection" given. Format must be ClassName::methodName.',
69
            ],
70
        ];
71
    }
72
}
73