| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace Tests\Services\OrderCommodityService;
- use App\Commodity;
- use App\OracleActAllocationDetails;
- use App\OracleDOCOrderHeader;
- use App\Order;
- use App\OrderCommodity;
- use App\Owner;
- use App\Services\CommodityService;
- use App\Services\OrderCommodityService;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Illuminate\Foundation\Testing\WithFaker;
- use Tests\TestCase;
- class SyncOrderCommodityTest extends TestCase
- {
- // use RefreshDatabase;
- /** @var OrderCommodityService $service */
- private $service;
- private $data = [];
- public function setUp(): void
- {
- parent::setUp(); // TODO: Change the autogenerated stub
- $this->service = app('OrderCommodityService');
- $owners = factory(Owner::class)->times(3)->create();
- $this->data['owners'] = $owners;
- $commodities = collect();
- foreach ($owners as $owner) {
- $counts = rand(1,20);
- for($i=0;$i<=$counts;$i++){
- $commodities->push(factory(Commodity::class)->create(['owner_id'=>$owner->id]));
- }
- }
- $this->data['commodities'] = $commodities;
- $orderHeaders = collect();$orders = collect();
- for ($i=0;$i<2000;$i++) {
- $owner = $owners->random();
- $commodity_list = $commodities->where('owner_id',$owner->id);
- $order = factory(Order::class)->create(['owner_id'=>$owner->id]);
- $orderHeader = factory(OracleDOCOrderHeader::class)->make(['orderno' => $order->code, 'customerid' => $owner->code]);
- $oracleActAllocationDetails = collect();
- for($count=1;$count<=4;$count++){
- $commodity = $commodity_list->random();
- $oracleActAllocationDetail = factory(OracleActAllocationDetails::class)->make([
- 'orderno'=>$orderHeader['orderno'],
- 'customerid' => $orderHeader['customerid'],
- 'sku' => $commodity->sku
- ]);
- $oracleActAllocationDetails->push($oracleActAllocationDetail);
- }
- $orderHeader->setRelation('actAllocationDetails',$oracleActAllocationDetails);
- $orderHeaders->push($orderHeader);
- $orders->push($order);
- }
- $this->data['orders'] = $orders;
- $this->data['orderHeaders'] = $orderHeaders;
- $this->mock(CommodityService::class,function($mock)use($commodities){
- $mock->shouldReceive('get_')->andReturn($commodities);
- });
- }
- /**
- * @test
- */
- public function syncOrderCommodity()
- {
- for ($i = 0 ;$i<4; $i++) {
- $this->service->syncOrderCommodity($this->data['orderHeaders']);
- }
- $counts = OrderCommodity::query()->whereIn('order_id',data_get($this->data['orders'],'*.id'))->get()->count();
- $actAllocationDetailsCounts = 0;
- foreach ($this->data['orderHeaders'] as $orderHeader) {
- $actAllocationDetails = $orderHeader->actAllocationDetails;
- $actAllocationDetailsCounts += $actAllocationDetails->count();
- }
- $this->assertEquals($counts,$actAllocationDetailsCounts);
- }
- public function tearDown(): void
- {
- cache()->flush();
- // Order::query()->whereIn('id',data_get($this->data['orders'],'*.id'))->delete();
- // Owner::query()->whereIn('id',data_get($this->data['owners'],'*.id'))->delete();
- // Commodity::query()->whereIn('id',data_get($this->data['commodities'],'*.id'))->delete();
- parent::tearDown(); // TODO: Change the autogenerated stub
- }
- }
|