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

tests/ClassMethodReferenceTest.php (1 issue)

Labels
Severity
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(
16
            'Doctrine\Common\Collections\Collection::slice',
17
            (new ClassMethodReference('Doctrine\Common\Collections\Collection::slice'))->getName()
18
        );
19
    }
20
21
    public function testGetClassName() : void
22
    {
23
        self::assertSame(
24
            'Doctrine\Common\Collections\Collection',
25
            (new ClassMethodReference('Doctrine\Common\Collections\Collection::slice'))->getClassName()
26
        );
27
    }
28
29
    public function testGetMethodName() : void
30
    {
31
        self::assertSame(
32
            'slice',
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);
43
        self::expectExceptionMessage($message);
0 ignored issues
show
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