@@ -148,4 +148,91 @@ public function testDefaultValuesCookie()
148148 $ this ->assertEquals ('form ' , $ parameter ->style );
149149 $ this ->assertTrue ($ parameter ->explode );
150150 }
151+
152+ public function testItValidatesSchemaAndContentCombination ()
153+ {
154+ /** @var $parameter Parameter */
155+ $ parameter = Reader::readFromYaml (<<<'YAML'
156+ name: token
157+ in: cookie
158+ schema:
159+ type: object
160+ content:
161+ application/json:
162+ schema:
163+ type: object
164+ YAML
165+ , Parameter::class);
166+
167+ $ result = $ parameter ->validate ();
168+ $ this ->assertEquals (['A Parameter Object MUST contain either a schema property, or a content property, but not both. ' ], $ parameter ->getErrors ());
169+ $ this ->assertFalse ($ result );
170+ }
171+
172+ public function testItValidatesContentCanHaveOnlySingleKey ()
173+ {
174+ /** @var $parameter Parameter */
175+ $ parameter = Reader::readFromYaml (<<<'YAML'
176+ name: token
177+ in: cookie
178+ content:
179+ application/json:
180+ schema:
181+ type: object
182+ application/xml:
183+ schema:
184+ type: object
185+ YAML
186+ , Parameter::class);
187+
188+ $ result = $ parameter ->validate ();
189+ $ this ->assertEquals (['A Parameter Object with Content property MUST have A SINGLE content type. ' ], $ parameter ->getErrors ());
190+ $ this ->assertFalse ($ result );
191+ }
192+
193+
194+ public function testItValidatesSupportedSerializationStyles ()
195+ {
196+ // 1. Prepare test inputs
197+ $ specTemplate = <<<YAML
198+ name: token
199+ required: true
200+ in: %s
201+ style: %s
202+ YAML ;
203+ $ goodCombinations = [
204+ 'path ' => ['simple ' , 'label ' , 'matrix ' ],
205+ 'query ' => ['form ' , 'spaceDelimited ' , 'pipeDelimited ' , 'deepObject ' ],
206+ 'header ' => ['simple ' ],
207+ 'cookie ' => ['form ' ],
208+ ];
209+ $ badCombinations = [
210+ 'path ' => ['unknown ' , 'form ' , 'spaceDelimited ' , 'pipeDelimited ' , 'deepObject ' ],
211+ 'query ' => ['unknown ' , 'simple ' , 'label ' , 'matrix ' ],
212+ 'header ' => ['unknown ' , 'form ' , 'spaceDelimited ' , 'pipeDelimited ' , 'deepObject ' , 'matrix ' ],
213+ 'cookie ' => ['unknown ' , 'spaceDelimited ' , 'pipeDelimited ' , 'deepObject ' , 'matrix ' , 'label ' , 'matrix ' ],
214+ ];
215+
216+ // 2. Run tests for valid input
217+ foreach ($ goodCombinations as $ in =>$ styles ) {
218+ foreach ($ styles as $ style ) {
219+ /** @var $parameter Parameter */
220+ $ parameter = Reader::readFromYaml (sprintf ($ specTemplate , $ in , $ style ) , Parameter::class);
221+ $ result = $ parameter ->validate ();
222+ $ this ->assertEquals ([], $ parameter ->getErrors ());
223+ $ this ->assertTrue ($ result );
224+ }
225+ }
226+
227+ // 2. Run tests for invalid input
228+ foreach ($ badCombinations as $ in =>$ styles ) {
229+ foreach ($ styles as $ style ) {
230+ /** @var $parameter Parameter */
231+ $ parameter = Reader::readFromYaml (sprintf ($ specTemplate , $ in , $ style ) , Parameter::class);
232+ $ result = $ parameter ->validate ();
233+ $ this ->assertEquals (['A Parameter Object DOES NOT support this serialization style. ' ], $ parameter ->getErrors ());
234+ $ this ->assertFalse ($ result );
235+ }
236+ }
237+ }
151238}
0 commit comments