DatingRuleTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 46
c 0
b 0
f 0
dl 0
loc 59
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testCompute() 0 12 2
A providerCompute() 0 40 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Service;
6
7
use Application\Model\Dating;
8
use Application\Service\DatingRule;
9
use PHPUnit\Framework\TestCase;
10
11
class DatingRuleTest extends TestCase
12
{
13
    /**
14
     * @dataProvider providerCompute
15
     */
16
    public function testCompute(string $input, array $expected): void
17
    {
18
        $datingRule = new DatingRule();
19
        $actual = $datingRule->compute($input);
20
21
        $actualFlat = [];
22
        foreach ($actual as $a) {
23
            self::assertInstanceOf(Dating::class, $a);
24
            $actualFlat[] = [$a->getFrom()->format('Y-m-d'), $a->getTo()->format('Y-m-d')];
25
        }
26
27
        self::assertEquals($expected, $actualFlat);
28
    }
29
30
    public static function providerCompute(): iterable
31
    {
32
        yield 'empty' => ['', []];
33
        yield 'simple' => ['1295-2295', [['1295-01-01', '2295-12-31']]];
34
        yield 'multiple' => ['1295-2295; 1300', [['1295-01-01', '2295-12-31'], ['1300-01-01', '1300-12-31']]];
35
        yield 'roman' => ['VIII', [['0701-01-01', '0800-12-31']]];
36
        yield 'roman with extra' => ['XVIIIème siècle', [['1701-01-01', '1800-12-31']]];
37
        yield 'roman ranges' => ['XVIIe-XVIIIe siècle', [['1601-01-01', '1700-12-31'], ['1701-01-01', '1800-12-31']]];
38
        yield ['64', [['1964-01-01', '1964-12-31']]];
39
        yield ['1875-1877', [['1875-01-01', '1877-12-31']]];
40
        yield ['1875-77', [['1875-01-01', '1877-12-31']]];
41
        yield ['1875/77', [['1875-01-01', '1877-12-31']]];
42
        yield ['1875 v. Chr.', [['-1875-01-01', '-1875-12-31']]];
43
        yield ['1875-1877', [['1875-01-01', '1877-12-31']]];
44
        yield ['1875 n. Chr.', [['1875-01-01', '1875-12-31']]];
45
        yield ['1875', [['1875-01-01', '1875-12-31']]];
46
        yield ['1876-1872 v. Chr.', [['-1876-01-01', '-1872-12-31']]];
47
        yield ['um 1875 v. Chr.', [['-1875-01-01', '-1875-12-31']]];
48
        yield ['vor 1875 v. Chr.', [['-1875-01-01', '-1875-12-31']]];
49
        yield ['nach 1875 v. Chr.', [['-1875-01-01', '-1875-12-31']]];
50
        yield ['23.10.2003', [['2003-10-23', '2003-10-23']]];
51
        yield ['spätantike', [['0275-01-01', '0525-12-31']]];
52
        yield ['Shang-Dynastie', [['-1625-01-01', '-0975-12-31']]];
53
        yield ['um 1875 v. Chr.', [['-1875-01-01', '-1875-12-31']]];
54
        yield ['antike ', [['-0825-01-01', '0525-12-31']]];
55
        yield ['6. Jhdt.', [['0500-01-01', '0599-12-31']]];
56
        yield ['6 Jhd  n. Chr', [['0500-01-01', '0599-12-31']]];
57
        yield ['6 Jh. n. Chr.', [['0500-01-01', '0599-12-31']]];
58
        yield ['um 1874', [['1873-01-01', '1875-12-31']]];
59
        yield ['Anfang 6. Jhdt.', [['0500-01-01', '0525-12-31']]];
60
        yield ['6. Jhdt. v. Chr.', [['-0501-01-01', '-0600-12-31']]];
61
        yield ['6. Jhdt. n. Chr.', [['0500-01-01', '0599-12-31']]];
62
        yield ['Ende 6. Jhdt.', [['0575-01-01', '0599-12-31']]];
63
        yield ['vor 1874', [['1874-01-01', '1874-12-31']]];
64
        yield ['mitte 6. Jhdt.', [['0533-01-01', '0566-12-31']]];
65
        yield ['mitte 6. Jhdt. v. chr', [['-0666-01-01', '-0633-12-31']]];
66
        yield ['um 6. Jhdt.', [['0480-01-01', '0620-12-31']]];
67
        yield ['nach 1874', [['1874-01-01', '1874-12-31']]];
68
        yield ['1. - 2. Jh. n. Chr.', [['0001-01-01', '0199-12-31']]];
69
        yield ['2. - 1. Jh. v. Chr.', [['-0200-01-01', '-0001-12-31']]];
70
    }
71
}
72