| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace Tests\Unit\Customer;
- use App\Feature;
- use App\Services\FeatureService;
- use Tests\TestCase;
- class FeatureServiceTest extends TestCase
- {
- /** @var FeatureService */
- public $service;
- public $data;
- protected function setUp(): void
- {
- parent::setUp();
- $this->service = app(FeatureService::class);
- $this->data = [
- [
- "type" => "商品名称",
- "logic" => "包含",
- "describe"=>"衣服",
- ],[
- "type" => "订单类型",
- "logic" => "不包含",
- "describe"=>"创建",
- ],[
- "type" => "承运商",
- "logic" => "等于",
- "describe"=>"顺丰",
- ],[
- "type" => "店铺类型",
- "logic" => "不包含",
- "describe"=>"日用品",
- ],[
- "type" => "商品名称",
- "logic" => "不包含",
- "describe"=>"鞋子",
- ],[
- "type" => "订单类型",
- "logic" => "包含",
- "describe"=>"取消",
- ]
- ];
- }
- public function testGetMapArray(){
- factory(Feature::class,3)->create();
- $models = $this->service->getMapArray();
- $this->assertGreaterThanOrEqual(3,count($models));
- }
- public function testTranslationFeature(){
- $model1 = factory(Feature::class)->create($this->data[0]);
- $model2 = factory(Feature::class)->create($this->data[1]);
- $model3 = factory(Feature::class)->create($this->data[2]);
- $str = $model1->id."&(".$model2->id."|".$model3->id.")";
- $result = $this->service->translationFeature($str);
- $this->assertEquals(3,count($result));
- $this->assertEquals("订单类型",$result[1]["type"]);
- $this->assertEquals(false,$result[0]["strategyGroupStartSign"]);
- $this->assertEquals(true,$result[1]["strategyGroupStartSign"]);
- $this->assertEquals("并且",$result[1]["calculation"]);
- $this->assertEquals(true,$result[2]["strategyGroupEndSign"]);
- $this->assertEquals("或",$result[2]["calculation"]);
- }
- public function testAnalysisFeature(){
- $model1 = factory(Feature::class)->create($this->data[4]);
- $model2 = factory(Feature::class)->create($this->data[5]);
- $model3 = factory(Feature::class)->create($this->data[3]);
- $params = [
- [
- "strategyGroupStartSign" => true,
- "calculation" => "",
- "type"=>"商品名称",
- "logic"=>"不包含",
- "describe"=>"鞋子",
- "strategyGroupEndSign" => false,
- ],[
- "strategyGroupStartSign" => false,
- "calculation" => "并且",
- "type"=>"订单类型",
- "logic"=>"包含",
- "describe"=>"取消",
- "strategyGroupEndSign" => true,
- ],[
- "strategyGroupStartSign" => false,
- "calculation" => "或",
- "type"=>"店铺类型",
- "logic"=>"不包含",
- "describe"=>"日用品",
- "strategyGroupEndSign" => false,
- ]
- ];
- $expected = "(".$model1->id."&".$model2->id.")|".$model3->id;
- $result = $this->service->analysisFeature($params);
- $this->assertIsArray($result);
- $this->assertCount(2,$result);
- $this->assertArrayHasKey("feature",$result);
- $this->assertEquals($expected,$result["feature"]);
- }
- public function testFormatFeature(){
- }
- //$expected = "商品名称 包含 衣服 并且(订单类型 不包含 创建 或 承运商 等于 顺丰)";
- public function testTruncate(){
- Feature::query()->truncate();
- $feature = Feature::query()->get();
- $this->assertCount(0,$feature);
- }
- }
|