Passed
Pull Request — master (#412)
by
unknown
17:58 queued 15:20
created

WhenTestTrait::testWhenInternal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 2
dl 0
loc 16
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Tests\Rule\Base;
6
7
use Closure;
8
use Yiisoft\Validator\WhenInterface;
9
10
trait WhenTestTrait
11
{
12
    abstract public function testWhen(): void;
13
14
    private function testWhenInternal(WhenInterface $ruleWithoutWhen, WhenInterface $ruleWithWhen): void
15
    {
16
        $this->assertNull($ruleWithoutWhen->getWhen());
0 ignored issues
show
Bug introduced by
It seems like assertNull() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

16
        $this->/** @scrutinizer ignore-call */ 
17
               assertNull($ruleWithoutWhen->getWhen());
Loading history...
17
18
        $when = static fn (mixed $value): bool => $value !== null;
19
        $new = $ruleWithoutWhen->when($when);
20
        $this->assertNull($ruleWithoutWhen->getWhen());
21
        $this->assertInstanceOf(Closure::class, $new->getWhen());
0 ignored issues
show
Bug introduced by
It seems like assertInstanceOf() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

21
        $this->/** @scrutinizer ignore-call */ 
22
               assertInstanceOf(Closure::class, $new->getWhen());
Loading history...
22
        $this->assertNotSame($ruleWithoutWhen, $new);
0 ignored issues
show
Bug introduced by
It seems like assertNotSame() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

22
        $this->/** @scrutinizer ignore-call */ 
23
               assertNotSame($ruleWithoutWhen, $new);
Loading history...
23
24
        $this->assertInstanceOf(Closure::class, $ruleWithWhen->getWhen());
25
26
        $new = $ruleWithWhen->when(null);
27
        $this->assertInstanceOf(Closure::class, $ruleWithWhen->getWhen());
28
        $this->assertNull($new->getWhen());
29
        $this->assertNotSame($ruleWithWhen, $new);
30
    }
31
}
32