77use FR3D \SwaggerAssertions \SchemaManager ;
88use JsonSchema \Validator ;
99use PHPUnit \Framework \Assert ;
10- use stdClass ;
1110use Zend \Http \Header \ContentType ;
1211
1312/**
@@ -18,46 +17,46 @@ trait AssertsTrait
1817 /**
1918 * Asserts response body match with the response schema.
2019 *
21- * @param stdClass|stdClass[] $responseBody
20+ * @param mixed $responseBody
2221 * @param string $path percent-encoded path used on the request.
2322 */
24- public function assertResponseBodyMatch (
23+ public static function assertResponseBodyMatch (
2524 $ responseBody ,
2625 SchemaManager $ schemaManager ,
2726 string $ path ,
2827 string $ httpMethod ,
2928 int $ httpCode ,
3029 string $ message = ''
31- ) {
30+ ): void {
3231 if (!$ schemaManager ->findPathInTemplates ($ path , $ template , $ params )) {
3332 throw new \RuntimeException ('Request URI does not match with any swagger path definition ' );
3433 }
3534
3635 $ bodySchema = $ schemaManager ->getResponseSchema ($ template , $ httpMethod , (string ) $ httpCode );
37- $ constraint = new JsonSchemaConstraint ($ bodySchema , 'response body ' , $ this -> getValidator ());
36+ $ constraint = new JsonSchemaConstraint ($ bodySchema , 'response body ' , self :: getValidator ());
3837
3938 Assert::assertThat ($ responseBody , $ constraint , $ message );
4039 }
4140
4241 /**
4342 * Asserts request body match with the request schema.
4443 *
45- * @param stdClass|stdClass[] $requestBody
44+ * @param mixed $requestBody
4645 * @param string $path percent-encoded path used on the request.
4746 */
48- public function assertRequestBodyMatch (
47+ public static function assertRequestBodyMatch (
4948 $ requestBody ,
5049 SchemaManager $ schemaManager ,
5150 string $ path ,
5251 string $ httpMethod ,
5352 string $ message = ''
54- ) {
53+ ): void {
5554 if (!$ schemaManager ->findPathInTemplates ($ path , $ template , $ params )) {
5655 throw new \RuntimeException ('Request URI does not match with any swagger path definition ' );
5756 }
5857
5958 $ bodySchema = $ schemaManager ->getRequestSchema ($ template , $ httpMethod );
60- $ constraint = new JsonSchemaConstraint ($ bodySchema , 'request body ' , $ this -> getValidator ());
59+ $ constraint = new JsonSchemaConstraint ($ bodySchema , 'request body ' , self :: getValidator ());
6160
6261 Assert::assertThat ($ requestBody , $ constraint , $ message );
6362 }
@@ -67,13 +66,13 @@ public function assertRequestBodyMatch(
6766 *
6867 * @param string $path percent-encoded path used on the request.
6968 */
70- public function assertResponseMediaTypeMatch (
69+ public static function assertResponseMediaTypeMatch (
7170 string $ responseMediaType ,
7271 SchemaManager $ schemaManager ,
7372 string $ path ,
7473 string $ httpMethod ,
7574 string $ message = ''
76- ) {
75+ ): void {
7776 if (!$ schemaManager ->findPathInTemplates ($ path , $ template , $ params )) {
7877 // @codeCoverageIgnoreStart
7978 throw new \RuntimeException ('Request URI does not match with any swagger path definition ' );
@@ -94,13 +93,13 @@ public function assertResponseMediaTypeMatch(
9493 *
9594 * @param string $path percent-encoded path used on the request.
9695 */
97- public function assertRequestMediaTypeMatch (
96+ public static function assertRequestMediaTypeMatch (
9897 string $ requestMediaType ,
9998 SchemaManager $ schemaManager ,
10099 string $ path ,
101100 string $ httpMethod ,
102101 string $ message = ''
103- ) {
102+ ): void {
104103 if (!$ schemaManager ->findPathInTemplates ($ path , $ template , $ params )) {
105104 // @codeCoverageIgnoreStart
106105 throw new \RuntimeException ('Request URI does not match with any swagger path definition ' );
@@ -122,14 +121,14 @@ public function assertRequestMediaTypeMatch(
122121 * @param string[] $headers
123122 * @param string $path percent-encoded path used on the request.
124123 */
125- public function assertResponseHeadersMatch (
124+ public static function assertResponseHeadersMatch (
126125 array $ headers ,
127126 SchemaManager $ schemaManager ,
128127 string $ path ,
129128 string $ httpMethod ,
130129 int $ httpCode ,
131130 string $ message = ''
132- ) {
131+ ): void {
133132 if (!$ schemaManager ->findPathInTemplates ($ path , $ template , $ params )) {
134133 // @codeCoverageIgnoreStart
135134 throw new \RuntimeException ('Request URI does not match with any swagger path definition ' );
@@ -138,7 +137,7 @@ public function assertResponseHeadersMatch(
138137
139138 $ constraint = new ResponseHeadersConstraint (
140139 $ schemaManager ->getResponseHeaders ($ template , $ httpMethod , (string ) $ httpCode ),
141- $ this -> getValidator ()
140+ self :: getValidator ()
142141 );
143142
144143 Assert::assertThat ($ headers , $ constraint , $ message );
@@ -150,20 +149,20 @@ public function assertResponseHeadersMatch(
150149 * @param string[] $headers
151150 * @param string $path percent-encoded path used on the request.
152151 */
153- public function assertRequestHeadersMatch (
152+ public static function assertRequestHeadersMatch (
154153 array $ headers ,
155154 SchemaManager $ schemaManager ,
156155 string $ path ,
157156 string $ httpMethod ,
158157 string $ message = ''
159- ) {
158+ ): void {
160159 if (!$ schemaManager ->findPathInTemplates ($ path , $ template , $ params )) {
161160 // @codeCoverageIgnoreStart
162161 throw new \RuntimeException ('Request URI does not match with any swagger path definition ' );
163162 // @codeCoverageIgnoreEnd
164163 }
165164
166- $ constraint = new RequestHeadersConstraint ($ schemaManager ->getRequestHeadersParameters ($ template , $ httpMethod ), $ this -> getValidator ());
165+ $ constraint = new RequestHeadersConstraint ($ schemaManager ->getRequestHeadersParameters ($ template , $ httpMethod ), self :: getValidator ());
167166
168167 Assert::assertThat ($ headers , $ constraint , $ message );
169168 }
@@ -174,25 +173,25 @@ public function assertRequestHeadersMatch(
174173 * @param mixed[] $query
175174 * @param string $path percent-encoded path used on the request.
176175 */
177- public function assertRequestQueryMatch (
176+ public static function assertRequestQueryMatch (
178177 $ query ,
179178 SchemaManager $ schemaManager ,
180179 string $ path ,
181180 string $ httpMethod ,
182181 string $ message = ''
183- ) {
182+ ): void {
184183 if (!$ schemaManager ->findPathInTemplates ($ path , $ template , $ params )) {
185184 // @codeCoverageIgnoreStart
186185 throw new \RuntimeException ('Request URI does not match with any swagger path definition ' );
187186 // @codeCoverageIgnoreEnd
188187 }
189188
190- $ constraint = new RequestQueryConstraint ($ schemaManager ->getRequestQueryParameters ($ template , $ httpMethod ), $ this -> getValidator ());
189+ $ constraint = new RequestQueryConstraint ($ schemaManager ->getRequestQueryParameters ($ template , $ httpMethod ), self :: getValidator ());
191190
192191 Assert::assertThat ($ query , $ constraint , $ message );
193192 }
194193
195- protected function getValidator (): Validator
194+ protected static function getValidator (): Validator
196195 {
197196 return new Validator ();
198197 }
0 commit comments