6
6
use Yaoi \Schema \Exception ;
7
7
use Yaoi \Schema \ObjectFlavour \Properties ;
8
8
use Yaoi \Schema \Schema ;
9
+ use Yaoi \Schema \Types \IntegerType ;
10
+ use Yaoi \Schema \Types \ObjectType ;
9
11
10
12
class ParentTest extends \PHPUnit_Framework_TestCase
11
13
{
@@ -33,10 +35,33 @@ private function deepSchema()
33
35
return $ schema ;
34
36
}
35
37
36
- public function testParent ()
38
+
39
+ private function deepSchemaSymbolic ()
37
40
{
38
- $ schema = $ this ->deepSchema ();
41
+ $ schema = ObjectType::makeSchema (
42
+ Properties::create ()
43
+ ->setProperty (
44
+ 'level1 ' ,
45
+ ObjectType::makeSchema (
46
+ Properties::create ()
47
+ ->setProperty (
48
+ 'level2 ' ,
49
+ ObjectType::makeSchema (
50
+ Properties::create ()
51
+ ->setProperty (
52
+ 'level3 ' ,
53
+ IntegerType::makeSchema ()
54
+ )
55
+ )
56
+ )
57
+ )
58
+ )
59
+ );
60
+ return $ schema ;
61
+ }
39
62
63
+ private function assertSchema (Schema $ schema )
64
+ {
40
65
$ level1Schema = Properties::getFromSchema ($ schema )->getProperty ('level1 ' );
41
66
$ level2Schema = Properties::getFromSchema ($ level1Schema )->getProperty ('level2 ' );
42
67
$ level3Schema = Properties::getFromSchema ($ level2Schema )->getProperty ('level3 ' );
@@ -50,6 +75,12 @@ public function testParent()
50
75
$ this ->assertSame ($ level2Schema , $ level3Schema ->getParentSchema ());
51
76
}
52
77
78
+ public function testParent ()
79
+ {
80
+ $ this ->assertSchema ($ this ->deepSchema ());
81
+ $ this ->assertSchema ($ this ->deepSchemaSymbolic ());
82
+ }
83
+
53
84
54
85
public function testAttach ()
55
86
{
@@ -78,6 +109,27 @@ public function testInvalidImport()
78
109
//$this->assertSame('abc', $object->level1->level2->level3);
79
110
}
80
111
112
+ public function testInvalidImportSymbolic ()
113
+ {
114
+ $ schema = $ this ->deepSchemaSymbolic ();
115
+ $ this ->setExpectedException (get_class (new Exception ()), 'Validation failed (level1->level2->level3) ' ,
116
+ Exception::INVALID_VALUE );
117
+ try {
118
+ $ object = $ schema ->import (array (
119
+ 'level1 ' => array (
120
+ 'level2 ' => array (
121
+ 'level3 ' => 'abc ' // integer required
122
+ ),
123
+ ),
124
+ ));
125
+ } catch (Exception $ exception ) {
126
+ $ this ->assertSame (array ('level1 ' , 'level2 ' , 'level3 ' ), $ exception ->getStructureTrace ());
127
+ throw $ exception ;
128
+ }
129
+ //$this->assertSame('abc', $object->level1->level2->level3);
130
+ }
131
+
132
+
81
133
public function testImport ()
82
134
{
83
135
$ object = $ this ->deepSchema ()->import (array (
@@ -89,4 +141,17 @@ public function testImport()
89
141
));
90
142
$ this ->assertSame (123 , $ object ->level1 ->level2 ->level3 );
91
143
}
144
+
145
+ public function testImportSymbolic ()
146
+ {
147
+ $ object = $ this ->deepSchemaSymbolic ()->import (array (
148
+ 'level1 ' => array (
149
+ 'level2 ' => array (
150
+ 'level3 ' => 123 // integer required
151
+ ),
152
+ ),
153
+ ));
154
+ $ this ->assertSame (123 , $ object ->level1 ->level2 ->level3 );
155
+ }
156
+
92
157
}
0 commit comments