|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Behat\Behat\Context\Context; |
|
4
|
|
|
use DVDoug\BoxPacker\PackedBox; |
|
5
|
|
|
use DVDoug\BoxPacker\PackedBoxList; |
|
6
|
|
|
use DVDoug\BoxPacker\Packer; |
|
7
|
|
|
use DVDoug\BoxPacker\Test\TestBox; |
|
8
|
|
|
use DVDoug\BoxPacker\Test\TestItem; |
|
9
|
|
|
use PHPUnit\Framework\Assert; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Defines application features from the specific context. |
|
13
|
|
|
*/ |
|
14
|
|
|
class FeatureContext implements Context |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var Packer |
|
18
|
|
|
*/ |
|
19
|
|
|
private $packer; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var PackedBoxList |
|
23
|
|
|
*/ |
|
24
|
|
|
private $packedBoxes; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Initializes context. |
|
28
|
|
|
* |
|
29
|
|
|
* Every scenario gets its own context instance. |
|
30
|
|
|
* You can also pass arbitrary arguments to the |
|
31
|
|
|
* context constructor through behat.yml. |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->packer = new Packer(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @Given /^there is a box "([^"]+)", which has external dimensions (\d+)mm w × (\d+)mm l × (\d+)mm d × (\d+)g and internal dimensions (\d+)mm w × (\d+)mm l × (\d+)mm d and has a max weight of (\d+)g$/ |
|
40
|
|
|
*/ |
|
41
|
|
|
public function thereIsABox( |
|
42
|
|
|
$boxType, |
|
43
|
|
|
$outerWidth, |
|
44
|
|
|
$outerLength, |
|
45
|
|
|
$outerDepth, |
|
46
|
|
|
$emptyWeight, |
|
47
|
|
|
$innerWidth, |
|
48
|
|
|
$innerLength, |
|
49
|
|
|
$innerDepth, |
|
50
|
|
|
$maxWeight |
|
51
|
|
|
) { |
|
52
|
|
|
$box = new TestBox($boxType, $outerWidth, $outerLength, $outerDepth, $emptyWeight, $innerWidth, $innerLength, $innerDepth, $maxWeight); |
|
53
|
|
|
$this->packer->addBox($box); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @When /^I add (\d+) x "([^"]+)" with dimensions (\d+)mm w × (\d+)mm l × (\d+)mm d × (\d+)g$/ |
|
58
|
|
|
*/ |
|
59
|
|
|
public function thereIsAnItem( |
|
60
|
|
|
$qty, |
|
61
|
|
|
$itemName, |
|
62
|
|
|
$width, |
|
63
|
|
|
$length, |
|
64
|
|
|
$depth, |
|
65
|
|
|
$weight |
|
66
|
|
|
) { |
|
67
|
|
|
$item = new TestItem($itemName, $width, $length, $depth, $weight, false); |
|
68
|
|
|
$this->packer->addItem($item, $qty); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @When /^I add (\d+) x keep flat "([^"]+)" with dimensions (\d+)mm w × (\d+)mm l × (\d+)mm d × (\d+)g$/ |
|
73
|
|
|
*/ |
|
74
|
|
|
public function thereIsAKeepFlatItem( |
|
75
|
|
|
$qty, |
|
76
|
|
|
$itemName, |
|
77
|
|
|
$width, |
|
78
|
|
|
$length, |
|
79
|
|
|
$depth, |
|
80
|
|
|
$weight |
|
81
|
|
|
) { |
|
82
|
|
|
$item = new TestItem($itemName, $width, $length, $depth, $weight, true); |
|
83
|
|
|
$this->packer->addItem($item, $qty); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @Then /^I should have (\d+) boxes of type "([^"]+)"$/ |
|
88
|
|
|
*/ |
|
89
|
|
|
public function thereExistsBoxes( |
|
90
|
|
|
$qty, |
|
91
|
|
|
$boxType |
|
92
|
|
|
) { |
|
93
|
|
|
$foundBoxes = 0; |
|
94
|
|
|
|
|
95
|
|
|
/** @var PackedBox $packedBox */ |
|
96
|
|
|
foreach ($this->packedBoxes as $packedBox) { |
|
97
|
|
|
if ($packedBox->getBox()->getReference() === $boxType) { |
|
98
|
|
|
$foundBoxes++; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
Assert::assertEquals($qty, $foundBoxes); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @When I do a packing |
|
107
|
|
|
*/ |
|
108
|
|
|
public function iDoAPacking() |
|
109
|
|
|
{ |
|
110
|
|
|
$this->packedBoxes = $this->packer->pack(); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|