/** * @param array $attributes * * @return Inventory */ protected function newInventory(array $attributes = []) { $metric = $this->newMetric(); $category = $this->newCategory(); if (count($attributes) > 0) { return Inventory::create($attributes); } return Inventory::create(['metric_id' => $metric->id, 'category_id' => $category->id, 'name' => 'Milk', 'description' => 'Delicious Milk']); }
public function testScopedInventories() { $metric = new Metric(); $metric->name = 'Test Metric'; $metric->symbol = 'Test Symbol'; $metric->save(); $productsCategory = Category::create(['name' => 'Products', 'belongs_to' => 'Products']); $miscCategory = Category::create(['name' => 'Misc', 'belongs_to' => 'Misc']); $noItemCategory = Category::create(['name' => 'No Items']); $productItem = Inventory::create(['name' => '', 'category_id' => $productsCategory->id, 'metric_id' => $metric->id]); $miscItem = Inventory::create(['name' => 'Item 1', 'category_id' => $miscCategory->id, 'metric_id' => $metric->id]); $miscItem2 = Inventory::create(['name' => 'Item 2', 'category_id' => $miscCategory->id, 'metric_id' => $metric->id]); $this->assertEquals(0, $noItemCategory->inventories()->count()); $this->assertEquals(1, $productsCategory->inventories()->count()); $this->assertEquals(2, $miscCategory->inventories()->count()); }
public function testGetTotalVariantStock() { $this->newCategory(); $this->newMetric(); $coke = Inventory::create(['name' => 'Coke', 'description' => 'Delicious Pop', 'metric_id' => 1, 'category_id' => 1]); $cherryCoke = $coke->createVariant('Cherry Coke'); $cherryCoke->makeVariantOf($coke); $vanillaCherryCoke = $cherryCoke->createVariant('Vanilla Cherry Coke'); $vanillaCherryCoke->makeVariantOf($cherryCoke); DB::shouldReceive('beginTransaction')->once()->andReturn(true); DB::shouldReceive('commit')->once()->andReturn(true); Event::shouldReceive('fire')->once()->andReturn(true); $location = $this->newLocation(); // Allow duplicate movements configuration option Config::shouldReceive('get')->twice()->andReturn(true); // Stock change reasons (one for create, one for put, for both items) Lang::shouldReceive('get')->times(4)->andReturn('Default Reason'); $cherryCoke->createStockOnLocation(20, $location); $vanillaCherryCoke->createStockOnLocation(20, $location); $this->assertEquals(40, $coke->getTotalVariantStock()); }