CreateStoreTest.php 1.6 KB

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