-
Notifications
You must be signed in to change notification settings - Fork 0
/
SecondDayMyValidatorTest.php
238 lines (199 loc) · 8.86 KB
/
SecondDayMyValidatorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?php
require_once 'second.php';
require_once 'PHPUnit/Framework/TestCase.php';
/**
* MyValidator test case.
*/
class SecondDayMyValidatorTest extends PHPUnit_Framework_TestCase
{
/**
*
* @var MyValidator
*/
private $MyValidator;
/**
* Prepares the environment before running a test.
*/
protected function setUp()
{
parent::setUp();
// TODO Auto-generated SecondDayMyValidatorTest::setUp()
$value = 1;
$this->MyValidator = new MyValidator($value/* parameters */);
}
/**
* Cleans up the environment after running a test.
*/
protected function tearDown()
{
// TODO Auto-generated SecondDayMyValidatorTest::tearDown()
$this->MyValidator = null;
parent::tearDown();
}
/**
* Constructs the test case.
*/
public function __construct()
{
// TODO Auto-generated constructor
}
/**
* Tests MyValidator->__construct()
*/
public function test__construct()
{
// TODO Auto-generated SecondDayMyValidatorTest->test__construct()
$this->markTestIncomplete("__construct test not implemented");
$this->MyValidator->__construct(/* parameters */);
}
/**
* Tests MyValidator->number()
*/
public function testNumber()
{
// 该单元测试用例采用等价类方式测试,黑盒测试
// 分类依据为 正数,负数, 正常范围数字,非正常范围数字,字符括起数字,字符,字符数字交叉
// 函数返回值为1为数字,返回0为非数字
// unit1 input 1 result 1
$this->MyValidator->setValue(1);
$this->assertEquals(1, $this->MyValidator->number());
// unit2 input 134567234562 result 1
$this->MyValidator->setValue(134567234562);
$this->assertEquals(1, $this->MyValidator->number());
// unit3 input 23456789234567834567834567893456789 result 0 error 超出正常数范畴,会被转变为科学记数法,不认为为有效数字
$this->MyValidator->setValue(23456789234567834567834567893456789);
$this->assertEquals(0, $this->MyValidator->number());
// unit4 input -1 result 1
$this->MyValidator->setValue(-1);
$this->assertEquals(1, $this->MyValidator->number());
// unit5 input -134567234562 result 1
$this->MyValidator->setValue(-134567234562);
$this->assertEquals(1, $this->MyValidator->number());
// unit6 input 23456789234567834567834567893456789 result 0 error 理由同unit3
$this->MyValidator->setValue(-23456789234567834567834567893456789);
$this->assertEquals(0, $this->MyValidator->number());
// unit7 input "123" result 1 字符括起数字
$this->MyValidator->setValue("123");
$this->assertEquals(1, $this->MyValidator->number());
// unit8 input "abc" result 0 字符
$this->MyValidator->setValue("abc");
$this->assertEquals(0, $this->MyValidator->number());
// unit9 input abc result 0 字符
$this->MyValidator->setValue(abc);
$this->assertEquals(0, $this->MyValidator->number());
// unit9 input abc result 0 字符数字交叉
$this->MyValidator->setValue("123bdsa1");
$this->assertEquals(0, $this->MyValidator->number());
}
/**
* Tests MyValidator->mobile()
*/
public function testMobile()
{
//该单元测试用例采用等价类的方式测试,黑盒测试
//划分依据 正常 (电信 移动 联通)号码 , 加地址位置正常号码, 非地理位置正常号码, 非号码但是11位数字, 非11位数字
// 非号码11位数字+地理位置号, 非地理位置非号码11位数字,非11位数字非地理位置,
// 字符, 字符数字混合, 数字空格混合
// unit1 正常-电信
$this->MyValidator->setValue("13312341234");
$this->assertEquals(1, $this->MyValidator->mobile());
// unit2 正常-移动
$this->MyValidator->setValue("15112341234");
$this->assertEquals(1, $this->MyValidator->mobile());
// unit3 正常-联通
$this->MyValidator->setValue("13212341234");
$this->assertEquals(1, $this->MyValidator->mobile());
// unit4 +地理位置
$this->MyValidator->setValue("8613212341234");
$this->assertEquals(1, $this->MyValidator->mobile());
// unit4.1 +地理位置
$this->MyValidator->setValue("86+13212341234");
$this->assertEquals(1, $this->MyValidator->mobile());
// unit5 +非地理位置
$this->MyValidator->setValue("86113212341234");
$this->assertEquals(0, $this->MyValidator->mobile());
// unit6 + 非号码但是11位
$this->MyValidator->setValue("11111111111");
$this->assertEquals(0, $this->MyValidator->mobile());
// unit7 + 非11位
$this->MyValidator->setValue("1331255273");
$this->assertEquals(0, $this->MyValidator->mobile());
// unit8 + 非号码但是11位+地理位置
$this->MyValidator->setValue("8611111111111");
$this->assertEquals(0, $this->MyValidator->mobile());
// unit9 + 非号码非地理位置
$this->MyValidator->setValue("8511111111111");
$this->assertEquals(0, $this->MyValidator->mobile());
// unit10 + 非11位非地理位置
$this->MyValidator->setValue("851111111");
$this->assertEquals(0, $this->MyValidator->mobile());
// unit11 + 字符
$this->MyValidator->setValue("asdfghjkutr");
$this->assertEquals(0, $this->MyValidator->mobile());
// unit12 + 字符数字
$this->MyValidator->setValue("151fghjkutr");
$this->assertEquals(0, $this->MyValidator->mobile());
// unit13 + 数字空格
$this->MyValidator->setValue("1518731 035");
$this->assertEquals(0, $this->MyValidator->mobile());
}
/**
* Tests MyValidator->telephone()
*/
public function testTelephone()
{
//该单元测试用例采用等价类的方式测试,黑盒测试
//划分依据 1开头,非1开头 7位 8位 非7,8进行组合 + 字符 + 数字字符混合
//
//unit1 1开头 7位
$this->MyValidator->setValue("1111111");
$this->assertEquals(0, $this->MyValidator->telephone());
//unit2 1开头 8位
$this->MyValidator->setValue("10000100");
$this->assertEquals(0, $this->MyValidator->telephone());
//unit3 1开头 非78位
$this->MyValidator->setValue("10000");
$this->assertEquals(0, $this->MyValidator->telephone());
//unit4 非1开头 7位
$this->MyValidator->setValue("6553645");
$this->assertEquals(1, $this->MyValidator->telephone());
//unit5 非1开头 8位
$this->MyValidator->setValue("65536445");
$this->assertEquals(1, $this->MyValidator->telephone());
//unit6 非1开头 非78位
$this->MyValidator->setValue("65536445000");
$this->assertEquals(0, $this->MyValidator->telephone());
//unit7 字符
$this->MyValidator->setValue("bfdhsjkf");
$this->assertEquals(0, $this->MyValidator->telephone());
//unit8 字符数字混合
$this->MyValidator->setValue("6553ffs5");
$this->assertEquals(0, $this->MyValidator->telephone());
}
/**
* Tests MyValidator->email()
*/
public function testEmail()
{
//该单元测试用例采用等价类的方式测试,黑盒测试
// 以.开头,含有特殊字符,user超出长度,domin超出长度
// 正常
$this->MyValidator->setValue("renjiangang@baixing.com");
$this->assertEquals(1, $this->MyValidator->email());
//unit1 以.开头
$this->MyValidator->setValue(".renjiangang@baixing.com");
$this->assertEquals(0, $this->MyValidator->telephone());
//unit2 含有特殊字符
$this->MyValidator->setValue("re$%^njiangang@baixing.com");
$this->assertEquals(0, $this->MyValidator->telephone());
//unit3 user超出长度
$this->MyValidator->setValue("renjiangangddfghhhhgfhfghfhdfhgdfhdfghdfhgdfhfdhdfhdfhdfhgdfghdhgdh@baixing.com");
$this->assertEquals(0, $this->MyValidator->telephone());
//unit4 domin超出长度
$this->MyValidator->setValue("renjiangang@bai.fdsfs.fdfsfsdfsdfsdfsdfsdfsdfsdfsdfsfsdfsfs.fdsfsdfsdfsd.fsdfsdfds
.fsdfsdfs
sfsd.fdsfs.fsdfs.fdsfs.fdsfsd.fsfsdf.fdsf.fsdfsf
.fssf.fssf.fssf.fssf.fssf.fssf.fssf.fssf.fssf.fssf.fssf.fsxing.com");
$this->assertEquals(0, $this->MyValidator->telephone());
}
}