Completed
Push — 1.x-dev ( 423a53...2f7d84 )
by Doug
48:23 queued 46:55
created

PackerTest::getSamples()   B

Complexity

Conditions 6
Paths 24

Size

Total Lines 71
Code Lines 53

Duplication

Lines 6
Ratio 8.45 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 6
loc 71
rs 8.5309
c 1
b 0
f 0
cc 6
eloc 53
nc 24
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Box packing (3D bin packing, knapsack problem)
4
 * @package BoxPacker
5
 * @author Doug Wright
6
 */
7
8
namespace DVDoug\BoxPacker;
9
10
use DVDoug\BoxPacker\Test\TestBox;
11
use DVDoug\BoxPacker\Test\TestItem;
12
use PHPUnit\Framework\TestCase;
13
14
class PackerTest extends TestCase
15
{
16 View Code Duplication
    public function testPackThreeItemsFitEasilyInSmallerOfTwoBoxes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
    {
18
19
        $box1 = new TestBox('Le petite box', 300, 300, 10, 10, 296, 296, 8, 1000);
20
        $box2 = new TestBox('Le grande box', 3000, 3000, 100, 100, 2960, 2960, 80, 10000);
21
22
        $item1 = new TestItem('Item 1', 250, 250, 2, 200);
23
        $item2 = new TestItem('Item 2', 250, 250, 2, 200);
24
        $item3 = new TestItem('Item 3', 250, 250, 2, 200);
25
26
        $packer = new Packer();
27
        $packer->addBox($box1);
28
        $packer->addBox($box2);
29
        $packer->addItem($item1);
30
        $packer->addItem($item2);
31
        $packer->addItem($item3);
32
        $packedBoxes = $packer->pack();
33
34
        self::assertEquals(1, $packedBoxes->count());
35
        self::assertEquals(3, $packedBoxes->top()->getItems()->count());
36
        self::assertEquals($box1, $packedBoxes->top()->getBox());
37
        self::assertEquals(610, $packedBoxes->top()->getWeight());
38
    }
39
40 View Code Duplication
    public function testPackThreeItemsFitEasilyInLargerOfTwoBoxes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
43
        $box1 = new TestBox('Le petite box', 300, 300, 10, 10, 296, 296, 8, 1000);
44
        $box2 = new TestBox('Le grande box', 3000, 3000, 100, 100, 2960, 2960, 80, 10000);
45
46
        $item1 = new TestItem('Item 1', 2500, 2500, 20, 2000);
47
        $item2 = new TestItem('Item 2', 2500, 2500, 20, 2000);
48
        $item3 = new TestItem('Item 3', 2500, 2500, 20, 2000);
49
50
        $packer = new Packer();
51
        $packer->addBox($box1);
52
        $packer->addBox($box2);
53
        $packer->addItem($item1);
54
        $packer->addItem($item2);
55
        $packer->addItem($item3);
56
        $packedBoxes = $packer->pack();
57
58
        self::assertEquals(1, $packedBoxes->count());
59
        self::assertEquals(3, $packedBoxes->top()->getItems()->count());
60
        self::assertEquals($box2, $packedBoxes->top()->getBox());
61
        self::assertEquals(6100, $packedBoxes->top()->getWeight());
62
    }
63
64 View Code Duplication
    public function testPackFiveItemsTwoLargeOneSmallBox()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66
67
        $box1 = new TestBox('Le petite box', 600, 600, 10, 10, 596, 596, 8, 1000);
68
        $box2 = new TestBox('Le grande box', 3000, 3000, 50, 100, 2960, 2960, 40, 10000);
69
70
        $item1 = new TestItem('Item 1', 2500, 2500, 20, 500);
71
        $item2 = new TestItem('Item 2', 550, 550, 2, 500);
72
        $item3 = new TestItem('Item 3', 2500, 2500, 20, 500);
73
        $item4 = new TestItem('Item 4', 2500, 2500, 20, 500);
74
        $item5 = new TestItem('Item 5', 2500, 2500, 20, 500);
75
76
        $packer = new Packer();
77
        $packer->addBox($box1);
78
        $packer->addBox($box2);
79
        $packer->addItem($item1);
80
        $packer->addItem($item2);
81
        $packer->addItem($item3);
