Passed
Push — master ( d7dee9...483d68 )
by Jan
04:53 queued 10s
created

PartParameterTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 35
c 1
b 0
f 0
dl 0
loc 76
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetValueMinWithUnit() 0 6 1
A testGetValueMaxWithUnit() 0 6 1
A valueWithUnitDataProvider() 0 7 1
A testGetValueTypicalWithUnit() 0 6 1
A formattedValueDataProvider() 0 12 1
A testGetFormattedValue() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
7
 *
8
 * Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as published
12
 * by the Free Software Foundation, either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
22
 */
23
24
namespace App\Tests\Entity\Parameters;
25
26
use App\Entity\Parameters\PartParameter;
27
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase 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...
28
29
class PartParameterTest extends TestCase
30
{
31
    public function valueWithUnitDataProvider(): array
32
    {
33
        return [
34
            ['1', 1.0, ''],
35
            ['1 V', 1.0, 'V'],
36
            ['1.23', 1.23, ''],
37
            ['1.23 V', 1.23, 'V'],
38
        ];
39
    }
40
41
    public function formattedValueDataProvider(): array
42
    {
43
        return [
44
            ['Text Test', null, null, null, 'V', 'Text Test'],
45
            ['10.23 V', null, 10.23, null, 'V', ''],
46
            ['10.23 V [Text]', null, 10.23, null, 'V', 'Text'],
47
            ['max. 10.23 V', null, null, 10.23, 'V', ''],
48
            ['max. 10.23 [Text]', null, null, 10.23, '', 'Text'],
49
            ['min. 10.23 V', 10.23, null, null, 'V', ''],
50
            ['10.23 V ... 11 V', 10.23, null, 11, 'V', ''],
51
            ['10.23 V (9 V ... 11 V)', 9, 10.23, 11, 'V', ''],
52
            ['10.23 V (9 V ... 11 V) [Test]', 9, 10.23, 11, 'V', 'Test'],
53
        ];
54
    }
55
56
    /**
57
     * @dataProvider  valueWithUnitDataProvider
58
     */
59
    public function testGetValueMinWithUnit(string $expected, float $value, string $unit): void
60
    {
61
        $param = new PartParameter();
62
        $param->setUnit($unit);
63
        $param->setValueMin($value);
64
        $this->assertSame($expected, $param->getValueMinWithUnit());
65
    }
66
67
    /**
68
     * @dataProvider  valueWithUnitDataProvider
69
     */
70
    public function testGetValueMaxWithUnit(string $expected, float $value, string $unit): void
71
    {
72
        $param = new PartParameter();
73
        $param->setUnit($unit);
74
        $param->setValueMax($value);
75
        $this->assertSame($expected, $param->getValueMaxWithUnit());
76
    }
77
78
    /**
79
     * @dataProvider  valueWithUnitDataProvider
80
     */
81
    public function testGetValueTypicalWithUnit(string $expected, float $value, string $unit): void
82
    {
83
        $param = new PartParameter();
84
        $param->setUnit($unit);
85
        $param->setValueTypical($value);
86
        $this->assertSame($expected, $param->getValueTypicalWithUnit());
87
    }
88
89
    /**
90
     * @dataProvider formattedValueDataProvider
91
     *
92
     * @param float $min
93
     * @param float $typical
94
     * @param float $max
95
     */
96
    public function testGetFormattedValue(string $expected, ?float $min, ?float $typical, ?float $max, string $unit, string $text): void
97
    {
98
        $param = new PartParameter();
99
        $param->setUnit($unit);
100
        $param->setValueMin($min);
101
        $param->setValueTypical($typical);
102
        $param->setValueMax($max);
103
        $param->setValueText($text);
104
        $this->assertSame($expected, $param->getFormattedValue());
105
    }
106
}
107