File tree 1 file changed +30
-1
lines changed
1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change 3
3
` ResponseBuilder ` is [ Laravel] ( https://laravel.com/ ) 's helper designed to simplify building
4
4
nice, normalized and easy to consume REST API responses.
5
5
6
-
7
6
## Unit testing your ApiCodes ##
8
7
9
8
` ResponseBuilder ` ships with traits that you can use to ensure your ApiCodes class and its values
@@ -51,3 +50,33 @@ and its namespace is `App`.
51
50
52
51
53
52
And that's it. From now on, you have your ` ApiCodes ` covered with tests too.
53
+
54
+
55
+ ## Testing other code using ResponseBuilder ##
56
+
57
+ If you want to test other code that uses response builder, then there provided traits can also be
58
+ helpful. Let's say your Laravel API exposes ` /v1/session/foo ` which is expected to return some
59
+ data. Let's test the response structure and data:
60
+
61
+ <?php
62
+
63
+ use MarcinOrlowski\ResponseBuilder\Tests\Traits\TestingHelpers;
64
+ class LoginTest extends \Illuminate\Foundation\Testing\TestCase
65
+ {
66
+ use TestingHelpers;
67
+
68
+ public function testLogin()
69
+ {
70
+ // call your method
71
+ $response = $this->call('POST', '/v1/session/foo');
72
+
73
+ // get the JSON object
74
+ $j = json_decode($response->getContent());
75
+
76
+ // validate JSON structure matches what ResponseBuilder produced
77
+ $this->assertValidResponse($j);
78
+
79
+ // some other tests of your choice
80
+ $this->assertTrue($j->success);
81
+ }
82
+ }
You can’t perform that action at this time.
0 commit comments