82
        $packer->addItem($item4);
83
        $packer->addItem($item5);
84
        $packedBoxes = $packer->pack();
85
86
        self::assertEquals(3, $packedBoxes->count());
87
88
        self::assertEquals(2, $packedBoxes->top()->getItems()->count());
89
        self::assertEquals($box2, $packedBoxes->top()->getBox());
90
        self::assertEquals(1100, $packedBoxes->top()->getWeight());
91
92
        $packedBoxes->extract();
93
94
        self::assertEquals(2, $packedBoxes->top()->getItems()->count());
95
        self::assertEquals($box2, $packedBoxes->top()->getBox());
96
        self::assertEquals(1100, $packedBoxes->top()->getWeight());
97
98
        $packedBoxes->extract();
99
100
        self::assertEquals(1, $packedBoxes->top()->getItems()->count());
101
        self::assertEquals($box1, $packedBoxes->top()->getBox());
102
        self::assertEquals(510, $packedBoxes->top()->getWeight());
103
    }
104
105 View Code Duplication
    public function testPackFiveItemsTwoLargeOneSmallBoxButThreeAfterRepack()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106
    {
107
108
        $box1 = new TestBox('Le petite box', 600, 600, 10, 10, 596, 596, 8, 1000);
109
        $box2 = new TestBox('Le grande box', 3000, 3000, 50, 100, 2960, 2960, 40, 10000);
110
111
        $item1 = new TestItem('Item 1', 2500, 2500, 20, 2000);
112
        $item2 = new TestItem('Item 2', 550, 550, 2, 200);
113
        $item3 = new TestItem('Item 3', 2500, 2500, 20, 2000);
114
        $item4 = new TestItem('Item 4', 2500, 2500, 20, 2000);
115
        $item5 = new TestItem('Item 5', 2500, 2500, 20, 2000);
116
117
        $packer = new Packer();
118
        $packer->addBox($box1);
119
        $packer->addBox($box2);
120
        $packer->addItem($item1);
121
        $packer->addItem($item2);
122
        $packer->addItem($item3);
123
        $packer->addItem($item4);
124
        $packer->addItem($item5);
125
        $packedBoxes = $packer->pack();
126
127
        self::assertEquals(3, $packedBoxes->count());
128
129
        self::assertEquals(2, $packedBoxes->top()->getItems()->count());
130
        self::assertEquals($box2, $packedBoxes->top()->getBox());
131
        self::assertEquals(4100, $packedBoxes->top()->getWeight());
132
133
        $packedBoxes->extract();
134
135
        self::assertEquals(2, $packedBoxes->top()->getItems()->count());
136
        self::assertEquals($box2, $packedBoxes->top()->getBox());
137
        self::assertEquals(2300, $packedBoxes->top()->getWeight());
138
139
        $packedBoxes->extract();
140
141
        self::assertEquals(1, $packedBoxes->top()->getItems()->count());
142
        self::assertEquals($box2, $packedBoxes->top()->getBox());
143
        self::assertEquals(2100, $packedBoxes->top()->getWeight());
144
    }
145
146
    /**
147
     * @expectedException \DVDoug\BoxPacker\ItemTooLargeException
148
     */
149
    public function testPackThreeItemsOneDoesntFitInAnyBox()
150
    {
151
152
        $box1 = new TestBox('Le petite box', 300, 300, 10, 10, 296, 296, 8, 1000);
153
        $box2 = new TestBox('Le grande box', 3000, 3000, 100, 100, 2960, 2960, 80, 10000);
154
155
        $item1 = new TestItem('Item 1', 2500, 2500, 20, 2000);
156
        $item2 = new TestItem('Item 2', 25000, 2500, 20, 2000);
157
        $item3 = new TestItem('Item 3', 2500, 2500, 20, 2000);
158
159
        $packer = new Packer();
160
        $packer->addBox($box1);
161
        $packer->addBox($box2);
162
        $packer->addItem($item1);
163
        $packer->addItem($item2);
164
        $packer->addItem($item3);
165
        $packedBoxes = $packer->pack();
0 ignored issues
show
Unused Code introduced by
$packedBoxes is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
166
    }
167
168
    /**
169
     * @expectedException \DVDoug\BoxPacker\ItemTooLargeException
170
     */
