inventory=factory(Inventory::class)->create(); $total=$this->inventory['total']; for ($i=0;$i<$total;$i++){ $this->inventoryMissions=InventoryMission::create([ 'inventory_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_id']); } function testGetSurplusAttribute(){ $surplus=$this->inventory['surplus']; $this->assertEquals($surplus,$this->inventory['total']-$this->inventory['processed']); } function testGetProcessedAmount(){ $processed=InventoryMission::where('inventory_id',$this->inventory['id'])->where('checked','是')->count(); $this->assertEquals($processed,$this->inventory['processed']); } function testGetDifferenceAmount(){ $difference=InventoryMission::where('inventory_id',$this->inventory['id'])->where('difference_amount','>',0)->count(); $this->assertEquals($difference,$this->inventory['difference']); } function testGetReturnedAmount(){ $returned=InventoryMission::where('inventory_id',$this->inventory['id'])->where('returned','是')->count(); $this->assertEquals($returned,$this->inventory['returned']); } function tearDown(): void { InventoryMission::where('inventory_id',$this->inventory['id'])->delete(); Inventory::where('id',$this->inventory['id'])->forceDelete(); parent::tearDown(); // TODO: Change the autogenerated stub } }