GetWareHouseByCodeTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. use RefreshDatabase;
  12. /** @var WarehouseService $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('WarehouseService');
  19. $warehouse = factory(Warehouse::class)->create();
  20. $basCustomer = factory(OracleBasCustomer::class)->make(['customerid'=>$warehouse->code,'descr_c'=>$warehouse->name,'customer_type'=>'OW']);
  21. $this->data['warehouse'] = $warehouse;
  22. $this->data['code'] = $warehouse->code;
  23. $this->data['basCustomer'] = $basCustomer;
  24. $this->mock(OracleBasCustomerService::class,function($mock)use($basCustomer){
  25. $mock->shouldReceive('first')->andReturn($basCustomer);
  26. });
  27. }
  28. /**
  29. * @test
  30. */
  31. public function getWareHouseByCodeTest()
  32. {
  33. $warehouse = $this->service->getWareHouseByCode($this->data['code']);
  34. $this->assertEquals($warehouse->toArray(),$this->data['warehouse']->toArray());
  35. }
  36. /**
  37. * @test
  38. */
  39. public function warehouseIsNotExist(){
  40. $this->data['warehouse']->delete();
  41. cache()->forget('WareHouse_'.$this->data['warehouse']->code);
  42. $warehouse = $this->service->getWareHouseByCode($this->data['code']);
  43. $this->data['warehouse'] = $warehouse;
  44. $this->assertEquals($warehouse['name'],$this->data['basCustomer']['descr_c']);
  45. $this->assertEquals($warehouse['code'],$this->data['basCustomer']['customerid']);
  46. }
  47. public function tearDown(): void
  48. {
  49. $this->data['warehouse']->delete();
  50. cache()->forget('WareHouse_'.$this->data['warehouse']->code);
  51. parent::tearDown(); // TODO: Change the autogenerated stub
  52. }
  53. }