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

DigestValueTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testDigestValue() 0 8 2
A provideDigestValue() 0 7 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\DigestValue;
12
13
/**
14
 * Class \SimpleSAML\Test\XMLSecurity\Type\DigestValueTest
15
 *
16
 * @package simplesamlphp/xml-security
17
 */
18
#[CoversClass(DigestValue::class)]
19
final class DigestValueTest extends TestCase
20
{
21
    /**
22
     * @param boolean $shouldPass
23
     * @param string $digestValue
24
     */
25
    #[DataProvider('provideDigestValue')]
26
    public function testDigestValue(bool $shouldPass, string $digestValue): void
27
    {
28
        try {
29
            DigestValue::fromString($digestValue);
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 provideDigestValue(): array
41
    {
42
        return [
43
            'empty' => [false, ''],
44
            'valid' => [true, 'U2ltcGxlU0FNTHBocA=='],
45
            'illegal characters' => [false, '&*$(#&^@!(^%$'],
46
            'length not dividable by 4' => [false, 'U2ltcGxlU0FTHBocA=='],
47
        ];
48
    }
49
}
50