|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Created by PhpStorm. |
|
5
|
|
|
* User: pjxh |
|
6
|
|
|
* Date: 15-11-1 |
|
7
|
|
|
* Time: 下午5:12 |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace Overtrue\Wechat\Test\Shop\Data; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use Overtrue\Wechat\Media; |
|
13
|
|
|
use Overtrue\Wechat\Shop\Data\Product; |
|
14
|
|
|
use Overtrue\Wechat\Test\TestBase; |
|
15
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
16
|
|
|
|
|
17
|
|
|
class ProductTest extends TestBase |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
protected $categoryId = '536891949'; |
|
21
|
|
|
|
|
22
|
|
|
public function testSetBaseAttr() |
|
23
|
|
|
{ |
|
24
|
|
|
$product = new Product(); |
|
25
|
|
|
|
|
26
|
|
|
$data = $product->setBaseAttr('主图',array('图一','图二'),null,'name',$this->categoryId); |
|
|
|
|
|
|
27
|
|
|
$this->assertInstanceOf(Product::class,$data); |
|
28
|
|
|
|
|
29
|
|
|
$product = new Product(true); |
|
30
|
|
|
$data = $product->setBaseAttr('主图',array('图一','图二')); |
|
31
|
|
|
$this->assertInstanceOf(Product::class,$data); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testSetDetail() |
|
35
|
|
|
{ |
|
36
|
|
|
$product = new Product(); |
|
37
|
|
|
$data = $product->setDetail('img','图片'); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertInstanceOf(Product::class,$data); |
|
40
|
|
|
|
|
41
|
|
|
$data = $product->setDetail('text','文字'); |
|
42
|
|
|
$this->assertInstanceOf(Product::class,$data); |
|
43
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testSetProperty() |
|
47
|
|
|
{ |
|
48
|
|
|
|
|
49
|
|
|
$product = new Product(); |
|
50
|
|
|
$data = $product->setProperty('id','vid'); |
|
51
|
|
|
$this->assertInstanceOf(Product::class,$data); |
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
public function testSetSkuInfo() |
|
57
|
|
|
{ |
|
58
|
|
|
|
|
59
|
|
|
$product = new Product(); |
|
60
|
|
|
$data = $product->setSkuInfo('id',array('vid','vid')); |
|
61
|
|
|
$this->assertInstanceOf(Product::class,$data); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
public function testSetSkuList() |
|
66
|
|
|
{ |
|
67
|
|
|
|
|
68
|
|
|
$product = new Product(); |
|
69
|
|
|
$data = $product->setSkuList('原价','微信价','sku_ico','sku 库存',array('id'=>'vid','id1'=>'vid1')); |
|
|
|
|
|
|
70
|
|
|
$this->assertInstanceOf(Product::class,$data); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testSetAttrext() |
|
74
|
|
|
{ |
|
75
|
|
|
$product = new Product(); |
|
76
|
|
|
$data = $product->setAttrext(0,1,1,1); |
|
77
|
|
|
$this->assertInstanceOf(Product::class,$data); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
public function testSetLocation() |
|
82
|
|
|
{ |
|
83
|
|
|
$product = new Product(); |
|
84
|
|
|
$data = $product->setLocation('浙江省','杭州市','滨江区阿里园'); |
|
85
|
|
|
$this->assertInstanceOf(Product::class,$data); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function testSetDeliveryInfo() |
|
89
|
|
|
{ |
|
90
|
|
|
$product = new Product(); |
|
91
|
|
|
$data = $product->setDeliveryInfo(1,'400184180'); |
|
|
|
|
|
|
92
|
|
|
$this->assertInstanceOf(Product::class,$data); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function testSetExpress() |
|
96
|
|
|
{ |
|
97
|
|
|
$product = new Product(); |
|
98
|
|
|
$data = $product->setExpress('id','price'); |
|
99
|
|
|
$this->assertInstanceOf(Product::class,$data); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
public function testGetData() |
|
104
|
|
|
{ |
|
105
|
|
|
|
|
106
|
|
|
$media = new Media($this->config->appId,$this->config->appSecret); |
|
|
|
|
|
|
107
|
|
|
$image = $media->lists('image'); |
|
108
|
|
|
|
|
109
|
|
|
//未上架 |
|
110
|
|
|
$product = new Product(); |
|
111
|
|
|
$product->setBaseAttr($image['item'][0]['url'],array($image['item'][0]['url'],$image['item'][0]['url']),null,'商品名',$this->categoryId) |
|
|
|
|
|
|
112
|
|
|
->setDetail('text','text') |
|
113
|
|
|
->setDetail('img',$image['item'][0]['url']); |
|
114
|
|
|
|
|
115
|
|
|
$testData = Yaml::parse(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Config'.DIRECTORY_SEPARATOR.'Data.yml')); |
|
116
|
|
|
|
|
117
|
|
|
foreach ($testData['Overtrue\Wechat\Test\Shop\ProductTest']['testGetProperty'] as $value) { |
|
118
|
|
|
$product->setProperty($value['id'],$value['property_value'][0]['id']); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
foreach ($testData['Overtrue\Wechat\Test\Shop\ProductTest']['testGetSku'] as $value) { |
|
122
|
|
|
foreach ($value['value_list'] as $key => $valueList) { |
|
123
|
|
|
//此判断仅是为了 让子序列少点,实际程序按照自身的逻辑来 |
|
124
|
|
|
if ($key % 5 == 0 && $key % 2 == 0) { |
|
125
|
|
|
$skuList[] = $valueList['id']; |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
$skuInfo[] = array('id'=>$value['id'],'vid'=>$skuList); |
|
|
|
|
|
|
130
|
|
|
$product->setSkuInfo($value['id'],$skuList); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
foreach ($skuInfo[0]['vid'] as $vid) { |
|
134
|
|
|
foreach ($skuInfo[1]['vid'] as $vid1) { |
|
135
|
|
|
$product->setSkuList(100, 20, $image['item'][0]['url'], 100, array(array($skuInfo[0]['id'], $vid), array($skuInfo[1]['id'], $vid1))); |
|
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
$data = $product->setAttrext(0,1,1,1) |
|
140
|
|
|
->setLocation('浙江省','杭州市','滨江区阿里园') |
|
141
|
|
|
->setDeliveryInfo(1,'400184180') |
|
|
|
|
|
|
142
|
|
|
->toArray(); |
|
143
|
|
|
$this->assertTrue(is_array($data)); |
|
144
|
|
|
|
|
145
|
|
|
// //以上架 |
|
146
|
|
|
// $product = new Product(true); |
|
147
|
|
|
// $data = $product->setBaseAttr('main_img',array('img','img')) |
|
148
|
|
|
// ->setDetail('text','text') |
|
149
|
|
|
// ->setDetail('img','image') |
|
150
|
|
|
// //->setProperty('id','vid') |
|
151
|
|
|
// //->setProperty('id','vid') |
|
152
|
|
|
// ->setSkuInfo('id',array('vid','vid')) |
|
153
|
|
|
// //统一售价 |
|
154
|
|
|
// //->setSkuList('原价','微信价','sku_ico','sku 库存'); |
|
155
|
|
|
// //设置sku售价 |
|
156
|
|
|
// ->setSkuList('原价','微信价','sku_ico','sku 库存',array('id'=>'vid','id1'=>'vid1')) |
|
157
|
|
|
// ->setAttrext(0,1,1,1) |
|
158
|
|
|
// ->setLocation('浙江省','杭州市','滨江区阿里园') |
|
159
|
|
|
// ->setDeliveryInfo(1,'400184180') |
|
160
|
|
|
// ->toArray(); |
|
161
|
|
|
// $this->assertTrue(is_array($data)); |
|
162
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: