GetLogisticByCodesTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Tests\Services\LogisticService;
  3. use App\OracleBasCustomer;
  4. use App\Services\LogisticService;
  5. use Illuminate\Foundation\Testing\RefreshDatabase;
  6. use Tests\TestCase;
  7. class GetLogisticByCodesTest extends TestCase
  8. {
  9. use RefreshDatabase;
  10. /** @var LogisticService $service */
  11. private $service;
  12. private $data;
  13. public function setUp(): void
  14. {
  15. parent::setUp(); // TODO: Change the autogenerated stub
  16. $this->service = app('LogisticService');
  17. $baseCustomers = OracleBasCustomer::query()
  18. ->selectRaw('Customer_Type,CustomerID,Descr_C')
  19. ->where('Customer_Type','CA')
  20. ->get();
  21. $this->data['baseCustomers'] = $baseCustomers;
  22. $this->data['codes'] = $baseCustomers->map(function($baseCustomer){
  23. return $baseCustomer->customerid;
  24. });
  25. }
  26. /**
  27. * @test
  28. */
  29. public function getLogisticByCodes()
  30. {
  31. $logistics = $this->service->getLogisticByCodes($this->data['codes']);
  32. $this->assertNotEmpty($logistics);
  33. foreach ($logistics as $logistic) {
  34. $baseCustomer = $this->data['baseCustomers']->where('customerid',$logistic->code)->where('descr_c',$logistic->name);
  35. $this->assertNotEmpty($baseCustomer);
  36. $this->assertEquals(1,$baseCustomer->count());
  37. }
  38. foreach ($this->data['baseCustomers'] as $baseCustomer) {
  39. $logistic = $logistics->where('code',$baseCustomer['customerid'])->where('name',$baseCustomer['descr_c']);
  40. $this->assertNotEmpty($logistic);
  41. $this->assertEquals(1,$logistic->count());
  42. }
  43. }
  44. public function tearDown(): void
  45. {
  46. cache()->flush();
  47. parent::tearDown(); // TODO: Change the autogenerated stub
  48. }
  49. }