PutBinToStoreTest.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace Tests\Services\CacheShelfService;
  3. use App\MaterialBox;
  4. use App\Services\CacheShelfService;
  5. use App\Services\ForeignHaiRoboticsService;
  6. use App\Services\StationCacheShelfGridService;
  7. use App\Services\StationTaskMaterialBoxService;
  8. use App\Station;
  9. use App\StationCacheShelfGrid;
  10. use App\StationTaskMaterialBox;
  11. use App\Traits\TestMockSubServices;
  12. use Tests\TestCase;
  13. class PutBinToStoreTest extends TestCase
  14. {
  15. use TestMockSubServices;
  16. /** @var CacheShelfService $cacheShelfService */
  17. protected $cacheShelfService;
  18. protected $data =[];
  19. protected function setup(): void
  20. {
  21. parent::setup(); // todo: change the autogenerated stub
  22. $this->data['station'] = factory(Station::class)->create(['name' => 'test', 'code'=> 'test']);
  23. $this->data['materialBox'] = factory(MaterialBox::class)->create();
  24. $this->data['stationTaskMaterialBox'] = factory(StationTaskMaterialBox::class)->create([
  25. 'station_id' => $this->data['station']['id'],
  26. 'material_box_id' => $this->data['materialBox']['id'],
  27. 'status' => 1
  28. ]);
  29. $this->data['stationCacheShelfGrid'] = factory(StationCacheShelfGrid::class)->create([
  30. 'station_id'=>$this->data['station']['id'],
  31. 'material_box_id'=>$this->data['materialBox']['id'],
  32. 'status' => 1
  33. ]);
  34. $this->cacheShelfService = $this->subMock([
  35. 'class' => CacheShelfService::class,
  36. 'subService' => [
  37. // [
  38. // 'serviceName' => 'stationTaskMaterialBoxService',
  39. // 'class' => StationTaskMaterialBoxService::class,
  40. // 'methods' => [
  41. // 'createByStationMaterialBox' => $this->data['stationTaskMaterialBox']
  42. // ]
  43. // ],
  44. [
  45. 'serviceName' => 'stationCacheShelfGridService',
  46. 'class' => StationCacheShelfGridService::class,
  47. 'methods' => [
  48. 'processGrid' => null
  49. ]
  50. ],
  51. [
  52. 'serviceName' => 'foreignHaiRoboticsService',
  53. 'class' => ForeignHaiRoboticsService::class,
  54. 'methods' => [
  55. // 'putBinToStore_fromCacheShelf' => true,
  56. 'controlHaiRobot' => true
  57. ]
  58. ]
  59. ]
  60. ]);
  61. }
  62. public function testPutBinToStore()
  63. {
  64. $bool = $this->cacheShelfService->putBinToStore($this->data['station'],$this->data['materialBox'],$this->data['stationCacheShelfGrid']);
  65. $boxTask = StationTaskMaterialBox::query()->where('station_id',$this->data['station']['id'])->where('material_box_id',$this->data['materialBox']['id'])->first();
  66. $this->assertTrue($bool);
  67. $this->assertNotEmpty($boxTask);
  68. $this->assertEquals($boxTask['status'],'待处理');
  69. }
  70. protected function tearDown(): void
  71. {
  72. Station::query()->where('id',$this->data['station']['id'])->delete();
  73. MaterialBox::query()->where('id',$this->data['materialBox']['id'])->delete();
  74. StationCacheShelfGrid::query()->where('id',$this->data['stationCacheShelfGrid']['id'])->delete();
  75. StationTaskMaterialBox::query()->where('id',$this->data['stationTaskMaterialBox']['id'])->delete();
  76. parent::tearDown();
  77. }
  78. }