GetOwnerByCodeTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Tests\Services\OwnerService;
  3. use App\OracleBasCustomer;
  4. use App\Owner;
  5. use App\Services\OwnerService;
  6. use Illuminate\Foundation\Testing\RefreshDatabase;
  7. use Illuminate\Foundation\Testing\WithFaker;
  8. use Tests\TestCase;
  9. class GetOwnerByCodeTest extends TestCase
  10. {
  11. use RefreshDatabase;
  12. /** @var OwnerService $service */
  13. private $service;
  14. private $data = [];
  15. public function setUp(): void
  16. {
  17. parent::setUp(); // TODO: Change the autogenerated stub
  18. cache()->flush();
  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['basCustomer'] = $basCustomer;
  23. $this->data['owner'] = $owner;
  24. $this->mock('OracleBasCustomerService',function ($mock)use($basCustomer){
  25. $mock->shouldReceive('first')->andReturn($basCustomer);
  26. });
  27. }
  28. /**
  29. * @test
  30. */
  31. public function getOwnerByCode()
  32. {
  33. $owner = $this->service->getOwnerByCode($this->data['owner']['code']);
  34. $this->assertEquals($owner->id,$this->data['owner']['id']);
  35. $this->assertEquals($owner->name,$this->data['owner']['name']);
  36. $this->assertEquals($owner->code,$this->data['owner']['code']);
  37. }
  38. /**
  39. * @test
  40. */
  41. public function ownerIsNotExist()
  42. {
  43. $this->data['owner']->delete();
  44. cache()->forget('getOwnerByCode_'.$this->data['owner']['code']);
  45. $owner = $this->service->getOwnerByCode($this->data['owner']['code']);
  46. $this->data['owner'] = $owner;
  47. $this->assertEquals($owner->id,$this->data['owner']['id']);
  48. $this->assertEquals($owner->code,$this->data['owner']['code']);
  49. $this->assertEquals($owner->name,$this->data['owner']['name']);
  50. $this->data['owner']= $owner;
  51. }
  52. public function tearDown(): void
  53. {
  54. cache()->forget('getOwnerByCode_'.$this->data['owner']['code']);
  55. $this->data['owner']->delete();
  56. parent::tearDown(); // TODO: Change the autogenerated stub
  57. }
  58. }