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

ExcludeInternalTraitTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testNormalTraitsAreNotExcluded() 0 24 1
A testInternalTraitsAreExcluded() 0 22 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\TraitBased;
6
7
use PHPUnit\Framework\TestCase;
8
use Roave\BackwardCompatibility\Change;
9
use Roave\BackwardCompatibility\Changes;
10
use Roave\BackwardCompatibility\DetectChanges\BCBreak\TraitBased\ExcludeInternalTrait;
11
use Roave\BackwardCompatibility\DetectChanges\BCBreak\TraitBased\TraitBased;
12
use Roave\BetterReflection\BetterReflection;
13
use Roave\BetterReflection\Reflector\ClassReflector;
14
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator;
15
16
/** @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\TraitBased\ExcludeInternalTrait */
17
final class ExcludeInternalTraitTest extends TestCase
18
{
19
    public function testNormalTraitsAreNotExcluded() : void
20
    {
21
        $locator    = (new BetterReflection())->astLocator();
22
        $reflector  = new ClassReflector(new StringSourceLocator(
23
            <<<'PHP'
24
<?php
25
26
trait ANormalTrait {}
27
PHP
28
            ,
29
            $locator
30
        ));
31
        $reflection = $reflector->reflect('ANormalTrait');
32
33
        $check = $this->createMock(TraitBased::class);
34
        $check->expects(self::once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

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

34
        $check->/** @scrutinizer ignore-call */ 
35
                expects(self::once())

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...
Bug introduced by
The method once() does not exist on RoaveTest\BackwardCompat...xcludeInternalTraitTest. ( Ignorable by Annotation )

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

34
        $check->expects(self::/** @scrutinizer ignore-call */ once())

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
              ->method('__invoke')
36
              ->with($reflection, $reflection)
37
              ->willReturn(Changes::fromList(Change::removed('foo', true)));
38
39
        self::assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not exist on RoaveTest\BackwardCompat...xcludeInternalTraitTest. 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

39
        self::/** @scrutinizer ignore-call */ 
40
              assertEquals(

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...
40
            Changes::fromList(Change::removed('foo', true)),
41
            (new ExcludeInternalTrait($check))
42
                ->__invoke($reflection, $reflection)
43
        );
44
    }
45
46
    public function testInternalTraitsAreExcluded() : void
47
    {
48
        $locator    = (new BetterReflection())->astLocator();
49
        $reflector  = new ClassReflector(new StringSourceLocator(
50
            <<<'PHP'
51
<?php
52
53
/** @internal */
54
trait AnInternalTrait {}
55
PHP
56
            ,
57
            $locator
58
        ));
59
        $reflection = $reflector->reflect('AnInternalTrait');
60
61
        $check = $this->createMock(TraitBased::class);
62
        $check->expects(self::never())->method('__invoke');
0 ignored issues
show
Bug introduced by
The method never() does not exist on RoaveTest\BackwardCompat...xcludeInternalTraitTest. ( Ignorable by Annotation )

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

62
        $check->expects(self::/** @scrutinizer ignore-call */ never())->method('__invoke');

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...
63
64
        self::assertEquals(
65
            Changes::empty(),
66
            (new ExcludeInternalTrait($check))
67
                ->__invoke($reflection, $reflection)
68
        );
69
    }
70
}
71