1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as published |
9
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
declare(strict_types=1); |
22
|
|
|
|
23
|
|
|
namespace App\Tests\Entity\Parts; |
24
|
|
|
|
25
|
|
|
use App\Entity\Parts\MeasurementUnit; |
26
|
|
|
use App\Entity\Parts\Part; |
27
|
|
|
use App\Entity\Parts\PartLot; |
28
|
|
|
use DateTime; |
29
|
|
|
use Doctrine\Common\Collections\Collection; |
30
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
31
|
|
|
|
32
|
|
|
class PartTest extends TestCase |
33
|
|
|
{ |
34
|
|
|
public function testAddRemovePartLot(): void |
35
|
|
|
{ |
36
|
|
|
$part = new Part(); |
37
|
|
|
$this->assertInstanceOf(Collection::class, $part->getPartLots()); |
38
|
|
|
$this->assertTrue($part->getPartLots()->isEmpty()); |
39
|
|
|
|
40
|
|
|
//Add element |
41
|
|
|
$lot = new PartLot(); |
42
|
|
|
$part->addPartLot($lot); |
43
|
|
|
$this->assertSame($part, $lot->getPart()); |
44
|
|
|
$this->assertSame(1, $part->getPartLots()->count()); |
45
|
|
|
|
46
|
|
|
//Remove element |
47
|
|
|
$part->removePartLot($lot); |
48
|
|
|
$this->assertTrue($part->getPartLots()->isEmpty()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testGetSetMinamount(): void |
52
|
|
|
{ |
53
|
|
|
$part = new Part(); |
54
|
|
|
$measurement_unit = new MeasurementUnit(); |
55
|
|
|
|
56
|
|
|
//Without an set measurement unit the part must return an int |
57
|
|
|
$part->setMinAmount(1.345); |
58
|
|
|
$this->assertSame(1.0, $part->getMinAmount()); |
59
|
|
|
|
60
|
|
|
//If an non int-based unit is assigned, an float is returned |
61
|
|
|
$part->setPartUnit($measurement_unit); |
62
|
|
|
$this->assertSame(1.345, $part->getMinAmount()); |
63
|
|
|
|
64
|
|
|
//If an int-based unit is assigned an int is returned |
65
|
|
|
$measurement_unit->setIsInteger(true); |
66
|
|
|
$this->assertSame(1.0, $part->getMinAmount()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testUseFloatAmount(): void |
70
|
|
|
{ |
71
|
|
|
$part = new Part(); |
72
|
|
|
$measurement_unit = new MeasurementUnit(); |
73
|
|
|
|
74
|
|
|
//Without an measurement unit int should be used |
75
|
|
|
$this->assertFalse($part->useFloatAmount()); |
76
|
|
|
|
77
|
|
|
$part->setPartUnit($measurement_unit); |
78
|
|
|
$this->assertTrue($part->useFloatAmount()); |
79
|
|
|
|
80
|
|
|
$measurement_unit->setIsInteger(true); |
81
|
|
|
$this->assertFalse($part->useFloatAmount()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testGetAmountSum(): void |
85
|
|
|
{ |
86
|
|
|
$part = new Part(); |
87
|
|
|
$measurement_unit = new MeasurementUnit(); |
88
|
|
|
$datetime = new DateTime(); |
89
|
|
|
|
90
|
|
|
$this->assertSame(0.0, $part->getAmountSum()); |
91
|
|
|
|
92
|
|
|
$part->addPartLot((new PartLot())->setAmount(3.141)); |
93
|
|
|
$part->addPartLot((new PartLot())->setAmount(10.0)); |
94
|
|
|
$part->addPartLot((new PartLot())->setAmount(5)->setInstockUnknown(true)); |
95
|
|
|
$part->addPartLot( |
96
|
|
|
(new PartLot()) |
97
|
|
|
->setAmount(6) |
98
|
|
|
->setExpirationDate($datetime->setTimestamp(strtotime('now -1 hour'))) |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$this->assertSame(13.0, $part->getAmountSum()); |
102
|
|
|
|
103
|
|
|
$part->setPartUnit($measurement_unit); |
104
|
|
|
$this->assertSame(13.141, $part->getAmountSum()); |
105
|
|
|
|
106
|
|
|
//1 billion part lot |
107
|
|
|
$part->addPartLot((new PartLot())->setAmount(1000000000)); |
108
|
|
|
$this->assertSame(1000000013.141, $part->getAmountSum()); |
109
|
|
|
$measurement_unit->setIsInteger(true); |
110
|
|
|
$this->assertSame(1000000013.0, $part->getAmountSum()); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths