| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace Tests\Inventory\model;
- use App\InventoryAccount;
- use App\InventoryAccountMission;
- use Illuminate\Support\Str;
- use Tests\TestCase;
- class InventoryAccountTest extends TestCase
- {
- public $inventory;
- public $inventoryMission;
- function setUp(): void
- {
- parent::setUp(); // TODO: Change the autogenerated stub
- $this->inventory=factory(InventoryAccount::class)->create();
- $total=$this->inventory['total'];
- for ($i=0;$i<$total;$i++){
- $this->inventoryMissions=InventoryAccountMission::create([
- 'inventory_account_id'=>$this->inventory['id'],
- 'location'=>Str::random(5),
- 'commodity_id'=>256226,
- 'produced_at'=>null,
- 'valid_at'=>null,
- 'stored_at'=>null,
- 'batch_number'=>'',
- 'erp_type_position'=>'',
- 'quality'=>'',
- 'stored_amount'=>50,
- 'valid_amount'=>'',
- 'verified_amount'=>'',
- 're_checked_amount'=>'',
- 'difference_amount'=>'',
- 'occupied_amount'=>'',
- 'checked'=>'否',
- 'returned'=>'无',
- ]);
- }
- }
- function testOwner(){
- $this->assertEquals($this->inventory['owner_id'],$this->inventory->owner['id']);
- }
- function testInventoryMissions(){
- $this->assertEquals($this->inventory->id,$this->inventory->inventoryMissions['inventory_account_id']);
- }
- function testGetSurplusAttribute(){
- $surplus=$this->inventory['surplus'];
- $this->assertEquals($surplus,$this->inventory['total']-$this->inventory['processed']);
- }
- function testGetProcessedAmount(){
- $processed=InventoryAccountMission::where('inventory_account_id',$this->inventory['id'])->where('checked','是')->count();
- $this->assertEquals($processed,$this->inventory['processed']);
- }
- function testGetDifferenceAmount(){
- $difference=InventoryAccountMission::where('inventory_account_id',$this->inventory['id'])->where('difference_amount','>',0)->count();
- $this->assertEquals($difference,$this->inventory['difference']);
- }
- function testGetReturnedAmount(){
- $returned=InventoryAccountMission::where('inventory_account_id',$this->inventory['id'])->where('returned','是')->count();
- $this->assertEquals($returned,$this->inventory['returned']);
- }
- function tearDown(): void
- {
- InventoryAccountMission::where('inventory_account_id',$this->inventory['id'])->delete();
- InventoryAccount::where('id',$this->inventory['id'])->forceDelete();
- parent::tearDown(); // TODO: Change the autogenerated stub
- }
- }
|