GetOwnerByCodeTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. /** @var OwnerService $service */
  12. private $service;
  13. private $data = [];
  14. public function setUp(): void
  15. {
  16. parent::setUp(); // TODO: Change the autogenerated stub
  17. cache()->flush();
  18. $this->service = app('OwnerService');
  19. $owner = factory(Owner::class)->create();
  20. $basCustomer = factory(OracleBasCustomer::class)->make(["customer_type"=>'OW',"customerid"=>$owner->code]);
  21. $this->data['basCustomer'] = $basCustomer;
  22. $this->data['owner'] = $owner;
  23. $this->mock('OracleBasCustomerService',function ($mock)use($basCustomer){
  24. $mock->shouldReceive('first')->andReturn($basCustomer);
  25. });
  26. }
  27. /**
  28. * @test
  29. */
  30. public function getOwnerByCode()
  31. {
  32. $owner = $this->service->getOwnerByCode($this->data['owner']['code']);
  33. $this->assertEquals($owner->id,$this->data['owner']['id']);
  34. $this->assertEquals($owner->name,$this->data['owner']['name']);
  35. $this->assertEquals($owner->code,$this->data['owner']['code']);
  36. }
  37. /**
  38. * @test
  39. */
  40. public function ownerIsNotExist()
  41. {
  42. $this->data['owner']->delete();
  43. cache()->forget('getOwnerByCode_'.$this->data['owner']['code']);
  44. $owner = $this->service->getOwnerByCode($this->data['owner']['code']);
  45. $this->data['owner'] = $owner;
  46. $this->assertEquals($owner->id,$this->data['owner']['id']);
  47. $this->assertEquals($owner->code,$this->data['owner']['code']);
  48. $this->assertEquals($owner->name,$this->data['owner']['name']);
  49. $this->data['owner']= $owner;
  50. }
  51. public function tearDown(): void
  52. {
  53. cache()->forget('getOwnerByCode_'.$this->data['owner']['code']);
  54. $this->data['owner']->delete();
  55. parent::tearDown(); // TODO: Change the autogenerated stub
  56. }
  57. }