Completed
Push — master ( 85853a...5df06c )
by James
20s queued 12s
created

ClassBecameInternalTest::classesToBeTested()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 25
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 52
rs 9.52

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\ClassBased;
6
7
use PHPUnit\Framework\TestCase;
8
use Roave\BackwardCompatibility\Change;
9
use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\ClassBecameInternal;
10
use Roave\BetterReflection\BetterReflection;
11
use Roave\BetterReflection\Reflection\ReflectionClass;
12
use Roave\BetterReflection\Reflector\ClassReflector;
13
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator;
14
use function array_map;
15
use function iterator_to_array;
16
17
/** @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\ClassBecameInternal */
18
final class ClassBecameInternalTest extends TestCase
19
{
20
    /**
21
     * @param string[] $expectedMessages
22
     *
23
     * @dataProvider classesToBeTested
24
     */
25
    public function testDiffs(
26
        ReflectionClass $fromClass,
27
        ReflectionClass $toClass,
28
        array $expectedMessages
29
    ) : void {
30
        $changes = (new ClassBecameInternal())
31
            ->__invoke($fromClass, $toClass);
32
33
        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

33
        self::/** @scrutinizer ignore-call */ 
34
              assertSame(
Loading history...
34
            $expectedMessages,
0 ignored issues
show
Bug introduced by
$expectedMessages 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

34
            /** @scrutinizer ignore-type */ $expectedMessages,
Loading history...
35
            array_map(static function (Change $change) : string {
36
                return $change->__toString();
37
            }, iterator_to_array($changes))
38
        );
39
    }
40
41
    /**
42
     * @return array<string, array<int, ReflectionClass|array<int, string>>>
43
     *
44
     * @psalm-return array<string, array{0: ReflectionClass, 1: ReflectionClass, 2: array<int, string>}>
45
     */
46
    public function classesToBeTested() : array
47
    {
48
        $locator       = (new BetterReflection())->astLocator();
49
        $fromReflector = new ClassReflector(new StringSourceLocator(
50
            <<<'PHP'
51
<?php
52
53
class A {}
54
class B {}
55
/** @internal */
56
class C {}
57
/** @internal */
58
class D {}
59
PHP
60
            ,
61
            $locator
62
        ));
63
        $toReflector   = new ClassReflector(new StringSourceLocator(
64
            <<<'PHP'
65
<?php
66
67
class A {}
68
/** @internal */
69
class B {}
70
/** @internal */
71
class C {}
72
class D {}
73
PHP
74
            ,
75
            $locator
76
        ));
77
78
        return [
79
            'A' => [
80
                $fromReflector->reflect('A'),
81
                $toReflector->reflect('A'),
82
                [],
83
            ],
84
            'B' => [
85
                $fromReflector->reflect('B'),
86
                $toReflector->reflect('B'),
87
                ['[BC] CHANGED: B was marked "@internal"'],
88
            ],
89
            'C' => [
90
                $fromReflector->reflect('C'),
91
                $toReflector->reflect('C'),
92
                [],
93
            ],
94
            'D' => [
95
                $fromReflector->reflect('D'),
96
                $toReflector->reflect('D'),
97
                [],
98
            ],
99
        ];
100
    }
101
}
102