@@ -68,16 +68,41 @@ protected function getExpectedServiceInfo()
68
68
*/
69
69
protected function getExpectedJsonResponse ()
70
70
{
71
- $ expectedResponse = new stdClass () ;
71
+ $ expectedResponse = new stdClass ;
72
72
$ expectedResponse ->status = 'ok ' ;
73
73
$ expectedResponse ->code = 200 ;
74
74
$ expectedResponse ->message = '' ;
75
- $ expectedResponse ->data = new stdClass () ;
75
+ $ expectedResponse ->data = new stdClass ;
76
76
$ expectedResponse ->data ->{$ this ->jsonResponseDataType } = $ this ->jsonResponseData ;
77
77
78
78
return $ expectedResponse ;
79
79
}
80
80
81
+ /**
82
+ * Get the expected format for an example JSON response (pre encode).
83
+ *
84
+ * @return stdClass
85
+ */
86
+ protected function getExpectedPaginatedJsonResponse ()
87
+ {
88
+ $ expectedResponse = new stdClass ;
89
+ $ expectedResponse ->status = 'ok ' ;
90
+ $ expectedResponse ->code = 200 ;
91
+ $ expectedResponse ->message = '' ;
92
+ $ expectedResponse ->data = new stdClass ;
93
+ $ expectedResponse ->data ->{$ this ->jsonResponseDataType } = $ this ->jsonResponseData ;
94
+ $ expectedResponse ->pagination = new stdClass ;
95
+ $ expectedResponse ->pagination ->total = 2 ;
96
+ $ expectedResponse ->pagination ->per_page = 10 ;
97
+ $ expectedResponse ->pagination ->current_page = 1 ;
98
+ $ expectedResponse ->pagination ->last_page = 1 ;
99
+ $ expectedResponse ->pagination ->next_page = null ;
100
+ $ expectedResponse ->pagination ->prev_page = null ;
101
+
102
+ return $ expectedResponse ;
103
+ }
104
+
105
+
81
106
/**
82
107
* Get the expected format for an example JSON response (pre encode).
83
108
*
@@ -319,6 +344,23 @@ public function testPagination()
319
344
'prev_page ' => 1
320
345
], (array ) $ responsePaginatorTwo ->preparePaginationResponse ()->snakeFormat ());
321
346
}
347
+
348
+ /**
349
+ * Check the JSON response formatter is providing a valid response.
350
+ *
351
+ * @return void
352
+ */
353
+ public function testPaginatedJsonResponse ()
354
+ {
355
+ // Set up the paginator.
356
+ $ paginator = new Paginator (count ($ this ->jsonResponseData ), 10 , 1 );
357
+
358
+ // Build the test response data.
359
+ $ jsonResponse = MicroServiceHelper::jsonResponseFormatter ($ this ->jsonResponseDataType , $ this ->jsonResponseData , 200 , 'ok ' );
360
+ $ jsonResponse ->pagination = $ paginator ->preparePaginationResponse ()->snakeFormat ();
361
+
362
+ $ this ->assertEquals ($ jsonResponse , $ this ->getExpectedPaginatedJsonResponse ());
363
+ }
322
364
}
323
365
324
366
/**
0 commit comments