SkipOnEmptyNormalizerTest::normalizeData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Tests\Helper;
6
7
use Closure;
8
use InvalidArgumentException;
9
use PHPUnit\Framework\TestCase;
10
use Yiisoft\Validator\EmptyCondition\NeverEmpty;
11
use Yiisoft\Validator\EmptyCondition\WhenEmpty;
12
use Yiisoft\Validator\Helper\SkipOnEmptyNormalizer;
13
14
final class SkipOnEmptyNormalizerTest extends TestCase
15
{
16
    public function normalizeData(): array
17
    {
18
        return [
19
            [null, NeverEmpty::class],
20
            [false, NeverEmpty::class],
21
            [true, WhenEmpty::class],
22
            [static fn (mixed $value, bool $isAttributeMissing): bool => true, Closure::class],
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

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

22
            [static fn (/** @scrutinizer ignore-unused */ mixed $value, bool $isAttributeMissing): bool => true, Closure::class],

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $isAttributeMissing is not used and could be removed. ( Ignorable by Annotation )

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

22
            [static fn (mixed $value, /** @scrutinizer ignore-unused */ bool $isAttributeMissing): bool => true, Closure::class],

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
        ];
24
    }
25
26
    /**
27
     * @dataProvider normalizeData
28
     */
29
    public function testNormalize(mixed $skipOnEmpty, string $expectedClassName): void
30
    {
31
        $this->assertInstanceOf($expectedClassName, SkipOnEmptyNormalizer::normalize($skipOnEmpty));
32
    }
33
34
    public function testWrongType(): void
35
    {
36
        $this->expectException(InvalidArgumentException::class);
37
        $this->expectExceptionMessage('$skipOnEmpty must be a null, a boolean or a callable');
38
        SkipOnEmptyNormalizer::normalize(1);
39
    }
40
}
41