GetLocationTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace Tests\Services\StationCacheShelfGrid;
  3. use App\Station;
  4. use App\StationCacheShelfGrid;
  5. use Tests\TestCase;
  6. class GetLocationTest extends TestCase
  7. {
  8. protected $data = [];
  9. protected function setUp(): void
  10. {
  11. parent::setUp();
  12. $row = 3;
  13. $col = 2;
  14. $this->data['grid_id'] = ($row-1)*3+$col;
  15. $this->data['station'] = factory(Station::class)->create();
  16. $this->data['grid'] = factory(StationCacheShelfGrid::class)->create(['station_id'=>$this->data['station']['id'],'grid_id'=>$this->data['grid_id']]);
  17. $this->data['code'] = 'HAI'.$this->data['station']['code'].'-0'. (2 - $col + 1).'-0'.(2-$row+1);
  18. }
  19. function testGetLocation()
  20. {
  21. $location = StationCacheShelfGrid::getLocation($this->data['station'],$this->data['grid']);
  22. $this->assertEquals($this->data['grid_id'],$this->data['grid']['grid_id']);
  23. $this->assertEquals($this->data['code'],$location);
  24. }
  25. protected function tearDown(): void
  26. {
  27. Station::query()->where('id',$this->data['station']['id'])->delete();
  28. StationCacheShelfGrid::query()->where('id',$this->data['grid']['id'])->delete();
  29. parent::tearDown();
  30. }
  31. }