ajun 5 лет назад
Родитель
Сommit
81173e3a91

+ 4 - 1
database/factories/StationCacheShelfGridFactory.php

@@ -7,6 +7,9 @@ use Faker\Generator as Faker;
 
 $factory->define(StationCacheShelfGrid::class, function (Faker $faker) {
     return [
-        //
+        'station_id' => $faker->numberBetween(0,1),
+        'material_box_id' => $faker->numberBetween(0,100),
+        'grid_id' => 1,
+        'status' => 0
     ];
 });

+ 2 - 1
database/factories/StationFactory.php

@@ -7,6 +7,7 @@ use Faker\Generator as Faker;
 
 $factory->define(Station::class, function (Faker $faker) {
     return [
-        //
+        'name' => $faker->name,
+        'code' => $faker->name,
     ];
 });

+ 24 - 1
tests/Services/CacheShelfService/GetTasksTest.php

@@ -2,7 +2,10 @@
 
 
 namespace Tests\Services\CacheShelfService;
+
 use App\Services\CacheShelfService;
+use App\Station;
+use App\StationCacheShelfGrid;
 use Tests\TestCase;
 
 class GetTasksTest extends TestCase
@@ -10,15 +13,35 @@ class GetTasksTest extends TestCase
     /** @var CacheShelfService $service */
     protected $service;
 
+    protected $data = [];
+
     protected function setup(): void
     {
+        parent::setup();
+
         $this->service = app(CacheShelfService::class);
+        $this->data['station'] = factory(Station::class)->create();
+        $collect = collect();
+        for ($i = 1; $i <= 8; $i++) {
+            $collect->push(StationCacheShelfGrid::query()->create([
+                'station_id' => $this->data['station']['id'] ?? '',
+                'grid_id' => $i,
+                'status' => 1,
+            ]));
+        }
+        $this->data['grids'] = $collect;
+    }
 
-        parent::setup(); // todo: change the autogenerated stub
+    public function testGetTasks()
+    {
+        $grids = $this->service->getTasks($this->data['station']);
+        $this->assertEquals(count($grids), count($this->data['grids']));
     }
 
     protected function tearDown(): void
     {
+        Station::query()->where('id', $this->data['station']['id'])->delete();
+        StationCacheShelfGrid::query()->where('station_id', $this->data['station']['id'])->delete();
         parent::tearDown(); // TODO: Change the autogenerated stub
     }
 

+ 12 - 3
tests/Services/CacheShelfService/LightOnTest.php

@@ -4,23 +4,32 @@
 namespace Tests\Services\CacheShelfService;
 
 use App\Services\CacheShelfService;
+use App\Station;
 use Tests\TestCase;
 
 class LightOnTest extends testcase
 {
     /** @var CacheShelfService $service */
     protected $service;
-
+    protected $data = [];
     protected function setup(): void
     {
+        parent::setUp();
         $this->service = app(CacheShelfService::class);
+        $this->data['station'] = factory(Station::class)->create();
+    }
 
-        parent::setup(); // todo: change the autogenerated stub
+    public function testLightOn()
+    {
+        $row = '';      //  从右到左
+        $col = '';      //  从下到上
+        $this->service->lightOn($this->data['station'],$row,$col);
     }
 
     protected function tearDown(): void
     {
-        parent::tearDown(); // TODO: Change the autogenerated stub
+        Station::query()->where('id',$this->data['station']['id'])->delete();
+        parent::tearDown();
     }
 
 }

+ 18 - 2
tests/Services/CacheShelfService/PutBinToStoreTest.php

@@ -2,7 +2,10 @@
 
 
 namespace Tests\Services\CacheShelfService;
+use App\MaterialBox;
 use App\Services\CacheShelfService;
+use App\Station;
+use App\StationCacheShelfGrid;
 use Tests\TestCase;
 
 
@@ -10,12 +13,25 @@ class PutBinToStoreTest extends TestCase
 {
     /** @var CacheShelfService $service */
     protected $service;
-
+    protected $data =[];
     protected function setup(): void
     {
+        parent::setup(); // todo: change the autogenerated stub
         $this->service = app(CacheShelfService::class);
+        $this->data['station'] = factory(Station::class)->create(['name' => 'test', 'code'=> 'test']);
+        $this->data['materialBox'] = factory(MaterialBox::class)->create();
+        $this->data['stationCacheShelfGrid'] = factory(StationCacheShelfGrid::class)->create([
+            'station_id'=>$this->data['station']['id'],
+            'material_box_id'=>$this->data['materialBox']['id'],
+            'status' => 1
+        ]);
 
-        parent::setup(); // todo: change the autogenerated stub
+    }
+
+    public function testPutBinToStore()
+    {
+        //     public function putBinToStore(Station $station,MaterialBox $materialBox,StationCacheShelfGrid $grid): bool
+        $this->service->putBinToStore($this->data['station'],$this->data['materialBox'],$this->data['stationCacheShelfGrid']);
     }
 
     protected function tearDown(): void