GetOwnerByCodeTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. $basCustomer = factory(OracleBasCustomer::class)->make([]);
  20. $this->data['owner'] = factory(Owner::class)->create();
  21. $this->data['basCustomer'] = $basCustomer;
  22. $this->service = app('OwnerService');
  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. }
  36. /**
  37. * @test
  38. */
  39. public function ownerIsNotExist()
  40. {
  41. $this->data['owner']->delete();
  42. $owner = $this->service->getOwnerByCode($this->data['owner']['code']);
  43. $this->assertEquals($owner->code,$this->data['basCustomer']['customerid']);
  44. $this->assertEquals($owner->name,$this->data['basCustomer']['descr_c']);
  45. $this->data['owner']= $owner;
  46. }
  47. public function tearDown(): void
  48. {
  49. cache()->flush();
  50. $this->data['owner']->delete();
  51. parent::tearDown(); // TODO: Change the autogenerated stub
  52. }
  53. }