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

HMACOutputLengthValueTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testHMACOutputLength() 0 8 2
A provideHMACOutputLength() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Test\XMLSecurity\Type;
6
7
use PHPUnit\Framework\Attributes\CoversClass;
8
use PHPUnit\Framework\Attributes\DataProvider;
9
use PHPUnit\Framework\TestCase;
10
use SimpleSAML\XML\Exception\SchemaViolationException;
11
use SimpleSAML\XMLSecurity\Type\HMACOutputLengthValue;
12
13
/**
14
 * Class \SimpleSAML\Test\XMLSecurity\Type\HMACOutputLengthValueTest
15
 *
16
 * @package simplesamlphp/xml-security
17
 */
18
#[CoversClass(HMACOutputLengthValue::class)]
19
final class HMACOutputLengthValueTest extends TestCase
20
{
21
    /**
22
     * @param boolean $shouldPass
23
     * @param string $HMACOutputLength
24
     */
25
    #[DataProvider('provideHMACOutputLength')]
26
    public function testHMACOutputLength(bool $shouldPass, string $HMACOutputLength): void
27
    {
28
        try {
29
            HMACOutputLengthValue::fromString($HMACOutputLength);
30
            $this->assertTrue($shouldPass);
31
        } catch (SchemaViolationException $e) {
32
            $this->assertFalse($shouldPass);
33
        }
34
    }
35
36
37
    /**
38
     * @return array<string, array{0: bool, 1: string}>
39
     */
40
    public static function provideHMACOutputLength(): array
41
    {
42
        return [
43
            'empty' => [false, ''],
44
            'valid positive integer' => [true, '128'],
45
            'invalid indivisible by 8' => [false, '4'],
46
            'invalid signed positive integer' => [false, '+128'],
47
            'invalid zero' => [false, '0'],
48
            'invalid leading zeros' => [false, '0000000000000000000128'],
49
            'invalid with fractional' => [false, '1.'],
50
            'invalid negative' => [false, '-128'],
51
            'invalid with thousands-delimiter' => [false, '1,28'],
52
            'valid with whitespace collapse' => [true, " 1 28\n"],
53
        ];
54
    }
55
}
56