From 45ee85ea7f2e13ff2716c17440a81202c5ba9f3e Mon Sep 17 00:00:00 2001 From: Farhan Munshi Date: Fri, 15 May 2026 10:03:58 -0400 Subject: [PATCH] Add Packrift ecommerce carton fixture tests --- tests/PackriftEcommerceFixtureTest.php | 181 +++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 tests/PackriftEcommerceFixtureTest.php diff --git a/tests/PackriftEcommerceFixtureTest.php b/tests/PackriftEcommerceFixtureTest.php new file mode 100644 index 00000000..908b269c --- /dev/null +++ b/tests/PackriftEcommerceFixtureTest.php @@ -0,0 +1,181 @@ + '1066', + 'title' => '10x6x6 ECT-32 Kraft Long Corrugated Boxes - 25 Bundle', + 'url' => 'https://packrift.com/products/10x6x6-ect-32-kraft-long-corrugated-boxes-25-bundle', + 'width' => 152, + 'length' => 254, + 'depth' => 152, + ], + [ + 'sku' => '1684', + 'title' => '16x8x4 ECT-32 Kraft Corrugated Shipping Boxes - 25 Bundle', + 'url' => 'https://packrift.com/products/16x8x4-ect-32-kraft-corrugated-shipping-boxes-25-bundle', + 'width' => 203, + 'length' => 406, + 'depth' => 102, + ], + [ + 'sku' => '20146', + 'title' => '20x14x6 ECT-32 Kraft Corrugated Boxes - Shallow Depth Design, Bundle of 25', + 'url' => 'https://packrift.com/products/20x14x6-ect-32-kraft-corrugated-boxes-shallow-depth-design-bundle-of-25', + 'width' => 356, + 'length' => 508, + 'depth' => 152, + ], + [ + 'sku' => '24108', + 'title' => '24x10x8 ECT-32 Kraft Corrugated Long Boxes - Easy-Pack Design, Bundle of 25', + 'url' => 'https://packrift.com/products/24x10x8-ect-32-kraft-corrugated-long-boxes-easy-pack-design-bundle-of-25', + 'width' => 254, + 'length' => 610, + 'depth' => 203, + ], + [ + 'sku' => '402020', + 'title' => '40x20x20 ECT-32 Kraft Corrugated Boxes - Bulk Shipping, 10 Pack', + 'url' => 'https://packrift.com/products/40x20x20-ect-32-kraft-corrugated-boxes-bulk-shipping-10-pack', + 'width' => 508, + 'length' => 1016, + 'depth' => 508, + ], + ]; + + #[DataProvider('packableEcommerceOrders')] + public function testCanPackEcommerceOrdersUsingPackriftSampleCartons( + string $expectedSku, + array $items + ): void { + $packer = new Packer(); + $this->addPackriftSampleCartons($packer); + + $expectedItemCount = 0; + foreach ($items as $item) { + $expectedItemCount += $item['qty']; + $packer->addItem( + new TestItem( + $item['description'], + $item['width'], + $item['length'], + $item['depth'], + $item['weight'], + Rotation::BestFit + ), + $item['qty'] + ); + } + + $packedBoxes = iterator_to_array($packer->pack(), false); + + self::assertCount(1, $packedBoxes); + self::assertCount($expectedItemCount, $packedBoxes[0]->items); + self::assertSame("Packrift {$expectedSku}", $packedBoxes[0]->box->getReference()); + } + + public function testThrowsWhenOrderDoesNotFitPackriftSampleCartons(): void + { + $this->expectException(NoBoxesAvailableException::class); + + $packer = new Packer(); + $this->addPackriftSampleCartons($packer); + $packer->addItem(new TestItem('oversized equipment case', 1200, 600, 600, 15000, Rotation::BestFit)); + + $packer->pack(); + } + + public static function packableEcommerceOrders(): array + { + return [ + 'small accessory order' => [ + '1066', + [ + [ + 'qty' => 1, + 'description' => 'small boxed accessory', + 'width' => 220, + 'length' => 120, + 'depth' => 90, + 'weight' => 300, + ], + ], + ], + 'shallow kit order' => [ + '20146', + [ + [ + 'qty' => 1, + 'description' => 'shallow ecommerce kit', + 'width' => 480, + 'length' => 300, + 'depth' => 120, + 'weight' => 900, + ], + ], + ], + 'long item order' => [ + '24108', + [ + [ + 'qty' => 1, + 'description' => 'long ecommerce item', + 'width' => 560, + 'length' => 220, + 'depth' => 150, + 'weight' => 700, + ], + ], + ], + ]; + } + + private function addPackriftSampleCartons(Packer $packer): void + { + foreach (self::PACKRIFT_CARTONS as $carton) { + self::assertStringStartsWith('https://packrift.com/products/', $carton['url']); + + $packer->addBox( + new TestBox( + "Packrift {$carton['sku']}", + $carton['width'], + $carton['length'], + $carton['depth'], + 0, + $carton['width'], + $carton['length'], + $carton['depth'], + self::MAX_WEIGHT + ) + ); + } + } +}