GetLogisticByCodeTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Tests\Services\LogisticService;
  3. use App\Logistic;
  4. use App\OracleBasCustomer;
  5. use App\Services\LogisticService;
  6. use Illuminate\Foundation\Testing\RefreshDatabase;
  7. use Tests\TestCase;
  8. class GetLogisticByCodeTest extends TestCase
  9. {
  10. use RefreshDatabase;
  11. /** @var LogisticService $service */
  12. private $service;
  13. private $data = [];
  14. public function setUp(): void
  15. {
  16. parent::setUp(); // TODO: Change the autogenerated stub
  17. $this->service = app('LogisticService');
  18. $logistic = factory(Logistic::class)->create(['code'=>'AABBCCDD1']);
  19. $basCustomer = factory(OracleBasCustomer::class)->make(["customer_type"=>'OW',"customerid"=>$logistic->code]);
  20. $this->data['basCustomers'] = $basCustomer;
  21. $this->data['logistic'] = $logistic;
  22. $this->mock('OracleBasCustomerService',function ($mock)use($basCustomer){
  23. $mock->shouldReceive('first')->andReturn($basCustomer);
  24. });
  25. }
  26. /**
  27. * @test
  28. */
  29. public function getLogisticByCode()
  30. {
  31. $logistic = $this->service->getLogisticByCode($this->data['logistic']['code']);
  32. $this->assertEquals($logistic->id,$this->data['logistic']['id']);
  33. $this->assertEquals($logistic->code,$this->data['logistic']['code']);
  34. $this->assertEquals($logistic->name,$this->data['logistic']['name']);
  35. }
  36. public function tearDown(): void
  37. {
  38. cache()->forget('getLogisticByCode_'.$this->data['logistic']['code']);
  39. $this->data['logistic']->delete();
  40. parent::tearDown(); // TODO: Change the autogenerated stub
  41. }
  42. }