File tree Expand file tree Collapse file tree 2 files changed +99
-1
lines changed Expand file tree Collapse file tree 2 files changed +99
-1
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,13 @@ public function validate($validationSubject): void
20
20
$ totalValue = 0 ;
21
21
22
22
foreach ($ validationSubject ->items as $ item ) {
23
- $ totalValue += $ item ->getItemValue ();
23
+ $ itemValue = $ item ->getItemValue ();
24
+
25
+ if (! isset ($ itemValue ['amount ' ])) {
26
+ continue ;
27
+ }
28
+
29
+ $ totalValue += (int ) $ itemValue ['amount ' ];
24
30
}
25
31
26
32
if ($ totalValue < 100 ) {
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace MyParcelNL \Sdk \Test \Rule ;
6
+
7
+ use MyParcelNL \Sdk \src \Model \Consignment \PostNLConsignment ;
8
+ use MyParcelNL \Sdk \src \Model \MyParcelCustomsItem ;
9
+ use MyParcelNL \Sdk \src \Rule \Consignment \MinimumItemValueRule ;
10
+ use MyParcelNL \Sdk \Test \Bootstrap \TestCase ;
11
+
12
+ class MinimumItemValueRuleTest extends TestCase
13
+ {
14
+ /**
15
+ * @return array
16
+ */
17
+ public function provideMinimumItemValueData (): array
18
+ {
19
+ return [
20
+ [
21
+ [
22
+ 'items ' => [
23
+ [
24
+ 'value ' => 50 ,
25
+ ],
26
+ [
27
+ 'value ' => 50 ,
28
+ ],
29
+ ],
30
+ ],
31
+ 'expected ' =>true ,
32
+ ],
33
+ [
34
+ [
35
+ 'items ' => [
36
+ [
37
+ 'value ' => 5000 ,
38
+ ],
39
+ [
40
+ 'value ' => 9995 ,
41
+ ],
42
+ ],
43
+ ],
44
+ 'expected ' =>true ,
45
+ ],
46
+ [
47
+ [
48
+ 'items ' => [
49
+ [
50
+ 'value ' => 50 ,
51
+ ],
52
+ ],
53
+ ],
54
+ 'expected ' =>false ,
55
+ ],
56
+ [
57
+ [
58
+ 'items ' => [],
59
+ ],
60
+ 'expected ' =>true ,
61
+ ],
62
+ ];
63
+ }
64
+
65
+ /**
66
+ * @param array $data
67
+ * @param bool $expected
68
+ *
69
+ * @dataProvider provideMinimumItemValueData
70
+ */
71
+ public function testMinimumItemValueRule (array $ data , bool $ expected ): void
72
+ {
73
+ $ rule = new MinimumItemValueRule ();
74
+ $ consignment = new PostNLConsignment ();
75
+
76
+ foreach ($ data ['items ' ] as $ item ) {
77
+ $ consignment ->addItem (
78
+ (new MyParcelCustomsItem ())
79
+ ->setItemValue ($ item ['value ' ])
80
+ ->setAmount (1 )
81
+ ->setWeight (1 )
82
+ ->setClassification (123456 )
83
+ ->setCountry ('NL ' )
84
+ ->setDescription ('test ' )
85
+ );
86
+ }
87
+
88
+ $ rule ->validate ($ consignment );
89
+
90
+ self ::assertEquals ($ expected , 0 === count ($ rule ->getErrors ()));
91
+ }
92
+ }
You can’t perform that action at this time.
0 commit comments