171
    public function testPackWithoutBox()
172
    {
173
174
        $item1 = new TestItem('Item 1', 2500, 2500, 20, 2000);
175
        $item2 = new TestItem('Item 2', 25000, 2500, 20, 2000);
176
        $item3 = new TestItem('Item 3', 2500, 2500, 20, 2000);
177
178
        $packer = new Packer();
179
        $packer->addItem($item1);
180
        $packer->addItem($item2);
181
        $packer->addItem($item3);
182
        $packedBoxes = $packer->pack();
0 ignored issues
show
Unused Code introduced by
$packedBoxes is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
183
    }
184
185 View Code Duplication
    public function testIssue1()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
186
    {
187
188
        $packer = new Packer();
189
        $packer->addBox(new TestBox('Le petite box', 292, 336, 60, 10, 292, 336, 60, 9000));
190
        $packer->addBox(new TestBox('Le grande box', 421, 548, 335, 100, 421, 548, 335, 10000));
191
        $packer->addItem(new TestItem('Item 1', 226, 200, 40, 440));
192
        $packer->addItem(new TestItem('Item 2', 200, 200, 155, 1660));
193
        $packedBoxes = $packer->pack();
194
195
        self::assertEquals(1, $packedBoxes->count());
196
    }
197
198
    public function testIssue3()
199
    {
200
201
        $packer = new Packer();
202
        $packer->addBox(new TestBox('OW Box 1', 51, 33, 33, 0.6, 51, 33, 33, 0.6));
203
        $packer->addBox(new TestBox('OW Box 2', 50, 40, 40, 0.95, 50, 40, 40, 0.95));
204
        $packer->addItem(new TestItem('Product', 28, 19, 9, 0), 6);
205
        $packedBoxes = $packer->pack();
206
207
        self::assertEquals(1, $packedBoxes->count());
208
    }
209
210
    public function testIssue6()
211
    {
212
213
        $packer = new Packer();
214
        $packer->addBox(new TestBox('Package 22', 675, 360, 210, 2, 670, 355, 204, 1000));
215
        $packer->addBox(new TestBox('Package 2', 330, 130, 102, 2, 335, 135, 107, 1000));
216
        $packer->addItem(new TestItem('Item 3', 355.6, 335.28, 127, 1.5));
217
        $packer->addItem(new TestItem('Item 7', 330.2, 127, 101.6, 1));
218
        $packer->addItem(new TestItem('Item 7', 330.2, 127, 101.6, 1));
219
        $packedBoxes = $packer->pack();
220
221
        self::assertEquals(1, $packedBoxes->count());
222
223
    }
224
225 View Code Duplication
    public function testIssue9()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
226
    {
227
        $packer = new Packer();
228
        $packer->addBox(new TestBox('24x24x24Box', 24, 24, 24, 24, 24, 24, 24, 100));
229
230
        $packer->addItem(new TestItem('6x6x6Item', 6, 6, 6, 1), 64);
231
        $packedBoxes = $packer->pack();
232
233
        self::assertEquals(1, $packedBoxes->count());
234
    }
235
236 View Code Duplication
    public function testIssue11()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
237
    {
238
        $packer = new Packer();
239
        $packer->addBox(new TestBox('4x4x4Box', 4, 4, 4, 4, 4, 4, 4, 100));
240
241
        $packer->addItem(new TestItem('BigItem', 2, 2, 4, 1), 2);
242
        $packer->addItem(new TestItem('SmallItem', 1, 1, 1, 1), 32);
243
        $packedBoxes = $packer->pack();
244
245
        self::assertEquals(1, $packedBoxes->count());
246
    }
247
248
    public function testIssue13()
249
    {
250
        $packer = new Packer();
251
        $packer->addBox(new TestBox('Le petite box', 12, 12, 12, 10, 10, 10, 10, 1000));
252
253
        $packer->addItem(new TestItem('Item 1', 5, 3, 2, 2));
254
        $packer->addItem(new TestItem('Item 2', 5, 3, 2, 2));
255
        $packer->addItem(new TestItem('Item 3', 3, 3, 3, 3));
256
        $packedBoxes = $packer->pack();
257
258
        self::assertEquals(1, $packedBoxes->count());
259
    }
