Last active
August 22, 2019 10:15
-
-
Save yuchitung/6e0a7fe1847046b965efd343be239d9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ShipmentManager extends StockManager implements Receivable | |
{ | |
use EmployeeTrait; | |
public function receive(ProductDTO $product) | |
{ | |
$qty = $product->getQuantity(); | |
$stock = $this->stockRepository | |
->skipPresenter(true) | |
->firstOrCreate([ | |
'product_id' => $product->getId(), | |
'warehouse_id' => config('setting.warehouse.taipei'), | |
]); | |
$stock->quantity = $stock->quantity + (int)$qty; | |
$stock->save(); | |
$this->stockMvtRepository->create( | |
[ | |
'stock_id' => $stock->id, | |
'quantity' => $qty, | |
'sign' => 1, | |
'employee_id' => $this->getEmployee()->id, | |
] | |
); | |
return $this; | |
} | |
} | |
public function test_receive() | |
{ | |
/** arrange */ | |
$product = new ProductDTO(); | |
$employee = new \stdClass(); | |
//assign ... | |
$mock = Mockery::mock(ShipmentManager::class)->makePartial(); | |
$mock->shouldReceive('getEmployee')->andReturn($employee); | |
$shipmentManager = $this->app->make(ShipmentManager::class);//應該是這裡沒有處理好 | |
/** act */ | |
$shipmentManager->receive($product); | |
/** assert */ | |
//從 model 取出 data 看數量有沒有+1 | |
} |
mouson
commented
Aug 22, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment