Passed
Pull Request — master (#55)
by Tim
01:54
created

DurationTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testValidDuration() 0 8 2
A provideDuration() 0 24 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Test\XML\Assert;
6
7
use PHPUnit\Framework\Attributes\CoversClass;
0 ignored issues
show
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\Attributes\DataProvider;
0 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...
9
use PHPUnit\Framework\TestCase;
10
use SimpleSAML\Assert\AssertionFailedException;
11
use SimpleSAML\XML\Assert\Assert;
12
13
/**
14
 * Class \SimpleSAML\Test\XML\Assert\DurationTest
15
 *
16
 * @package simplesamlphp/xml-common
17
 */
18
#[CoversClass(Assert::class)]
19
final class DurationTest extends TestCase
20
{
21
    /**
22
     * @param boolean $shouldPass
23
     * @param string $duration
24
     */
25
    #[DataProvider('provideDuration')]
26
    public function testValidDuration(bool $shouldPass, string $duration): void
27
    {
28
        try {
29
            Assert::validDuration($duration);
30
            $this->assertTrue($shouldPass);
31
        } catch (AssertionFailedException $e) {
32
            $this->assertFalse($shouldPass);
33
        }
34
    }
35
36
37
    /**
38
     * @return array<int, array{0: bool, 1: string}>
39
     */
40
    public static function provideDuration(): array
41
    {
42
        return [
43
            [true, 'P2Y6M5DT12H35M30S'],
44
            [true, 'P1DT2H'],
45
            [true, 'P1W'],
46
            [true, 'P20M'],
47
            [true, 'PT20M'],
48
            [true, 'P0Y20M0D'],
49
            [true, 'P0Y'],
50
            [true, '-P60D'],
51
            [true, 'PT1M30.5S'],
52
            [true, 'P15.5Y'],
53
            [true, 'P15,5Y'],
54
            [false, 'P-20M'],
55
            [false, 'P20MT'],
56
            [false, 'P1YM5D'],
57
            [false, 'P1D2H'],
58
            [false, '1Y2M'],
59
            [false, 'P2M1Y'],
60
            [false, 'P'],
61
            [false, 'PT15.S'],
62
            // Trailing newlines are forbidden
63
            [false, "P20M\n"],
64
        ];
65
    }
66
}
67