CreateStoreTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. $this->service=app(StoreService::class);
  18. $this->asnHeaders=OracleDOCASNHeader::query()
  19. ->with(['asnType', 'asnStatus', 'asnDetails' => function ($query) {
  20. $query->with(['lineStatus', 'qualityStatus','basSku']);
  21. }])
  22. ->where('addTime', '>=', Carbon::parse('2020-10-21 00:00:00')->format('Y-m-d H:i:s'))
  23. ->get();
  24. }
  25. public function testCreateStore(){
  26. if (!$this->asnHeaders) return null;
  27. $this->stores=$this->service->createStore($this->asnHeaders);
  28. $this->assertNotEmpty($this->stores);
  29. }
  30. public function tearDown(): void
  31. {
  32. $storeIds=[];
  33. foreach ($this->stores as $store){
  34. array_push($storeIds,$store->id);
  35. }
  36. DB::table('stores')->whereIn('asn_code',data_get($this->asnHeaders,'*.asnno'))->delete();
  37. DB::table('store_items')->whereIn('store_id',$storeIds)->delete();
  38. parent::tearDown(); // TODO: Change the autogenerated stub
  39. }
  40. }