CreateStoreTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Tests\Services\StoreService;
  3. use App\OracleDOCASNHeader;
  4. use App\Services\StoreService;
  5. use Carbon\Carbon;
  6. use Illuminate\Support\Facades\DB;
  7. use Tests\TestCase;
  8. class CreateStoreTest extends TestCase
  9. {
  10. /** @var StoreService $service */
  11. public $service;
  12. public $asnHeaders;
  13. public $stores;
  14. public function setUp(): void
  15. {
  16. parent::setUp(); // TODO: Change the autogenerated stub
  17. $startDate = \Illuminate\Support\Carbon::now()->subSeconds(300);
  18. $this->service=app(StoreService::class);
  19. $this->asnHeaders=OracleDOCASNHeader::query()
  20. ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
  21. $query->with(['lineStatus', 'qualityStatus','basSku']);
  22. }])
  23. ->where('addTime', '>=', $startDate)
  24. ->get();
  25. }
  26. public function testCreateStore(){
  27. if (!$this->asnHeaders) return null;
  28. $this->service->createStore($this->asnHeaders);
  29. $this->stores=$this->service->getByWms($this->asnHeaders);
  30. $this->assertNotEmpty($this->stores);
  31. $this->assertNotNull($this->asnHeaders);
  32. }
  33. public function tearDown(): void
  34. {
  35. $storeIds=[];
  36. foreach ($this->stores as $store){
  37. array_push($storeIds,$store->id);
  38. }
  39. DB::table('stores')->whereIn('asn_code',data_get($this->asnHeaders,'*.asnno'))->delete();
  40. DB::table('store_items')->whereIn('store_id',$storeIds)->delete();
  41. parent::tearDown(); // TODO: Change the autogenerated stub
  42. }
  43. }