GetWareHouseByCodeTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Tests\Services\WarehouseService;
  3. use App\OracleBasCustomer;
  4. use App\Services\OracleBasCustomerService;
  5. use App\Services\WarehouseService;
  6. use App\Warehouse;
  7. use Illuminate\Foundation\Testing\RefreshDatabase;
  8. use Tests\TestCase;
  9. class GetWareHouseByCodeTest extends TestCase
  10. {
  11. /** @var WarehouseService $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('WarehouseService');
  18. $warehouse = factory(Warehouse::class)->create();
  19. $basCustomer = factory(OracleBasCustomer::class)->make(['customerid'=>$warehouse->code,'descr_c'=>$warehouse->name,'customer_type'=>'OW']);
  20. $this->data['warehouse'] = $warehouse;
  21. $this->data['code'] = $warehouse->code;
  22. $this->data['basCustomer'] = $basCustomer;
  23. $this->mock(OracleBasCustomerService::class,function($mock)use($basCustomer){
  24. $mock->shouldReceive('first')->andReturn($basCustomer);
  25. });
  26. }
  27. /**
  28. * @test
  29. */
  30. public function getWareHouseByCodeTest()
  31. {
  32. $warehouse = $this->service->getWareHouseByCode($this->data['code']);
  33. $this->assertEquals($warehouse->toArray(),$this->data['warehouse']->toArray());
  34. }
  35. /**
  36. * @test
  37. */
  38. public function warehouseIsNotExist(){
  39. $this->data['warehouse']->delete();
  40. cache()->forget('WareHouse_'.$this->data['warehouse']->code);
  41. $warehouse = $this->service->getWareHouseByCode($this->data['code']);
  42. $this->data['warehouse'] = $warehouse;
  43. $this->assertEquals($warehouse['name'],$this->data['basCustomer']['descr_c']);
  44. $this->assertEquals($warehouse['code'],$this->data['basCustomer']['customerid']);
  45. }
  46. public function tearDown(): void
  47. {
  48. $this->data['warehouse']->delete();
  49. cache()->forget('WareHouse_'.$this->data['warehouse']->code);
  50. parent::tearDown(); // TODO: Change the autogenerated stub
  51. }
  52. }