1- <?php
1+ <?php /** @noinspection PhpUnhandledExceptionInspection */
22
3- namespace Briedis \ApiBuilder \Tests ;
3+ namespace Briedis \ApiBuilder \Tests \ Unit ;
44
55use Briedis \ApiBuilder \Exceptions \InvalidStructureException ;
66use Briedis \ApiBuilder \Items \DecimalItem ;
77use Briedis \ApiBuilder \StructureBuilder ;
8- use Briedis \ApiBuilder \StructureBuilder as SB ;
98use Briedis \ApiBuilder \StructureValidator ;
10- use PHPUnit_Framework_TestCase ;
9+ use Briedis \ ApiBuilder \ Tests \ TestCase ;
1110
12- class MultiDepthValidatorTest extends PHPUnit_Framework_TestCase
11+ class MultiDepthValidatorTest extends TestCase
1312{
14- /** @var SB */
13+ /** @var StructureBuilder */
1514 private $ s ;
1615
1716 /** @var StructureValidator */
1817 private $ v ;
1918
2019 protected function setUp ()
2120 {
22- $ this ->s = new SB ;
21+ parent ::setUp ();
22+
23+ $ this ->s = new StructureBuilder ;
2324 $ this ->v = new StructureValidator ($ this ->s );
2425 }
2526
2627 public function testValidStructure ()
2728 {
2829 $ this ->s
29- ->struct ('s1 ' , (new SB )
30+ ->struct ('s1 ' , (new StructureBuilder )
3031 ->int ('id ' )
31- )->struct ('s2 ' , (new SB )
32+ )->struct ('s2 ' , (new StructureBuilder )
3233 ->float ('decimal ' )
3334 )->str ('str ' );
3435
@@ -50,10 +51,10 @@ public function testInvalidStructure()
5051 $ caught = false ;
5152
5253 $ this ->s
53- ->struct ('s11 ' , (new SB )
54+ ->struct ('s11 ' , (new StructureBuilder )
5455 ->float ('decimal ' )
5556 )
56- ->struct ('s22 ' , (new SB )
57+ ->struct ('s22 ' , (new StructureBuilder )
5758 ->float ('decimal ' )
5859 );
5960
@@ -81,11 +82,11 @@ public function testInvalidStructure()
8182 public function testVeryDeepValidStructure ()
8283 {
8384 $ this ->s
84- ->struct ('s111 ' , (new SB )
85- ->struct ('s222 ' , (new SB )
86- ->struct ('s333 ' , (new SB )
87- ->struct ('s444 ' , (new SB )
88- ->struct ('s555 ' , (new SB )
85+ ->struct ('s111 ' , (new StructureBuilder )
86+ ->struct ('s222 ' , (new StructureBuilder )
87+ ->struct ('s333 ' , (new StructureBuilder )
88+ ->struct ('s444 ' , (new StructureBuilder )
89+ ->struct ('s555 ' , (new StructureBuilder )
8990 ->int ('id ' )
9091 )
9192 )
@@ -115,12 +116,12 @@ public function testWrongParameterDepth()
115116 {
116117 $ this ->s
117118 ->str ('1_1 ' )
118- ->struct ('1_3 ' , (new SB )
119+ ->struct ('1_3 ' , (new StructureBuilder )
119120 ->str ('2_1 ' )
120- ->struct ('2_2 ' , (new SB )
121+ ->struct ('2_2 ' , (new StructureBuilder )
121122 ->str ('3_1 ' )
122- ->struct ('3_2 ' , (new SB )
123- ->struct ('4_1 ' , (new SB )
123+ ->struct ('3_2 ' , (new StructureBuilder )
124+ ->struct ('4_1 ' , (new StructureBuilder )
124125 ->bool ('5_1 ' )
125126 ->int ('5_2 ' )
126127 )
@@ -167,12 +168,13 @@ public function testValidArrayOfStructures()
167168 ->str ('name ' )
168169 ->str ('status ' )->values (['one ' , 'two ' , 'three ' ])->optional ();
169170
170- $ whole = (new SB )
171+ $ whole = (new StructureBuilder )
171172 ->int ('someId ' )
172173 ->struct ('items ' , $ item )->multiple ();
173174
174175 $ structureValidator = new StructureValidator ($ whole );
175- $ structureValidator ->validate ([
176+
177+ $ result = $ structureValidator ->validate ([
176178 'someId ' => 666 ,
177179 'items ' => [
178180 [
@@ -191,6 +193,8 @@ public function testValidArrayOfStructures()
191193 ],
192194 ],
193195 ]);
196+
197+ self ::assertTrue ($ result );
194198 }
195199
196200 public function testInvalidArrayOfStructures ()
@@ -199,7 +203,7 @@ public function testInvalidArrayOfStructures()
199203 ->int ('id ' )
200204 ->str ('name ' );
201205
202- $ whole = (new SB )->struct ('items ' , $ item )->multiple ();
206+ $ whole = (new StructureBuilder )->struct ('items ' , $ item )->multiple ();
203207
204208 $ structureValidator = new StructureValidator ($ whole );
205209
@@ -228,7 +232,7 @@ public function testStructureOfArrayReceivesInvalidStructure()
228232 ->int ('id ' )
229233 ->str ('name ' );
230234
231- $ whole = (new SB )->struct ('items ' , $ item )->multiple ();
235+ $ whole = (new StructureBuilder )->struct ('items ' , $ item )->multiple ();
232236
233237 $ structureValidator = new StructureValidator ($ whole );
234238
@@ -250,7 +254,7 @@ public function testOptionalStructuresCanBeNull()
250254 {
251255 $ item = (new StructureBuilder ('MyStructure ' ));
252256
253- $ whole = (new SB )->struct ('item ' , $ item )->optional ();
257+ $ whole = (new StructureBuilder )->struct ('item ' , $ item )->optional ();
254258
255259 $ structureValidator = new StructureValidator ($ whole );
256260
0 commit comments