testPassesThrowsExceptionIfMaxIsNotSet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Validation\Rules;
6
7
use PHPUnit\Framework\TestCase;
8
9
class MaxLengthTest extends TestCase
10
{
11
    /**
12
     * @return array[]
13
     */
14
    public function passesProvider(): array
15
    {
16
        return [
17
            'empty'             => ['', [], [1], true],
18
            'max-1-foo'         => ['foo', [], [1], false],
19
            'max-3-foo-default' => ['foo', [], [3], true],
20
            'max-3-foo-inc'     => ['foo', [], [3, true], true],
21
            'max-3-foo'         => ['foo', [], [3, false], false],
22
        ];
23
    }
24
25
    /**
26
     * @dataProvider passesProvider
27
     *
28
     * @param       $value
29
     * @param array $allValues
30
     * @param array $args
31
     * @param bool  $expectedResult
32
     */
33
    public function testPasses($value, array $allValues, array $args, bool $expectedResult): void
34
    {
35
        $sut = new MaxLength();
36
        $sut->setArgs($args);
37
38
        $actualResult = $sut->passes($value, $allValues);
39
40
        $this->assertEquals($expectedResult, $actualResult);
41
    }
42
43
    public function testGetSlug(): void
44
    {
45
        $sut = new MaxLength();
46
        $sut->setArgs([1]);
47
48
        $actualResult = $sut->getSlug();
49
50
        $this->assertSame('maxLength', $actualResult);
51
    }
52
53
    public function testPassesThrowsExceptionIfMaxIsNotSet(): void
54
    {
55
        $this->expectException(\LogicException::class);
56
57
        $sut = new MaxLength();
58
59
        $sut->passes('foo', []);
60
    }
61
}
62