PushOrderUpdateCacheTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Tests\Services\OrderService;
  3. use App\OracleDOCOrderHeader;
  4. use App\Services\OrderService;
  5. use Illuminate\Foundation\Testing\RefreshDatabase;
  6. use Illuminate\Support\Facades\Cache;
  7. use Illuminate\Support\Str;
  8. use Tests\TestCase;
  9. class PushOrderUpdateCacheTest extends TestCase
  10. {
  11. use RefreshDatabase;
  12. /** @var OrderService $service */
  13. public $service;
  14. public $data;
  15. private $renewal_list;
  16. private $hasKey;
  17. private $prefixKey;
  18. public function setUp(): void
  19. {
  20. parent::setUp(); // TODO: Change the autogenerated stub
  21. $this->service = app('OrderService');
  22. $arr = [Str::uuid(),Str::uuid(),Str::uuid(),Str::uuid(),Str::uuid()];
  23. $list = [];
  24. foreach ($arr as $item) {
  25. $orderHeader= new OracleDOCOrderHeader();
  26. $orderHeader->orderno = (string)$item;
  27. $list[] = $orderHeader;
  28. }
  29. $this->data['OrderHeader'] = $list;
  30. $this->renewal_list = config('sync.order_sync.cache_prefix.renewal_list');
  31. $this->hasKey = config('sync.order_sync.cache_prefix.renewal_has');
  32. $this->prefixKey = config('sync.order_sync.cache_prefix.renewal');
  33. }
  34. /**
  35. * @test
  36. */
  37. public function pushOrderUpdateCache()
  38. {
  39. $this->service->pushOrderCache($this->data['OrderHeader'],$this->prefixKey,$this->hasKey,$this->renewal_list);
  40. try {
  41. Cache::get($this->hasKey);
  42. $this->assertNotNull(Cache::get($this->hasKey));
  43. foreach ($this->data['OrderHeader'] as $datum) {
  44. $this->assertNotEmpty(Cache::get($this->prefixKey.$datum->orderno));
  45. }
  46. $this->assertNotNull($this->data['OrderHeader']);
  47. } catch (\Exception $e) {
  48. $this->assertNotNull($e);
  49. }
  50. }
  51. public function tearDown(): void
  52. {
  53. try {
  54. Cache::forget($this->renewal_list);
  55. Cache::forget($this->hasKey);
  56. foreach ($this->data['OrderHeader'] as $item) {
  57. Cache::forget($this->prefixKey . $item->orderno);
  58. }
  59. } catch (\Exception $e) {
  60. }
  61. parent::tearDown(); // TODO: Change the autogenerated stub
  62. }
  63. }