BindMaterialBoxTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\StationTaskMaterialBoxService;
  7. use App\Services\StationTaskService;
  8. use App\Station;
  9. use App\Storage;
  10. use App\Traits\TestMockSubServices;
  11. use Tests\TestCase;
  12. class BindMaterialBoxTest extends TestCase
  13. {
  14. use TestMockSubServices;
  15. /** @var CacheShelfService $cacheShelfService*/
  16. public $cacheShelfService;
  17. public $data = [];
  18. protected function setUp(): void
  19. {
  20. parent::setUp(); // TODO: Change the autogenerated stub
  21. $this->cacheShelfService = $this->subMock([
  22. 'class' => CacheShelfService::class,
  23. 'methods' => [
  24. '_stationCacheLightOn' => new MaterialBox(['code' => 200])
  25. ],
  26. ]);
  27. $this->data['station'] = factory(Station::class)->create();
  28. $this->data['materialBox'] = factory(MaterialBox::class)->create();
  29. $this->data['storage'] = factory(Storage::class)->create(['station_id' => $this->data['station']['id']]);
  30. }
  31. public function testBindMaterialBoxTest()
  32. {
  33. $result = $this->cacheShelfService->bindMaterialBox($this->data['station']['code'],$this->data['materialBox']['code']);
  34. $this->assertTrue($result['success']);
  35. $storage = Storage::query()->whereKey($this->data['storage']['id'])->first();
  36. $this->assertEquals($this->data['materialBox']['id'],$storage['material_box_id']);
  37. }
  38. protected function tearDown(): void
  39. {
  40. if($this->data['station'] ?? false) Station::query()->whereKey($this->data['station']['id'])->delete();
  41. if($this->data['materialBox'] ?? false) MaterialBox::query()->whereKey($this->data['materialBox']['id'])->delete();
  42. if($this->data['storage'] ?? false) Storage::query()->whereKey($this->data['storage']['id'])->delete();
  43. parent::tearDown(); // TODO: Change the autogenerated stub
  44. }
  45. }