Passed
Pull Request — master (#60)
by Tim
02:20
created

KeySizeTest::testValidKeySize()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
nc 3
nop 2
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Test\XMLSecurity\Assert;
6
7
use PHPUnit\Framework\Attributes\{CoversClass, DataProvider};
8
use PHPUnit\Framework\TestCase;
9
use SimpleSAML\Assert\AssertionFailedException;
10
use SimpleSAML\XMLSecurity\Assert\Assert;
11
12
/**
13
 * Class \SimpleSAML\Test\XMLSecurity\Assert\KeySizeTest
14
 *
15
 * @package simplesamlphp/xml-security
16
 */
17
#[CoversClass(Assert::class)]
18
final class KeySizeTest extends TestCase
19
{
20
    /**
21
     * @param boolean $shouldPass
22
     * @param string $keySize
23
     */
24
    #[DataProvider('provideKeySize')]
25
    public function testValidKeySize(bool $shouldPass, string $keySize): void
26
    {
27
        try {
28
            Assert::validKeySize($keySize);
29
            $this->assertTrue($shouldPass);
30
        } catch (AssertionFailedException $e) {
31
            $this->assertFalse($shouldPass);
32
        }
33
    }
34
35
36
    /**
37
     * @return array<string, array{0: bool, 1: string}>
38
     */
39
    public static function provideKeySize(): array
40
    {
41
        return [
42
            'empty' => [false, ''],
43
            'valid positive integer' => [true, '123456'],
44
            'invalid signed positive integer' => [false, '+123456'],
45
            'invalid zero' => [false, '0'],
46
            'invalid leading zeros' => [false, '0000000000000000000005'],
47
            'invalid with fractional' => [false, '1.'],
48
            'invalid negative' => [false, '-1234'],
49
            'invalid with thousands-delimiter' => [false, '1,234'],
50
        ];
51
    }
52
}
53