GetOwnerByCodesTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Tests\Services\OwnerService;
  3. use App\OracleBasCustomer;
  4. use App\Services\OwnerService;
  5. use Illuminate\Foundation\Testing\RefreshDatabase;
  6. use Illuminate\Foundation\Testing\WithFaker;
  7. use Tests\TestCase;
  8. class GetOwnerByCodesTest extends TestCase
  9. {
  10. use RefreshDatabase;
  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. $basCustomers = OracleBasCustomer::query()->selectRaw('customerid')->where('Customer_Type','OW')->get();
  19. $this->data = $basCustomers->map(function($basCustomer){
  20. return $basCustomer->customerid;
  21. });
  22. }
  23. /**
  24. * @test
  25. */
  26. public function getOwnerByCodesNormal(){
  27. $owners = $this->service->getOwnerByCodes($this->data);
  28. if(empty($owners)){
  29. $this->assertEmpty($owners);
  30. $this->assertEmpty($this->data);
  31. return;
  32. };
  33. $this->assertEquals($owners->count(),$this->data->count());
  34. foreach ($this->data as $datum) {
  35. $owner = $owners->where('code',$datum);
  36. $this->assertNotNull($owner);
  37. }
  38. }
  39. public function tearDown(): void
  40. {
  41. cache()->flush();
  42. parent::tearDown(); // TODO: Change the autogenerated stub
  43. }
  44. }