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

HMACOutputLengthTest::provideHMACOutputLength()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 12
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Test\XMLSecurity\Assert;
6
7
use PHPUnit\Framework\Attributes\{CoversClass, DataProvider};
2 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\Attributes\DataProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type PHPUnit\Framework\Attributes\CoversClass was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use PHPUnit\Framework\TestCase;
9
use SimpleSAML\XML\Exception\SchemaViolationException;
10
use SimpleSAML\XMLSecurity\Assert\Assert;
11
use SimpleSAML\XMLSecurity\Exception\ProtocolViolationException;
12
13
/**
14
 * Class \SimpleSAML\Test\XMLSecurity\Assert\HMACOutputLengthTest
15
 *
16
 * @package simplesamlphp/xml-security
17
 */
18
#[CoversClass(Assert::class)]
19
final class HMACOutputLengthTest extends TestCase
20
{
21
    /**
22
     * @param boolean $shouldPass
23
     * @param string $HMACOutputLength
24
     */
25
    #[DataProvider('provideHMACOutputLength')]
26
    public function testValidHMACOutputLength(bool $shouldPass, string $HMACOutputLength): void
27
    {
28
        try {
29
            Assert::validHMACOutputLength($HMACOutputLength);
30
            $this->assertTrue($shouldPass);
31
        } catch (SchemaViolationException | ProtocolViolationException $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
        ];
53
    }
54
}
55