FeatureServiceTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace Tests\Unit\Customer;
  3. use App\Feature;
  4. use App\Services\FeatureService;
  5. use Tests\TestCase;
  6. class FeatureServiceTest extends TestCase
  7. {
  8. /** @var FeatureService */
  9. public $service;
  10. public $data;
  11. protected function setUp(): void
  12. {
  13. parent::setUp();
  14. $this->service = app(FeatureService::class);
  15. $this->data = [
  16. [
  17. "type" => "商品名称",
  18. "logic" => "包含",
  19. "describe"=>"衣服",
  20. ],[
  21. "type" => "订单类型",
  22. "logic" => "不包含",
  23. "describe"=>"创建",
  24. ],[
  25. "type" => "承运商",
  26. "logic" => "等于",
  27. "describe"=>"顺丰",
  28. ],[
  29. "type" => "店铺类型",
  30. "logic" => "不包含",
  31. "describe"=>"日用品",
  32. ],[
  33. "type" => "商品名称",
  34. "logic" => "不包含",
  35. "describe"=>"鞋子",
  36. ],[
  37. "type" => "订单类型",
  38. "logic" => "包含",
  39. "describe"=>"取消",
  40. ]
  41. ];
  42. }
  43. public function testGetMapArray(){
  44. factory(Feature::class,3)->create();
  45. $models = $this->service->getMapArray();
  46. $this->assertGreaterThanOrEqual(3,count($models));
  47. }
  48. public function testTranslationFeature(){
  49. $model1 = factory(Feature::class)->create($this->data[0]);
  50. $model2 = factory(Feature::class)->create($this->data[1]);
  51. $model3 = factory(Feature::class)->create($this->data[2]);
  52. $str = $model1->id."&(".$model2->id."|".$model3->id.")";
  53. $result = $this->service->translationFeature($str);
  54. $this->assertEquals(3,count($result));
  55. $this->assertEquals("订单类型",$result[1]["type"]);
  56. $this->assertEquals(false,$result[0]["strategyGroupStartSign"]);
  57. $this->assertEquals(true,$result[1]["strategyGroupStartSign"]);
  58. $this->assertEquals("并且",$result[1]["calculation"]);
  59. $this->assertEquals(true,$result[2]["strategyGroupEndSign"]);
  60. $this->assertEquals("或",$result[2]["calculation"]);
  61. }
  62. public function testAnalysisFeature(){
  63. $model1 = factory(Feature::class)->create($this->data[4]);
  64. $model2 = factory(Feature::class)->create($this->data[5]);
  65. $model3 = factory(Feature::class)->create($this->data[3]);
  66. $params = [
  67. [
  68. "strategyGroupStartSign" => true,
  69. "calculation" => "",
  70. "type"=>"商品名称",
  71. "logic"=>"不包含",
  72. "describe"=>"鞋子",
  73. "strategyGroupEndSign" => false,
  74. ],[
  75. "strategyGroupStartSign" => false,
  76. "calculation" => "并且",
  77. "type"=>"订单类型",
  78. "logic"=>"包含",
  79. "describe"=>"取消",
  80. "strategyGroupEndSign" => true,
  81. ],[
  82. "strategyGroupStartSign" => false,
  83. "calculation" => "或",
  84. "type"=>"店铺类型",
  85. "logic"=>"不包含",
  86. "describe"=>"日用品",
  87. "strategyGroupEndSign" => false,
  88. ]
  89. ];
  90. $expected = "(".$model1->id."&".$model2->id.")|".$model3->id;
  91. $result = $this->service->analysisFeature($params);
  92. $this->assertIsArray($result);
  93. $this->assertCount(2,$result);
  94. $this->assertArrayHasKey("feature",$result);
  95. $this->assertEquals($expected,$result["feature"]);
  96. }
  97. public function testFormatFeature(){
  98. }
  99. //$expected = "商品名称 包含 衣服 并且(订单类型 不包含 创建 或 承运商 等于 顺丰)";
  100. public function testTruncate(){
  101. Feature::query()->truncate();
  102. $feature = Feature::query()->get();
  103. $this->assertCount(0,$feature);
  104. }
  105. }