@@ -15,31 +15,66 @@ class ResponseBodyValidatorTest extends \PHPUnit_Framework_TestCase
1515 public function invalidResponseBodyProvider ()
1616 {
1717 return [
18- 'empty body ' => [(object )null ],
19- 'only version ' => [(object )['jsonrpc ' => '2.0 ' ]],
20- 'invalid version ' => [(object )['jsonrpc ' => '1.1 ' ]],
21- 'only result ' => [(object )['result ' => (object )['success ' => true ]]],
22- 'only id ' => [(object )['id ' => 1234 ]],
23- 'result and id ' => [(object )['result ' => (object )['success ' => true ], 'id ' => 1234 ]],
24- 'result and id and invalid version ' => [(object )['jsonrpc ' => '1.1 ' , 'result ' => (object )['success ' => true ], 'id ' => 1234 ]],
25- 'both result and error present ' => [(object )['jsonrpc ' => '2.0 ' , 'result ' => (object )['success ' => true ], 'id ' => 1234 , 'error ' => (object )['code ' => JsonRpcErrorInterface::INTERNAL_ERROR , 'message ' => 'Test error ' ]]],
18+ 'empty body ' => [(object )null ],
19+ 'only version ' => [(object )['jsonrpc ' => '2.0 ' ]],
20+ 'invalid version ' => [(object )['jsonrpc ' => '1.1 ' ]],
21+ 'only result ' => [(object )['result ' => (object )['success ' => true ]]],
22+ 'only id ' => [(object )['id ' => 1234 ]],
23+ 'result and id ' => [(object )['result ' => (object )['success ' => true ], 'id ' => 1234 ]],
24+ 'result and id and invalid version ' => [
25+ (object )[
26+ 'jsonrpc ' => '1.1 ' ,
27+ 'result ' => (object )['success ' => true ],
28+ 'id ' => 1234 ,
29+ ],
30+ ],
31+ 'both result and error present ' => [
32+ (object )[
33+ 'jsonrpc ' => '2.0 ' ,
34+ 'result ' => (object )['success ' => true ],
35+ 'id ' => 1234 ,
36+ 'error ' => (object )[
37+ 'code ' => JsonRpcErrorInterface::INTERNAL_ERROR ,
38+ 'message ' => 'Test error ' ,
39+ ],
40+ ],
41+ ],
2642 ];
2743 }
2844
2945 public function validResponseBodyProvider ()
3046 {
3147 return [
32- 'valid response ' => [(object )['jsonrpc ' => '2.0 ' , 'result ' => ['success ' => true ], 'id ' => 1234 ]],
48+ 'valid response ' => [(object )['jsonrpc ' => '2.0 ' , 'result ' => ['success ' => true ], 'id ' => 1234 ]],
3349 'valid empty response ' => [(object )['jsonrpc ' => '2.0 ' , 'result ' => null , 'id ' => 1234 ]],
34- 'valid error ' => [(object )['jsonrpc ' => '2.0 ' , 'error ' => (object )['code ' => JsonRpcErrorInterface::INTERNAL_ERROR , 'message ' => 'Test error ' ], 'id ' => 1234 ]],
35- 'valid error w\ data ' => [(object )['jsonrpc ' => '2.0 ' , 'error ' => (object )['code ' => JsonRpcErrorInterface::INTERNAL_ERROR , 'message ' => 'Test error ' , 'data ' => 'Test error data ' ], 'id ' => 1234 ]],
50+ 'valid error ' => [
51+ (object )[
52+ 'jsonrpc ' => '2.0 ' ,
53+ 'error ' => (object )[
54+ 'code ' => JsonRpcErrorInterface::INTERNAL_ERROR ,
55+ 'message ' => 'Test error ' ,
56+ ],
57+ 'id ' => 1234 ,
58+ ],
59+ ],
60+ 'valid error w\ data ' => [
61+ (object )[
62+ 'jsonrpc ' => '2.0 ' ,
63+ 'error ' => (object )[
64+ 'code ' => JsonRpcErrorInterface::INTERNAL_ERROR ,
65+ 'message ' => 'Test error ' ,
66+ 'data ' => 'Test error data ' ,
67+ ],
68+ 'id ' => 1234 ,
69+ ],
70+ ],
3671 ];
3772 }
3873
3974 /**
4075 * @param \stdClass $body
4176 *
42- * @dataProvider invalidResponseBodyProvider
77+ * @dataProvider invalidResponseBodyProvider
4378 * @expectedException \ScayTrase\Api\JsonRpc\Exception\ResponseParseException
4479 */
4580 public function testInvalidBody (\stdClass $ body )
@@ -50,12 +85,12 @@ public function testInvalidBody(\stdClass $body)
5085
5186 /**
5287 * @param \stdClass $body
88+ *
5389 * @dataProvider validResponseBodyProvider
5490 */
5591 public function testValidBody (\stdClass $ body )
5692 {
5793 $ parser = new ResponseBodyValidator ();
5894 $ parser ->validate ($ body );
5995 }
60-
6196}
0 commit comments