Skip to content

Commit e038e34

Browse files
Updated docs
1 parent b670324 commit e038e34

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

docs/testing.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
`ResponseBuilder` is [Laravel](https://laravel.com/)'s helper designed to simplify building
44
nice, normalized and easy to consume REST API responses.
55

6-
76
## Unit testing your ApiCodes ##
87

98
`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`.
5150

5251

5352
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+
}

0 commit comments

Comments
 (0)