InventoryTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Tests\Inventory\model;
  3. use App\Inventory;
  4. use App\InventoryMission;
  5. use Illuminate\Support\Str;
  6. use Tests\TestCase;
  7. class InventoryTest extends TestCase
  8. {
  9. public $inventory;
  10. public $inventoryMission;
  11. function setUp(): void
  12. {
  13. parent::setUp(); // TODO: Change the autogenerated stub
  14. $this->inventory=factory(Inventory::class)->create();
  15. $total=$this->inventory['total'];
  16. for ($i=0;$i<$total;$i++){
  17. $this->inventoryMissions=InventoryMission::create([
  18. 'inventory_id'=>$this->inventory['id'],
  19. 'location'=>Str::random(5),
  20. 'commodity_id'=>256226,
  21. 'produced_at'=>null,
  22. 'valid_at'=>null,
  23. 'stored_at'=>null,
  24. 'batch_number'=>'',
  25. 'erp_type_position'=>'',
  26. 'quality'=>'',
  27. 'stored_amount'=>50,
  28. 'valid_amount'=>'',
  29. 'verified_amount'=>'',
  30. 're_checked_amount'=>'',
  31. 'difference_amount'=>'',
  32. 'occupied_amount'=>'',
  33. 'checked'=>'否',
  34. 'returned'=>'无',
  35. ]);
  36. }
  37. }
  38. function testOwner(){
  39. $this->assertEquals($this->inventory['owner_id'],$this->inventory->owner['id']);
  40. }
  41. function testInventoryMissions(){
  42. $this->assertEquals($this->inventory->id,$this->inventory->inventoryMissions['inventory_id']);
  43. }
  44. function testGetSurplusAttribute(){
  45. $surplus=$this->inventory['surplus'];
  46. $this->assertEquals($surplus,$this->inventory['total']-$this->inventory['processed']);
  47. }
  48. function testGetProcessedAmount(){
  49. $processed=InventoryMission::where('inventory_id',$this->inventory['id'])->where('checked','是')->count();
  50. $this->assertEquals($processed,$this->inventory['processed']);
  51. }
  52. function testGetDifferenceAmount(){
  53. $difference=InventoryMission::where('inventory_id',$this->inventory['id'])->where('difference_amount','>',0)->count();
  54. $this->assertEquals($difference,$this->inventory['difference']);
  55. }
  56. function testGetReturnedAmount(){
  57. $returned=InventoryMission::where('inventory_id',$this->inventory['id'])->where('returned','是')->count();
  58. $this->assertEquals($returned,$this->inventory['returned']);
  59. }
  60. function tearDown(): void
  61. {
  62. InventoryMission::where('inventory_id',$this->inventory['id'])->delete();
  63. Inventory::where('id',$this->inventory['id'])->forceDelete();
  64. parent::tearDown(); // TODO: Change the autogenerated stub
  65. }
  66. }