Passed
Pull Request — master (#2)
by Chad
03:27
created

TimeSpanFilterTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A filterValue() 0 9 2
A provideFilterData() 0 21 1
1
<?php
2
3
namespace Filter;
4
5
use TraderInteractive\Exceptions\FilterException;
6
use TraderInteractive\Filter\TimeSpanFilter;
7
use PHPUnit\Framework\TestCase;
8
9
/**
10
 * @coversDefaultClass \TraderInteractive\Filter\TimeSpanFilter
11
 */
12
class TimeSpanFilterTest extends TestCase
13
{
14
    /**
15
     * @param mixed       $value                    The value to be filtered.
16
     * @param string|null $expectedExceptionMessage Optional expection message to be thrown.
17
     *
18
     * @test
19
     * @covers ::filter
20
     * @dataProvider provideFilterData
21
     */
22
    public function filterValue($value, string $expectedExceptionMessage = null)
23
    {
24
        if ($expectedExceptionMessage !== null) {
25
            $this->expectException(FilterException::class);
26
            $this->expectExceptionMessage($expectedExceptionMessage);
27
        }
28
29
        $filteredValue = TimeSpanFilter::filter($value);
30
        $this->assertSame($value, $filteredValue);
31
    }
32
33
    /**
34
     * @return array
35
     */
36
    public function provideFilterData() : array
37
    {
38
        return [
39
            [
40
                'value' => '23:59:59',
41
            ],
42
            [
43
                'value' => '1:1:1',
44
                'message' => '$value must be in the correct format HH:MM:SS',
45
            ],
46
            [
47
                'value' => null,
48
                'message' => '$value must be a non-empty string',
49
            ],
50
            [
51
                'value' => '',
52
                'message' => '$value must be a non-empty string',
53
            ],
54
            [
55
                'value' => "\n\t    \n",
56
                'message' => '$value must be a non-empty string',
57
            ],
58
        ];
59
    }
60
}
61