22
33namespace Swaggest \JsonSchema \Tests \PHPUnit \ClassStructure ;
44
5-
65use Swaggest \JsonSchema \Exception \TypeException ;
76use Swaggest \JsonSchema \Tests \Helper \ClassWithAllOf ;
87use Swaggest \JsonSchema \Tests \Helper \LevelThreeClass ;
8+ use Swaggest \JsonSchema \Tests \Helper \SampleProperties ;
99use Swaggest \JsonSchema \Tests \Helper \SampleStructure ;
1010use Swaggest \JsonSchema \Tests \Helper \StructureWithItems ;
1111
@@ -91,10 +91,55 @@ public function testSampleInvalid()
9191
9292 public function testAllOfClassInstance ()
9393 {
94- $ value = ClassWithAllOf::import ((object )array ('myProperty ' => 'abc ' ));
94+ $ value = ClassWithAllOf::import ((object )array ('myProperty ' => 'abc ' ));
9595 $ this ->assertSame ('abc ' , $ value ->myProperty );
9696 $ this ->assertTrue ($ value instanceof ClassWithAllOf);
9797 }
9898
99+ public function testAdditionalProperties ()
100+ {
101+ $ properties = new SampleProperties ();
102+ $ properties ->propOne = (object )array (
103+ 'subOne ' => 'one ' ,
104+ 'subTwo ' => 'two '
105+ );
106+
107+ $ exported = SampleProperties::export ($ properties );
108+ $ json = <<<JSON
109+ {
110+ "propOne": {
111+ "subOne": "one",
112+ "subTwo": "two"
113+ }
114+ }
115+ JSON ;
116+ $ this ->assertSame ($ json , json_encode ($ exported , JSON_PRETTY_PRINT ), 'With flag to true ' );
117+ }
118+
119+ public function testPatternProperties ()
120+ {
121+ $ properties = new SampleProperties ();
122+ $ properties ->setXValue ('x-foo ' , 'bar ' );
123+ $ properties ->setXValue ('x-baz ' , 'gnu ' );
124+
125+ $ exported = SampleProperties::export ($ properties );
126+ $ json = <<<JSON
127+ {
128+ "x-foo": "bar",
129+ "x-baz": "gnu"
130+ }
131+ JSON ;
132+ $ this ->assertSame ($ json , json_encode ($ exported , JSON_PRETTY_PRINT ), 'With flag to true ' );
133+ }
134+
135+ /**
136+ * @expectedException Swaggest\JsonSchema\Exception\StringException
137+ * @expectedExceptionMessage Pattern mismatch
138+ */
139+ public function testPatternPropertiesMismatch ()
140+ {
141+ $ properties = new SampleProperties ();
142+ $ properties ->setXValue ('xfoo ' , 'bar ' );
143+ }
99144
100145}
0 commit comments