260
261 View Code Duplication
    public function testIssue14()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
262
    {
263
        $packer = new Packer();
264
        $packer->addBox(new TestBox('29x1x23Box', 29, 1, 23, 0, 29, 1, 23, 100));
265
        $packer->addItem(new TestItem('13x1x10Item', 13, 1, 10, 1));
266
        $packer->addItem(new TestItem('9x1x6Item', 9, 1, 6, 1));
267
        $packer->addItem(new TestItem('9x1x6Item', 9, 1, 6, 1));
268
        $packer->addItem(new TestItem('9x1x6Item', 9, 1, 6, 1));
269
        $packedBoxes = $packer->pack();
270
271
        self::assertEquals(1, $packedBoxes->count());
272
    }
273
274 View Code Duplication
    public function testIssue47A()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
275
    {
276
        $packer = new Packer();
277
        $packer->addBox(new TestBox('165x225x25Box', 165, 225, 25, 0, 165, 225, 25, 100));
278
        $packer->addItem(new TestItem('20x69x20Item', 20, 69, 20, 0), 23);
279
        $packedBoxes = $packer->pack();
280
281
        self::assertEquals(1, $packedBoxes->count());
282
    }
283
284 View Code Duplication
    public function testIssue47B()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
285
    {
286
        $packer = new Packer();
287
        $packer->addBox(new TestBox('165x225x25Box', 165, 225, 25, 0, 165, 225, 25, 100));
288
        $packer->addItem(new TestItem('20x69x20Item', 69, 20, 20, 0), 23);
289
        $packedBoxes = $packer->pack();
290
291
        self::assertEquals(1, $packedBoxes->count());
292
    }
293
294 View Code Duplication
    public function testIssue47C()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
295
    {
296
        $packer = new Packer();
297
        $packer->addBox(new TestBox('Box', 11.75, 23.6875, 3, 0, 11.75, 23.6875, 3, 70));
298
        $packer->addItem(new TestItem('Item', 3.75, 6.5, 3, 0), 9);
299
        $packedBoxes = $packer->pack();
300
301
        self::assertEquals(1, $packedBoxes->count());
302
    }
303
304 View Code Duplication
    public function testIssue47D()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
305
    {
306
        $packer = new Packer();
307
        $packer->addBox(new TestBox('Box', 11.75, 23.6875, 3, 0, 11.75, 23.6875, 3, 70));
308
        $packer->addItem(new TestItem('Item', 6.5, 3.75, 3, 0), 9);
309
        $packedBoxes = $packer->pack();
310
311
        self::assertEquals(1, $packedBoxes->count());
312
    }
313
314
    public function testPackerPacksRotatedBoxesInNewRow()
315
    {
316
        $packer = new Packer();
317
        $packer->addItem(new TestItem('30x10x30item', 30, 10, 30, 0), 9);
318
319
        //Box can hold 7 items in a row and then is completely full, so 9 items won't fit
320
        $packer->addBox(new TestBox('30x70x30InternalBox', 30, 70, 30, 0, 30, 70, 30, 0, 1000));
0 ignored issues
show
Unused Code introduced by
The call to TestBox::__construct() has too many arguments starting with 1000.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
321
        $packedBoxes = $packer->pack();
322
        self::assertEquals(2, $packedBoxes->count());
323
324
        //Box can hold 7 items in a row, plus two more rotated, making 9 items
325
        // with a 10x10x30 hole in the corner.
326
        //
327
        // Overhead view:
328
        //
329
        // +--+--++
330
        // ++++++++
331
        // ||||||||
332
        // ++++++++
333
        //
334
        $packer = new Packer();
335
        $packer->addItem(new TestItem('30x10x30item', 30, 10, 30, 0), 9);
336
        $packer->addBox(new TestBox('40x70x30InternalBox', 40, 70, 30, 0, 40, 70, 30, 0, 1000));
0 ignored issues
show
Unused Code introduced by
The call to TestBox::__construct() has too many arguments starting with 1000.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
337
        $packedBoxes = $packer->pack();
338
        self::assertEquals(1, $packedBoxes->count());
339
340
        // Make sure that it doesn't try to fit in a 10th item
341
        $packer = new Packer();
342
        $packer->addItem(new TestItem('30x10x30item', 30, 10, 30, 0), 10);
343
        $packer->addBox(new TestBox('40x70x30InternalBox', 40, 70, 30, 0, 40, 70, 30, 0, 1000));
0 ignored issues
show
Unused Code introduced by
The call to TestBox::__construct() has too many arguments starting with 1000.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
344
        $packedBoxes = $packer->pack();
345
        self::assertEquals(2, $packedBoxes->count());
346
    }
