GetLogisticByCodeTest.php 1.6 KB

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