| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace Tests\Services\CacheShelfService;
- use App\MaterialBox;
- use App\Services\CacheShelfService;
- use App\Services\ForeignHaiRoboticsService;
- use App\Services\StationCacheShelfGridService;
- use App\Station;
- use App\StationTask;
- use App\StationTaskChildren;
- use App\StationTaskMaterialBox;
- use App\Traits\TestMockSubServices;
- use Tests\TestCase;
- class PutBinToStoreTest extends TestCase
- {
- use TestMockSubServices;
- /** @var CacheShelfService $cacheShelfService */
- protected $cacheShelfService;
- protected $data = [];
- protected function setup(): void
- {
- parent::setup(); // todo: change the autogenerated stub
- $this->data['station'] = factory(Station::class)->create(['station_type_id'=>1]);
- $this->data['materialBox'] = factory(MaterialBox::class)->create();
- $this->data['stationTask'] = factory(StationTask::class)->create();
- $this->data['stationTask']['station_id'] = $this->data['station']['id'];
- $this->data['stationTask']->save();
- $this->data['stationTaskMaterialBox'] = factory(StationTaskMaterialBox::class)->create([
- 'station_id' => $this->data['station']['id'],
- 'material_box_id' => $this->data['materialBox']['id'],
- 'status' => '待处理'
- ]);
- $this->data['stationTaskMaterialBox']['station_task_id'] = $this->data['stationTask']['id'];
- $this->data['stationTaskMaterialBox']->save();
- $this->data['stationTaskChildren'] = StationTaskChildren::query()->create([
- "station_task_id" => $this->data['stationTask']['id'],
- ]);
- $this->data['stationTaskChildren']["station_taskable_type"] = StationTaskMaterialBox::class;
- $this->data['stationTaskChildren']["station_taskable_id"]= $this->data['stationTaskMaterialBox']['id'];
- $this->data['stationTaskChildren']->save();
- $this->cacheShelfService = $this->subMock([
- 'class' => CacheShelfService::class,
- 'subService' => [
- [
- 'serviceName' => 'foreignHaiRoboticsService',
- 'class' => ForeignHaiRoboticsService::class,
- 'methods' => [
- 'controlHaiRobot' => true
- ]
- ]
- ]
- ]);
- }
- public function testPutBinToStore()
- {
- $bool = $this->cacheShelfService->putBinToStore($this->data['station']);
- $boxTask = StationTaskMaterialBox::query()->where('material_box_id', $this->data['materialBox']['id'])->get();
- $this->assertTrue($bool);
- $this->assertNotEmpty($boxTask);
- }
- protected function tearDown(): void
- {
- StationTaskChildren::query()->where('station_taskable_id',$this->data['stationTaskMaterialBox']['id'])->delete();
- $materialBox = MaterialBox::query()->where('id', $this->data['materialBox']['id'])->first();
- if ($materialBox) {
- $stationTaskMaterialBoxes = StationTaskMaterialBox::query()->where('material_box_id', $materialBox['id'])->get();
- foreach ($stationTaskMaterialBoxes as $stationTaskMaterialBox) {
- if ($stationTaskMaterialBox->station) $stationTaskMaterialBox->station->delete();
- if ($stationTaskMaterialBox->stationTask) $stationTaskMaterialBox->stationTask->delete();
- $stationTaskMaterialBox->delete();
- }
- $materialBox->delete();
- }
- if($this->data['stationTaskChildren'])StationTaskChildren::query()->where('id',$this->data['stationTaskChildren']['id'])->delete();
- parent::tearDown();
- }
- }
|