GetOwnerByCodeTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. $this->service = app('OwnerService');
  18. $owner = factory(Owner::class)->create();
  19. $basCustomer = factory(OracleBasCustomer::class)->make(["customer_type"=>'OW',"customerid"=>$owner->code]);
  20. $this->data['basCustomer'] = $basCustomer;
  21. $this->data['owner'] = $owner;
  22. $this->mock('OracleBasCustomerService',function ($mock)use($basCustomer){
  23. $mock->shouldReceive('first')->andReturn($basCustomer);
  24. });
  25. }
  26. /**
  27. * @test
  28. */
  29. public function getOwnerByCode()
  30. {
  31. $owner = $this->service->getOwnerByCode($this->data['owner']['code']);
  32. $this->assertEquals($owner->id,$this->data['owner']['id']);
  33. $this->assertEquals($owner->name,$this->data['owner']['name']);
  34. $this->assertEquals($owner->code,$this->data['owner']['code']);
  35. }
  36. public function tearDown(): void
  37. {
  38. cache()->forget('getOwnerByCode_'.$this->data['owner']['code']);
  39. $this->data['owner']->delete();
  40. parent::tearDown(); // TODO: Change the autogenerated stub
  41. }
  42. }