File: D:/HostingSpaces/SBogers10/shop.komma.nl/tests/Unit/ShipmentTest.php
<?php
//TODO Update when shop v1 is ready
//
//namespace App\Tests\Unit;
//
//use App\Addresses\Models\Address;
//use App\Cart\ShoppingCartItem;
//use App\Cart\ShoppingCartService;
//use App\Cart\ShoppingCartServiceInterface;
//use App\Checkout\CheckoutServiceInterface;
//use App\Products\Product\Product;
//use App\Products\ProductableInterface;
//use App\Products\ProductComposite\ProductComposite;
//use App\Products\ProductGroup\ProductGroup;
//use App\Products\ProductGroupBehaviour\ProductGroupBehaviour;
//use App\ShipmentGroups\ShipmentGroup;
//use App\ShipmentGroups\ShipmentGroupService;
//use App\ShipmentGroups\ShipmentGroupStatus;
//use App\Shipments\Shipment;
//use App\Shipments\ShipmentService;
//use App\Shipments\ShipmentStatus;
//use Tests\TestCase;
//use Komma\KMS\Sites\SiteServiceInterface;;
//use Illuminate\Foundation\Testing\DatabaseTransactions;
//
//class ShipmentTest extends TestCase
//{
// use DatabaseTransactions; //Automatically rolls back database actions after tests
//
// /** @var ShoppingCartServiceInterface */
// private $shoppingCart;
//
// /** @var CheckoutServiceInterface $checkoutService */
// private $checkoutService;
//
// /**
// * @group Shipment
// * @test
// */
// public function testShipmentAndGroupCreation()
// {
// /** @var SiteServiceInterface $siteService */
// $siteService = app(SiteServiceInterface::class);
// $siteService->setCurrentSiteToDefault();
//
// $shipmentService = new ShipmentService();
// $shipmentGroupService = new ShipmentGroupService();
// $this->shoppingCart = new ShoppingCartService();
// $this->checkoutService = app(CheckoutServiceInterface::class);
//
// //Get a random customer user to test with
// /** @var SiteUser $customer */
// $customer = factory(SiteUser::class)->create();
// $this->assertInstanceOf(SiteUser::class, $customer);
//
// //Give it an address
// /** @var Address $address */
// $address = factory(Address::class)->create();
// $customer->addresses()->save($address);
//
// //Put some random products in the shopping cart
// $products = factory(Product::class, 3)->create();
// $this->assertCount(3, $products);
//
// //Put some random product groups in the shopping cart
// $productGroups = factory(ProductGroup::class, 2)->make();
// $productGroups = $productGroups->map(function(ProductGroup $productGroup) {
// $behaviour = factory(ProductGroupBehaviour::class)->create();
// $productGroup->productGroupBehaviour()->associate($behaviour);
// $productGroup->save();
// return $productGroup;
// });
//
// $this->assertCount(2, $productGroups);
//
// //Put some random product composites in the shopping cart
// $productComposites = factory(ProductComposite::class, 1)->create();
// $this->assertCount(1, $productComposites);
//
// //Build an order
// $allProductables = collect();
// $allProductables = $allProductables->merge($products);
// $allProductables = $allProductables->merge($productGroups);
// $allProductables = $allProductables->merge($productComposites);
//
// $allProductables->each(function(ProductableInterface $productable) {
// /** @var ShoppingCartItem $shoppingCartItem */
// $this->shoppingCart->addProductable($productable, mt_rand(1, 3));
// });
//
// //Create an order from the items in the shoppingCart
// $order = $this->checkoutService->createOrder($this->shoppingCart, $customer, $customer->addresses()->first(), $customer->addresses()->first());
//
// //Create a shipment from an order
// $shipment = $shipmentService->makeForOrder($order, '3S'.mt_rand(1000, 9999), 'Part x will arrive later as it is out of stock.');
// $shipment->save();
// $this->assertInstanceOf(Shipment::class, $shipment);
// $this->assertTrue($shipment->exists);
// $this->assertTrue($shipment->status == ShipmentStatus::NEW);
//
// //Create a group from that order
// $shipmentGroup = $shipmentGroupService->createForShipment($shipment);
// $this->assertInstanceOf(ShipmentGroup::class, $shipmentGroup);
// $this->assertTrue($shipmentGroup->status == ShipmentGroupStatus::PENDING);
//
// $this->assertTrue($shipmentGroup->shipments()->count() == 1);
// $this->assertTrue($order->shipments()->count() == 1);
// }
//}