1 | <?php |
||
2 | |||
3 | namespace App\Tests\Services\Parts; |
||
4 | |||
5 | use App\Entity\Parts\Part; |
||
6 | use App\Entity\Parts\PartLot; |
||
7 | use App\Entity\Parts\Storelocation; |
||
8 | use App\Services\ElementTypeNameGenerator; |
||
9 | use App\Services\Parts\PartLotWithdrawAddHelper; |
||
10 | use PHPUnit\Framework\TestCase; |
||
0 ignored issues
–
show
|
|||
11 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
||
12 | |||
13 | class TestPartLot extends PartLot |
||
14 | { |
||
15 | public function getID(): ?int |
||
16 | { |
||
17 | return 2; |
||
18 | } |
||
19 | } |
||
20 | |||
21 | class PartLotWithdrawAddHelperTest extends WebTestCase |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * @var PartLotWithdrawAddHelper |
||
26 | */ |
||
27 | protected $service; |
||
28 | |||
29 | /** @var Part */ |
||
30 | private $part; |
||
31 | |||
32 | /** @var Storelocation */ |
||
33 | private $storageLocation; |
||
34 | /** @var Storelocation */ |
||
35 | private $full_storageLocation; |
||
36 | |||
37 | /** @var PartLot */ |
||
38 | private $partLot1; |
||
39 | /** @var PartLot */ |
||
40 | private $partLot2; |
||
41 | /** @var PartLot */ |
||
42 | private $partLot3; |
||
43 | |||
44 | /** @var PartLot */ |
||
45 | private $fullLot; |
||
46 | /** @var PartLot */ |
||
47 | private $lotWithUnknownInstock; |
||
48 | |||
49 | protected function setUp(): void |
||
50 | { |
||
51 | parent::setUp(); |
||
52 | //Get an service instance. |
||
53 | self::bootKernel(); |
||
54 | $this->service = self::getContainer()->get(PartLotWithdrawAddHelper::class); |
||
55 | |||
56 | $this->fillTestData(); |
||
57 | } |
||
58 | |||
59 | private function fillTestData(): void |
||
60 | { |
||
61 | $this->part = new Part(); |
||
62 | |||
63 | $this->storageLocation = new Storelocation(); |
||
64 | $this->full_storageLocation = new Storelocation(); |
||
65 | $this->full_storageLocation->setIsFull(true); |
||
66 | |||
67 | $this->partLot1 = new TestPartLot(); |
||
68 | $this->partLot1->setPart($this->part); |
||
69 | $this->partLot1->setAmount(10); |
||
70 | |||
71 | $this->partLot2 = new TestPartLot(); |
||
72 | $this->partLot2->setPart($this->part); |
||
73 | $this->partLot2->setStorageLocation($this->storageLocation); |
||
74 | $this->partLot2->setAmount(2); |
||
75 | |||
76 | $this->partLot3 = new TestPartLot(); |
||
77 | $this->partLot3->setPart($this->part); |
||
78 | $this->partLot3->setAmount(0); |
||
79 | |||
80 | $this->fullLot = new TestPartLot(); |
||
81 | $this->fullLot->setPart($this->part); |
||
82 | $this->fullLot->setAmount(45); |
||
83 | $this->fullLot->setStorageLocation($this->full_storageLocation); |
||
84 | |||
85 | $this->lotWithUnknownInstock = new TestPartLot(); |
||
86 | $this->lotWithUnknownInstock->setPart($this->part); |
||
87 | $this->lotWithUnknownInstock->setAmount(5); |
||
88 | $this->lotWithUnknownInstock->setInstockUnknown(true); |
||
89 | $this->lotWithUnknownInstock->setStorageLocation($this->storageLocation); |
||
90 | } |
||
91 | |||
92 | public function testCanWithdraw() |
||
93 | { |
||
94 | //Normal lots should be withdrawable |
||
95 | $this->assertTrue($this->service->canWithdraw($this->partLot1)); |
||
96 | $this->assertTrue($this->service->canWithdraw($this->partLot2)); |
||
97 | //Empty lots should not be withdrawable |
||
98 | $this->assertFalse($this->service->canWithdraw($this->partLot3)); |
||
99 | |||
100 | //Full lots should be withdrawable |
||
101 | $this->assertTrue($this->service->canWithdraw($this->fullLot)); |
||
102 | //Lots with unknown instock should not be withdrawable |
||
103 | $this->assertFalse($this->service->canWithdraw($this->lotWithUnknownInstock)); |
||
104 | } |
||
105 | |||
106 | public function testCanAdd() |
||
107 | { |
||
108 | //Normal lots should be addable |
||
109 | $this->assertTrue($this->service->canAdd($this->partLot1)); |
||
110 | $this->assertTrue($this->service->canAdd($this->partLot2)); |
||
111 | $this->assertTrue($this->service->canAdd($this->partLot3)); |
||
112 | |||
113 | //Full lots should not be addable |
||
114 | $this->assertFalse($this->service->canAdd($this->fullLot)); |
||
115 | //Lots with unknown instock should not be addable |
||
116 | $this->assertFalse($this->service->canAdd($this->lotWithUnknownInstock)); |
||
117 | } |
||
118 | |||
119 | public function testAdd() |
||
120 | { |
||
121 | //Add 5 to lot 1 |
||
122 | $this->service->add($this->partLot1, 5, "Test"); |
||
123 | $this->assertEquals(15, $this->partLot1->getAmount()); |
||
124 | |||
125 | //Add 3.2 to lot 2 |
||
126 | $this->service->add($this->partLot2, 3.2, "Test"); |
||
127 | $this->assertEquals(5, $this->partLot2->getAmount()); |
||
128 | |||
129 | //Add 1.5 to lot 3 |
||
130 | $this->service->add($this->partLot3, 1.5, "Test"); |
||
131 | $this->assertEquals(2, $this->partLot3->getAmount()); |
||
132 | |||
133 | } |
||
134 | |||
135 | public function testWithdraw() |
||
136 | { |
||
137 | //Withdraw 5 from lot 1 |
||
138 | $this->service->withdraw($this->partLot1, 5, "Test"); |
||
139 | $this->assertEquals(5, $this->partLot1->getAmount()); |
||
140 | |||
141 | //Withdraw 2.2 from lot 2 |
||
142 | $this->service->withdraw($this->partLot2, 2.2, "Test"); |
||
143 | $this->assertEquals(0, $this->partLot2->getAmount()); |
||
144 | } |
||
145 | |||
146 | public function testMove() |
||
147 | { |
||
148 | //Move 5 from lot 1 to lot 2 |
||
149 | $this->service->move($this->partLot1, $this->partLot2, 5, "Test"); |
||
150 | $this->assertEquals(5, $this->partLot1->getAmount()); |
||
151 | $this->assertEquals(7, $this->partLot2->getAmount()); |
||
152 | |||
153 | //Move 2.2 from lot 2 to lot 3 |
||
154 | $this->service->move($this->partLot2, $this->partLot3, 2.2, "Test"); |
||
155 | $this->assertEquals(5, $this->partLot2->getAmount()); |
||
156 | $this->assertEquals(2, $this->partLot3->getAmount()); |
||
157 | } |
||
158 | } |
||
159 |
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