347
348
    public function testIssue52A()
349
    {
350
        $packer = new Packer();
351
        $packer->addBox(new TestBox('Box', 100, 50, 50, 0, 100, 50, 50, 5000));
352
        $packer->addItem(new TestItem('Item', 15, 13, 8, 407), 2);
353
        $packedBoxes = $packer->pack();
354
355
        self::assertEquals(1, $packedBoxes->count());
356
        self::assertEquals(26, $packedBoxes->top()->getUsedWidth());
357
        self::assertEquals(15, $packedBoxes->top()->getUsedLength());
358
        self::assertEquals(8, $packedBoxes->top()->getUsedDepth());
359
    }
360
361
    public function testIssue52B()
362
    {
363
        $packer = new Packer();
364
        $packer->addBox(new TestBox('Box',370,375,60,140,364,374,40,3000));
365
        $packer->addItem(new TestItem('Item 1',220,310,12,679));
366
        $packer->addItem(new TestItem('Item 2',210,297,11,648));
367
        $packer->addItem(new TestItem('Item 3',210,297,5,187));
368
        $packer->addItem(new TestItem('Item 4',148,210,32,880));
369
        $packedBoxes = $packer->pack();
370
371
        self::assertEquals(1, $packedBoxes->count());
372
        self::assertEquals(310, $packedBoxes->top()->getUsedWidth());
373
        self::assertEquals(368, $packedBoxes->top()->getUsedLength());
374
        self::assertEquals(32, $packedBoxes->top()->getUsedDepth());
375
    }
376
377
    public function testIssue52C()
378
    {
379
        $packer = new Packer();
380
        $packer->addBox(new TestBox('Box',230,300,240,160,230,300,240,15000));
381
        $packer->addItem(new TestItem('Item 1',210,297,4,213));
382
        $packer->addItem(new TestItem('Item 2',80,285,70,199));
383
        $packer->addItem(new TestItem('Item 3',80,285,70,199));
384
        $packedBoxes = $packer->pack();
385
386
        self::assertEquals(2, $packedBoxes->count());
387
        $box1 = $packedBoxes->extract();
388
        $box2 = $packedBoxes->extract();
389
390
        self::assertEquals(160, $box1->getUsedWidth());
391
        self::assertEquals(285, $box1->getUsedLength());
392
        self::assertEquals(70, $box1->getUsedDepth());
393
394
        self::assertEquals(210, $box2->getUsedWidth());
395
        self::assertEquals(297, $box2->getUsedLength());
396
        self::assertEquals(4, $box2->getUsedDepth());
397
    }
398
399
    public function testIssue79() {
400
        $packer = new Packer();
401
        $packer->addBox(new TestBox('Bundle', 75, 15, 15, 0, 75, 15, 15, 30));
402
        $packer->addItem(new TestItem('Item 1', 14, 12, 2, 2));
403
        $packer->addItem(new TestItem('Item 2', 14, 12, 2, 2));
404
        $packer->addItem(new TestItem('Item 3', 14, 12, 2, 2));
405
        $packer->addItem(new TestItem('Item 4', 14, 12, 2, 2));
406
        $packer->addItem(new TestItem('Item 5', 14, 12, 2, 2));
407
        $packedBoxes = $packer->pack();
408
        $box = $packedBoxes->extract();
409
410
        self::assertEquals(60, $box->getUsedWidth());
411
        self::assertEquals(14, $box->getUsedLength());
412
        self::assertEquals(2, $box->getUsedDepth());
413
    }
414
415
    /**
416
     * @dataProvider getSamples
417
     * @coversNothing
418
     */
