Skip to content

Commit 2ac8cf6

Browse files
committed
Add support for DTO 2
1 parent 5554314 commit 2ac8cf6

File tree

2 files changed

+43
-45
lines changed

2 files changed

+43
-45
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
],
2424
"require": {
2525
"php": ">=8.0",
26-
"maplephp/dto": "^1.0"
26+
"maplephp/dto": "^2.0"
2727
},
2828
"require-dev": {
2929
"maplephp/unitary": "^1.0"

tests/unitary-validate-inp.php

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,184 +9,182 @@
99
use MaplePHP\Validate\Inp;
1010

1111
$unit = new Unit();
12-
$unit->case("MaplePHP input validate test", function($inst) {
12+
$unit->case("MaplePHP input validate test", function() {
1313

1414
$strVal = Inp::value("TestStringValue");
1515
$testStrValidates = ["isString", "required", "hasValue"];
1616

1717
foreach ($testStrValidates as $validate) {
18-
$inst->add($strVal->{$validate}(), [
18+
$this->add($strVal->{$validate}(), [
1919
"equal" => [true],
2020
], "Expect {$validate} to be true");
2121
}
2222

23-
$inst->add(Inp::value("8808218329")->socialNumber(), [
23+
$this->add(Inp::value("8808218329")->socialNumber(), [
2424
"equal" => [false],
2525
], "Expect socialNumber to be false");
2626

27-
$inst->add(Inp::value("4030000010001234")->creditCard(), [
27+
$this->add(Inp::value("4030000010001234")->creditCard(), [
2828
"equal" => [true],
2929
], "Expect creditCard to be true");
3030

31-
$inst->add(Inp::value("john.doe-gmail.com")->email(), [
31+
$this->add(Inp::value("john.doe-gmail.com")->email(), [
3232
"equal" => [false],
3333
], "Expect creditCard to be false");
3434

35-
$inst->add(Inp::value("Hello world!")->findInString("world"), [
35+
$this->add(Inp::value("Hello world!")->findInString("world"), [
3636
"equal" => [true],
3737
], "Expect findInString to be true");
3838

39-
$inst->add(Inp::value("+46 (0) 702-83 27 12")->phone(), [
39+
$this->add(Inp::value("+46 (0) 702-83 27 12")->phone(), [
4040
"equal" => [true],
4141
], "Expect phone to be true");
4242

43-
$inst->add(Inp::value("252522")->zip(5), [
43+
$this->add(Inp::value("252522")->zip(5), [
4444
"equal" => [true],
4545
], "Expect zip to be true");
4646

4747
$testDataTypeValidations = ['isString', 'isInt', 'isFloat', 'isArray', 'isObject', 'isBool'];
48-
$inst->add(Inp::value("Is string")->isString(), [
48+
$this->add(Inp::value("Is string")->isString(), [
4949
"equal" => [true],
5050
], "Expect isString to be true");
5151

52-
$inst->add(Inp::value(true)->isInt(), [
52+
$this->add(Inp::value(true)->isInt(), [
5353
"equal" => [true],
5454
], "Expect isInt to be true");
5555

56-
$inst->add(Inp::value(22.12)->isFloat(), [
56+
$this->add(Inp::value(22.12)->isFloat(), [
5757
"equal" => [true],
5858
], "Expect isFloat to be true");
5959

60-
$inst->add(Inp::value([1, 2, 3])->isArray(), [
60+
$this->add(Inp::value([1, 2, 3])->isArray(), [
6161
"equal" => [true],
6262
], "Expect isArray to be true");
6363

64-
$inst->add(Inp::value(new stdClass())->isObject(), [
64+
$this->add(Inp::value(new stdClass())->isObject(), [
6565
"equal" => [true],
6666
], "Expect isObject to be true");
6767

68-
$inst->add(Inp::value(false)->isBool(), [
68+
$this->add(Inp::value(false)->isBool(), [
6969
"equal" => [true],
7070
], "Expect isBool to be true");
7171

72-
$inst->add(Inp::value("222.33")->number(), [
72+
$this->add(Inp::value("222.33")->number(), [
7373
"equal" => [true],
7474
], "Expect number to be true");
7575

76-
$inst->add(Inp::value(100)->positive(), [
76+
$this->add(Inp::value(100)->positive(), [
7777
"equal" => [true],
7878
], "Expect positive to be true");
7979

80-
$inst->add(Inp::value(-100)->negative(), [
80+
$this->add(Inp::value(-100)->negative(), [
8181
"equal" => [true],
8282
], "Expect negative to be true");
8383

84-
$inst->add(Inp::value(10)->min(10), [
84+
$this->add(Inp::value(10)->min(10), [
8585
"equal" => [true],
8686
], "Expect min to be true");
8787

88-
$inst->add(Inp::value(10)->max(10), [
88+
$this->add(Inp::value(10)->max(10), [
8989
"equal" => [true],
9090
], "Expect max to be true");
9191

92-
$inst->add(Inp::value("Lorem ipsum")->length(1, 11), [
92+
$this->add(Inp::value("Lorem ipsum")->length(1, 11), [
9393
"equal" => [true],
9494
], "Expect length to be true");
9595

96-
$inst->add(Inp::value("22222")->equalLength(5), [
96+
$this->add(Inp::value("22222")->equalLength(5), [
9797
"equal" => [true],
9898
], "Expect equalLength to be true");
9999

100-
$inst->add(Inp::value("hello")->equal("hello"), [
100+
$this->add(Inp::value("hello")->equal("hello"), [
101101
"equal" => [true],
102102
], "Expect equal to be true");
103103

104-
$inst->add(Inp::value("world")->notEqual("hello"), [
104+
$this->add(Inp::value("world")->notEqual("hello"), [
105105
"equal" => [true],
106106
], "Expect notEqual to be true");
107107

108-
$inst->add(Inp::value("1.2.3")->validVersion(true), [
108+
$this->add(Inp::value("1.2.3")->validVersion(true), [
109109
"equal" => [true],
110110
], "Expect validVersion to be true");
111111

112-
$inst->add(Inp::value("1.2.0")->versionCompare("1.2.0"), [
112+
$this->add(Inp::value("1.2.0")->versionCompare("1.2.0"), [
113113
"equal" => [true],
114114
], "Expect versionCompare to be true");
115115

116-
$inst->add(Inp::value("MyStrongPass")->lossyPassword(), [
116+
$this->add(Inp::value("MyStrongPass")->lossyPassword(), [
117117
"equal" => [true],
118118
], "Expect lossyPassword to be true");
119119

120-
$inst->add(Inp::value("My@StrongPass12")->strictPassword(), [
120+
$this->add(Inp::value("My@StrongPass12")->strictPassword(), [
121121
"equal" => [true],
122122
], "Expect strictPassword to be true");
123123

124-
$inst->add(Inp::value("HelloWorld")->atoZ(), [
124+
$this->add(Inp::value("HelloWorld")->atoZ(), [
125125
"equal" => [true],
126126
], "Expect atoZ to be true");
127127

128-
$inst->add(Inp::value("welloworld")->lowerAtoZ(), [
128+
$this->add(Inp::value("welloworld")->lowerAtoZ(), [
129129
"equal" => [true],
130130
], "Expect lowerAtoZ to be true");
131131

132-
$inst->add(Inp::value("HELLOWORLD")->upperAtoZ(), [
132+
$this->add(Inp::value("HELLOWORLD")->upperAtoZ(), [
133133
"equal" => [true],
134134
], "Expect upperAtoZ to be true");
135135

136-
$inst->add(Inp::value("#F1F1F1")->hex(), [
136+
$this->add(Inp::value("#F1F1F1")->hex(), [
137137
"equal" => [true],
138138
], "Expect hex to be true");
139139

140-
$inst->add(Inp::value("1922-03-01")->date(), [
140+
$this->add(Inp::value("1922-03-01")->date(), [
141141
"equal" => [true],
142142
], "Expect date to be true");
143143

144-
$inst->add(Inp::value("1988-08-21")->age(36), [
144+
$this->add(Inp::value("1988-08-21")->age(36), [
145145
"equal" => [true],
146146
], "Expect age to be true");
147147

148-
$inst->add(Inp::value("example.se")->domain(), [
148+
$this->add(Inp::value("example.se")->domain(), [
149149
"equal" => [true],
150150
], "Expect domain to be true");
151151

152-
$inst->add(Inp::value("https://example.se")->url(), [
152+
$this->add(Inp::value("https://example.se")->url(), [
153153
"equal" => [true],
154154
], "Expect url to be true");
155155

156-
$inst->add(Inp::value("examplethatwillfail.se")->dns(), [
156+
$this->add(Inp::value("examplethatwillfail.se")->dns(), [
157157
"equal" => [false],
158158
], "Expect dns to be false");
159159

160-
$inst->add(Inp::value("Lorem ipsum")->oneOf([
160+
$this->add(Inp::value("Lorem ipsum")->oneOf([
161161
"length" => [120, 200],
162162
"isString" => []
163163
]), [
164164
"equal" => [true],
165165
], "Expect oneOf to be true");
166166

167-
$inst->add(Inp::value("Lorem ipsum")->allOf([
167+
$this->add(Inp::value("Lorem ipsum")->allOf([
168168
"length" => [1, 200],
169169
"isString" => []
170170
]), [
171171
"equal" => [true],
172172
], "Expect allOf to be true");
173173

174-
$inst->add(Inp::value("required")->required(), [
174+
$this->add(Inp::value("required")->required(), [
175175
"equal" => [true],
176176
], "Expect required to be true");
177177

178-
$inst->add(Inp::value("required")->required(), [
178+
$this->add(Inp::value("required")->required(), [
179179
"equal" => [true],
180180
], "Expect required to be true");
181181

182-
$inst->add(Inp::value("required")->required(), [
182+
$this->add(Inp::value("required")->required(), [
183183
"equal" => [true],
184184
], "Expect required to be true");
185185

186-
$inst->add(Inp::value("required")->required(), [
186+
$this->add(Inp::value("required")->required(), [
187187
"equal" => [true],
188188
], "Expect required to be true");
189189

190190
});
191-
192-
$unit->execute();

0 commit comments

Comments
 (0)