|
9 | 9 | use MaplePHP\Validate\Inp; |
10 | 10 |
|
11 | 11 | $unit = new Unit(); |
12 | | -$unit->case("MaplePHP input validate test", function($inst) { |
| 12 | +$unit->case("MaplePHP input validate test", function() { |
13 | 13 |
|
14 | 14 | $strVal = Inp::value("TestStringValue"); |
15 | 15 | $testStrValidates = ["isString", "required", "hasValue"]; |
16 | 16 |
|
17 | 17 | foreach ($testStrValidates as $validate) { |
18 | | - $inst->add($strVal->{$validate}(), [ |
| 18 | + $this->add($strVal->{$validate}(), [ |
19 | 19 | "equal" => [true], |
20 | 20 | ], "Expect {$validate} to be true"); |
21 | 21 | } |
22 | 22 |
|
23 | | - $inst->add(Inp::value("8808218329")->socialNumber(), [ |
| 23 | + $this->add(Inp::value("8808218329")->socialNumber(), [ |
24 | 24 | "equal" => [false], |
25 | 25 | ], "Expect socialNumber to be false"); |
26 | 26 |
|
27 | | - $inst->add(Inp::value("4030000010001234")->creditCard(), [ |
| 27 | + $this->add(Inp::value("4030000010001234")->creditCard(), [ |
28 | 28 | "equal" => [true], |
29 | 29 | ], "Expect creditCard to be true"); |
30 | 30 |
|
31 | | - $inst->add(Inp::value("john.doe-gmail.com")->email(), [ |
| 31 | + $this->add(Inp::value("john.doe-gmail.com")->email(), [ |
32 | 32 | "equal" => [false], |
33 | 33 | ], "Expect creditCard to be false"); |
34 | 34 |
|
35 | | - $inst->add(Inp::value("Hello world!")->findInString("world"), [ |
| 35 | + $this->add(Inp::value("Hello world!")->findInString("world"), [ |
36 | 36 | "equal" => [true], |
37 | 37 | ], "Expect findInString to be true"); |
38 | 38 |
|
39 | | - $inst->add(Inp::value("+46 (0) 702-83 27 12")->phone(), [ |
| 39 | + $this->add(Inp::value("+46 (0) 702-83 27 12")->phone(), [ |
40 | 40 | "equal" => [true], |
41 | 41 | ], "Expect phone to be true"); |
42 | 42 |
|
43 | | - $inst->add(Inp::value("252522")->zip(5), [ |
| 43 | + $this->add(Inp::value("252522")->zip(5), [ |
44 | 44 | "equal" => [true], |
45 | 45 | ], "Expect zip to be true"); |
46 | 46 |
|
47 | 47 | $testDataTypeValidations = ['isString', 'isInt', 'isFloat', 'isArray', 'isObject', 'isBool']; |
48 | | - $inst->add(Inp::value("Is string")->isString(), [ |
| 48 | + $this->add(Inp::value("Is string")->isString(), [ |
49 | 49 | "equal" => [true], |
50 | 50 | ], "Expect isString to be true"); |
51 | 51 |
|
52 | | - $inst->add(Inp::value(true)->isInt(), [ |
| 52 | + $this->add(Inp::value(true)->isInt(), [ |
53 | 53 | "equal" => [true], |
54 | 54 | ], "Expect isInt to be true"); |
55 | 55 |
|
56 | | - $inst->add(Inp::value(22.12)->isFloat(), [ |
| 56 | + $this->add(Inp::value(22.12)->isFloat(), [ |
57 | 57 | "equal" => [true], |
58 | 58 | ], "Expect isFloat to be true"); |
59 | 59 |
|
60 | | - $inst->add(Inp::value([1, 2, 3])->isArray(), [ |
| 60 | + $this->add(Inp::value([1, 2, 3])->isArray(), [ |
61 | 61 | "equal" => [true], |
62 | 62 | ], "Expect isArray to be true"); |
63 | 63 |
|
64 | | - $inst->add(Inp::value(new stdClass())->isObject(), [ |
| 64 | + $this->add(Inp::value(new stdClass())->isObject(), [ |
65 | 65 | "equal" => [true], |
66 | 66 | ], "Expect isObject to be true"); |
67 | 67 |
|
68 | | - $inst->add(Inp::value(false)->isBool(), [ |
| 68 | + $this->add(Inp::value(false)->isBool(), [ |
69 | 69 | "equal" => [true], |
70 | 70 | ], "Expect isBool to be true"); |
71 | 71 |
|
72 | | - $inst->add(Inp::value("222.33")->number(), [ |
| 72 | + $this->add(Inp::value("222.33")->number(), [ |
73 | 73 | "equal" => [true], |
74 | 74 | ], "Expect number to be true"); |
75 | 75 |
|
76 | | - $inst->add(Inp::value(100)->positive(), [ |
| 76 | + $this->add(Inp::value(100)->positive(), [ |
77 | 77 | "equal" => [true], |
78 | 78 | ], "Expect positive to be true"); |
79 | 79 |
|
80 | | - $inst->add(Inp::value(-100)->negative(), [ |
| 80 | + $this->add(Inp::value(-100)->negative(), [ |
81 | 81 | "equal" => [true], |
82 | 82 | ], "Expect negative to be true"); |
83 | 83 |
|
84 | | - $inst->add(Inp::value(10)->min(10), [ |
| 84 | + $this->add(Inp::value(10)->min(10), [ |
85 | 85 | "equal" => [true], |
86 | 86 | ], "Expect min to be true"); |
87 | 87 |
|
88 | | - $inst->add(Inp::value(10)->max(10), [ |
| 88 | + $this->add(Inp::value(10)->max(10), [ |
89 | 89 | "equal" => [true], |
90 | 90 | ], "Expect max to be true"); |
91 | 91 |
|
92 | | - $inst->add(Inp::value("Lorem ipsum")->length(1, 11), [ |
| 92 | + $this->add(Inp::value("Lorem ipsum")->length(1, 11), [ |
93 | 93 | "equal" => [true], |
94 | 94 | ], "Expect length to be true"); |
95 | 95 |
|
96 | | - $inst->add(Inp::value("22222")->equalLength(5), [ |
| 96 | + $this->add(Inp::value("22222")->equalLength(5), [ |
97 | 97 | "equal" => [true], |
98 | 98 | ], "Expect equalLength to be true"); |
99 | 99 |
|
100 | | - $inst->add(Inp::value("hello")->equal("hello"), [ |
| 100 | + $this->add(Inp::value("hello")->equal("hello"), [ |
101 | 101 | "equal" => [true], |
102 | 102 | ], "Expect equal to be true"); |
103 | 103 |
|
104 | | - $inst->add(Inp::value("world")->notEqual("hello"), [ |
| 104 | + $this->add(Inp::value("world")->notEqual("hello"), [ |
105 | 105 | "equal" => [true], |
106 | 106 | ], "Expect notEqual to be true"); |
107 | 107 |
|
108 | | - $inst->add(Inp::value("1.2.3")->validVersion(true), [ |
| 108 | + $this->add(Inp::value("1.2.3")->validVersion(true), [ |
109 | 109 | "equal" => [true], |
110 | 110 | ], "Expect validVersion to be true"); |
111 | 111 |
|
112 | | - $inst->add(Inp::value("1.2.0")->versionCompare("1.2.0"), [ |
| 112 | + $this->add(Inp::value("1.2.0")->versionCompare("1.2.0"), [ |
113 | 113 | "equal" => [true], |
114 | 114 | ], "Expect versionCompare to be true"); |
115 | 115 |
|
116 | | - $inst->add(Inp::value("MyStrongPass")->lossyPassword(), [ |
| 116 | + $this->add(Inp::value("MyStrongPass")->lossyPassword(), [ |
117 | 117 | "equal" => [true], |
118 | 118 | ], "Expect lossyPassword to be true"); |
119 | 119 |
|
120 | | - $inst->add(Inp::value("My@StrongPass12")->strictPassword(), [ |
| 120 | + $this->add(Inp::value("My@StrongPass12")->strictPassword(), [ |
121 | 121 | "equal" => [true], |
122 | 122 | ], "Expect strictPassword to be true"); |
123 | 123 |
|
124 | | - $inst->add(Inp::value("HelloWorld")->atoZ(), [ |
| 124 | + $this->add(Inp::value("HelloWorld")->atoZ(), [ |
125 | 125 | "equal" => [true], |
126 | 126 | ], "Expect atoZ to be true"); |
127 | 127 |
|
128 | | - $inst->add(Inp::value("welloworld")->lowerAtoZ(), [ |
| 128 | + $this->add(Inp::value("welloworld")->lowerAtoZ(), [ |
129 | 129 | "equal" => [true], |
130 | 130 | ], "Expect lowerAtoZ to be true"); |
131 | 131 |
|
132 | | - $inst->add(Inp::value("HELLOWORLD")->upperAtoZ(), [ |
| 132 | + $this->add(Inp::value("HELLOWORLD")->upperAtoZ(), [ |
133 | 133 | "equal" => [true], |
134 | 134 | ], "Expect upperAtoZ to be true"); |
135 | 135 |
|
136 | | - $inst->add(Inp::value("#F1F1F1")->hex(), [ |
| 136 | + $this->add(Inp::value("#F1F1F1")->hex(), [ |
137 | 137 | "equal" => [true], |
138 | 138 | ], "Expect hex to be true"); |
139 | 139 |
|
140 | | - $inst->add(Inp::value("1922-03-01")->date(), [ |
| 140 | + $this->add(Inp::value("1922-03-01")->date(), [ |
141 | 141 | "equal" => [true], |
142 | 142 | ], "Expect date to be true"); |
143 | 143 |
|
144 | | - $inst->add(Inp::value("1988-08-21")->age(36), [ |
| 144 | + $this->add(Inp::value("1988-08-21")->age(36), [ |
145 | 145 | "equal" => [true], |
146 | 146 | ], "Expect age to be true"); |
147 | 147 |
|
148 | | - $inst->add(Inp::value("example.se")->domain(), [ |
| 148 | + $this->add(Inp::value("example.se")->domain(), [ |
149 | 149 | "equal" => [true], |
150 | 150 | ], "Expect domain to be true"); |
151 | 151 |
|
152 | | - $inst->add(Inp::value("https://example.se")->url(), [ |
| 152 | + $this->add(Inp::value("https://example.se")->url(), [ |
153 | 153 | "equal" => [true], |
154 | 154 | ], "Expect url to be true"); |
155 | 155 |
|
156 | | - $inst->add(Inp::value("examplethatwillfail.se")->dns(), [ |
| 156 | + $this->add(Inp::value("examplethatwillfail.se")->dns(), [ |
157 | 157 | "equal" => [false], |
158 | 158 | ], "Expect dns to be false"); |
159 | 159 |
|
160 | | - $inst->add(Inp::value("Lorem ipsum")->oneOf([ |
| 160 | + $this->add(Inp::value("Lorem ipsum")->oneOf([ |
161 | 161 | "length" => [120, 200], |
162 | 162 | "isString" => [] |
163 | 163 | ]), [ |
164 | 164 | "equal" => [true], |
165 | 165 | ], "Expect oneOf to be true"); |
166 | 166 |
|
167 | | - $inst->add(Inp::value("Lorem ipsum")->allOf([ |
| 167 | + $this->add(Inp::value("Lorem ipsum")->allOf([ |
168 | 168 | "length" => [1, 200], |
169 | 169 | "isString" => [] |
170 | 170 | ]), [ |
171 | 171 | "equal" => [true], |
172 | 172 | ], "Expect allOf to be true"); |
173 | 173 |
|
174 | | - $inst->add(Inp::value("required")->required(), [ |
| 174 | + $this->add(Inp::value("required")->required(), [ |
175 | 175 | "equal" => [true], |
176 | 176 | ], "Expect required to be true"); |
177 | 177 |
|
178 | | - $inst->add(Inp::value("required")->required(), [ |
| 178 | + $this->add(Inp::value("required")->required(), [ |
179 | 179 | "equal" => [true], |
180 | 180 | ], "Expect required to be true"); |
181 | 181 |
|
182 | | - $inst->add(Inp::value("required")->required(), [ |
| 182 | + $this->add(Inp::value("required")->required(), [ |
183 | 183 | "equal" => [true], |
184 | 184 | ], "Expect required to be true"); |
185 | 185 |
|
186 | | - $inst->add(Inp::value("required")->required(), [ |
| 186 | + $this->add(Inp::value("required")->required(), [ |
187 | 187 | "equal" => [true], |
188 | 188 | ], "Expect required to be true"); |
189 | 189 |
|
190 | 190 | }); |
191 | | - |
192 | | -$unit->execute(); |
0 commit comments