419
    public function testCanPackRepresentativeLargerSamples2D(
420
        $test,
0 ignored issues
show
Unused Code introduced by
The parameter $test is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
421
        $boxes,
422
        $items,
423
        $expectedBoxes2D,
424
        $expectedBoxes3D,
0 ignored issues
show
Unused Code introduced by
The parameter $expectedBoxes3D is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
425
        $expectedWeightVariance2D,
426
        $expectedWeightVariance3D
0 ignored issues
show
Unused Code introduced by
The parameter $expectedWeightVariance3D is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
427
    ) {
428
        $expectedItemCount = 0;
429
        $packedItemCount = 0;
430
431
        $packer = new Packer();
432
        foreach ($boxes as $box) {
433
            $packer->addBox($box);
434
        }
435
        foreach ($items as $item) {
436
            $packer->addItem(
437
                new TestItem(
438
                    $item['name'],
439
                    $item['width'],
440
                    $item['length'],
441
                    $item['depth'],
442
                    $item['weight'],
443
                    true
0 ignored issues
show
Unused Code introduced by
The call to TestItem::__construct() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
444
                ),
445
                $item['qty']
446
            );
447
            $expectedItemCount += $item['qty'];
448
        }
449
        $packedBoxes = $packer->pack();
450
451
        foreach (clone $packedBoxes as $packedBox) {
452
            $packedItemCount += $packedBox->getItems()->count();
453
        }
454
455
456
        self::assertEquals($expectedBoxes2D, $packedBoxes->count());
457
        self::assertEquals($expectedItemCount, $packedItemCount);
458
        self::assertEquals($expectedWeightVariance2D, (int)$packedBoxes->getWeightVariance());
459
    }
460
461
    public function getSamples()
462
    {
463
        $expected = ['2D' => [], '3D' => []];
464
465
        $expected2DData = fopen(__DIR__ . '/data/expected2d.csv', 'r');
466 View Code Duplication
        while ($data = fgetcsv($expected2DData)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
467
            $expected['2D'][$data[0]] = array('boxes' => $data[1], 'weightVariance' => $data[2]);
468
        }
469
        fclose($expected2DData);
470
471
        $expected3DData = fopen(__DIR__ . '/data/expected3d.csv', 'r');
472 View Code Duplication
        while ($data = fgetcsv($expected3DData)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
473
            $expected['3D'][$data[0]] = array('boxes' => $data[1], 'weightVariance' => $data[2]);
474
        }
475
        fclose($expected3DData);
476
477
        $boxes = [];
478
        $boxData = fopen(__DIR__ . '/data/boxes.csv', 'r');
479
        while ($data = fgetcsv($boxData)) {
480
            $boxes[] = new TestBox(
481
                $data[0],
482
                $data[1],
483
                $data[2],
484
                $data[3],
485
                $data[4],
486
                $data[5],
487
                $data[6],
488
                $data[7],
489
                $data[8]
490
            );
491
        }
492
        fclose($boxData);
493
494
        $tests = [];
495
        $itemData = fopen(__DIR__ . '/data/items.csv', 'r');
496
        while ($data = fgetcsv($itemData)) {
497
498
            if (isset($tests[$data[0]])) {
499
                $tests[$data[0]]['items'][] = array(
500
                    'qty' => $data[1],
501
                    'name' => $data[2],
502
                    'width' => $data[3],
503
                    'length' => $data[4],
504
                    'depth' => $data[5],
505
                    'weight' => $data[6]
506
                );
507
            } else {
508
                $tests[$data[0]] = array(
509
                    'test' => $data[0],
510
                    'boxes' => $boxes,
511
                    'items' => array(
512
                        array(
513
                            'qty' => $data[1],
514
                            'name' => $data[2],
515
                            'width' => $data[3],
516
                            'length' => $data[4],
517
                            'depth' => $data[5],
518
                            'weight' => $data[6]
519
                        )
520
                    ),
521
                    'expected2D' => $expected['2D'][$data[0]]['boxes'],
522
                    'expected3D' => $expected['3D'][$data[0]]['boxes'],
523
                    'weightVariance2D' => $expected['2D'][$data[0]]['weightVariance'],
524
                    'weightVariance3D' => $expected['3D'][$data[0]]['weightVariance']
525
                );
526
            }
527
        }
528
        fclose($itemData);
529
530
        return $tests;
531
    }
532
533
}
534