1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics) |
6
|
|
|
* |
7
|
|
|
* This program is free software; you can redistribute it and/or |
8
|
|
|
* modify it under the terms of the GNU General Public License |
9
|
|
|
* as published by the Free Software Foundation; either version 2 |
10
|
|
|
* of the License, or (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 General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with this program; if not, write to the Free Software |
19
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace App\Tests\Entity\Parts; |
23
|
|
|
|
24
|
|
|
use App\Entity\Parts\MeasurementUnit; |
25
|
|
|
use App\Entity\Parts\Part; |
26
|
|
|
use App\Entity\Parts\PartLot; |
27
|
|
|
use Doctrine\Common\Collections\Collection; |
28
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
29
|
|
|
|
30
|
|
|
class PartTest extends TestCase |
31
|
|
|
{ |
32
|
|
|
public function testAddRemovePartLot() |
33
|
|
|
{ |
34
|
|
|
$part = new Part(); |
35
|
|
|
$this->assertInstanceOf(Collection::class, $part->getPartLots()); |
36
|
|
|
$this->assertTrue($part->getPartLots()->isEmpty()); |
37
|
|
|
|
38
|
|
|
//Add element |
39
|
|
|
$lot = new PartLot(); |
40
|
|
|
$part->addPartLot($lot); |
41
|
|
|
$this->assertEquals($part, $lot->getPart()); |
42
|
|
|
$this->assertEquals(1, $part->getPartLots()->count()); |
43
|
|
|
|
44
|
|
|
//Remove element |
45
|
|
|
$part->removePartLot($lot); |
46
|
|
|
$this->assertTrue($part->getPartLots()->isEmpty()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testGetSetMinamount() |
50
|
|
|
{ |
51
|
|
|
$part = new Part(); |
52
|
|
|
$measurement_unit = new MeasurementUnit(); |
53
|
|
|
|
54
|
|
|
//Without an set measurement unit the part must return an int |
55
|
|
|
$part->setMinAmount(1.345); |
56
|
|
|
$this->assertEquals(1, $part->getMinAmount()); |
57
|
|
|
|
58
|
|
|
//If an non int-based unit is assigned, an float is returned |
59
|
|
|
$part->setPartUnit($measurement_unit); |
60
|
|
|
$this->assertEquals(1.345, $part->getMinAmount()); |
61
|
|
|
|
62
|
|
|
//If an int-based unit is assigned an int is returned |
63
|
|
|
$measurement_unit->setIsInteger(true); |
64
|
|
|
$this->assertEquals(1, $part->getMinAmount()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testUseFloatAmount() |
68
|
|
|
{ |
69
|
|
|
$part = new Part(); |
70
|
|
|
$measurement_unit = new MeasurementUnit(); |
71
|
|
|
|
72
|
|
|
//Without an measurement unit int should be used |
73
|
|
|
$this->assertFalse($part->useFloatAmount()); |
74
|
|
|
|
75
|
|
|
$part->setPartUnit($measurement_unit); |
76
|
|
|
$this->assertTrue($part->useFloatAmount()); |
77
|
|
|
|
78
|
|
|
$measurement_unit->setIsInteger(true); |
79
|
|
|
$this->assertFalse($part->useFloatAmount()); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testGetAmountSum() |
83
|
|
|
{ |
84
|
|
|
$part = new Part(); |
85
|
|
|
$measurement_unit = new MeasurementUnit(); |
86
|
|
|
$datetime = new \DateTime(); |
87
|
|
|
|
88
|
|
|
$this->assertEquals(0, $part->getAmountSum()); |
89
|
|
|
|
90
|
|
|
$part->addPartLot((new PartLot())->setAmount(3.141)); |
91
|
|
|
$part->addPartLot((new PartLot())->setAmount(10.0)); |
92
|
|
|
$part->addPartLot((new PartLot())->setAmount(5)->setInstockUnknown(true)); |
93
|
|
|
$part->addPartLot( |
94
|
|
|
(new PartLot()) |
95
|
|
|
->setAmount(6) |
96
|
|
|
->setExpirationDate($datetime->setTimestamp(strtotime('now -1 hour'))) |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
$this->assertEquals(13, $part->getAmountSum()); |
100
|
|
|
|
101
|
|
|
$part->setPartUnit($measurement_unit); |
102
|
|
|
$this->assertEquals(13.141, $part->getAmountSum()); |
103
|
|
|
|
104
|
|
|
//1 billion part lot |
105
|
|
|
$part->addPartLot((new PartLot())->setAmount(1000000000)); |
106
|
|
|
$this->assertEquals(1000000013.141, $part->getAmountSum()); |
107
|
|
|
$measurement_unit->setIsInteger(true); |
108
|
|
|
$this->assertEquals(1000000013, $part->getAmountSum()); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
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