GetLogisticByCodesTest.php 2.0 KB

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